Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion tests/acceptance/features/bootstrap/WebUIGeneralContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use TestHelpers\SetupHelper;
use TestHelpers\UploadHelper;
use Page\GeneralErrorPage;
use Page\GeneralExceptionPage;

require_once 'bootstrap.php';

Expand All @@ -48,6 +49,12 @@ class WebUIGeneralContext extends RawMinkContext implements Context {
*/
private $generalErrorPage;

/**
*
* @var GeneralExceptionPage
*/
private $generalExceptionPage;

/**
*
* @var LoginPage
Expand Down Expand Up @@ -141,15 +148,18 @@ class WebUIGeneralContext extends RawMinkContext implements Context {
* @param OwncloudPage $owncloudPage
* @param LoginPage $loginPage
* @param GeneralErrorPage $generalErrorPage
* @param GeneralExceptionPage $generalExceptionPage
*/
public function __construct(
OwncloudPage $owncloudPage,
LoginPage $loginPage,
GeneralErrorPage $generalErrorPage
GeneralErrorPage $generalErrorPage,
GeneralExceptionPage $generalExceptionPage
) {
$this->owncloudPage = $owncloudPage;
$this->loginPage = $loginPage;
$this->generalErrorPage = $generalErrorPage;
$this->generalExceptionPage = $generalExceptionPage;
}

/**
Expand Down Expand Up @@ -459,6 +469,50 @@ public function anErrorShouldBeDisplayedOnTheGeneralErrorPage($error) {
);
}

/**
* @Then the user should be redirected to the general exception webUI page with the title :title
*
* @param string $title
*
* @return void
*/
public function theUserShouldBeRedirectedToGeneralExceptionPage($title) {
$title = $this->featureContext->substituteInLineCodes($title);
$this->generalExceptionPage->waitTillPageIsLoaded($this->getSession());
// Just check that the actual title starts with the expected title.
// Theming can have other text following.
PHPUnit\Framework\Assert::assertStringStartsWith(
$title, $this->generalExceptionPage->getPageTitle()
);
}

/**
* @Then the title of the exception on general exception webUI page should be :title
*
* @param string $title
*
* @return void
*/
public function anErrorShouldBeDisplayedOnTheGeneralExceptionPageWithTitle($title) {
PHPUnit\Framework\Assert::assertEquals(
$title, $this->generalExceptionPage->getExceptionTitle()
);
}

/**
* @Then a message should be displayed on the general exception webUI page containing :message
*
* @param string $message
*
* @return void
*/
public function anErrorShouldBeDisplayedOnTheGeneralErrorPageContaining($message) {
PHPUnit\Framework\Assert::assertContains(
$message,
$this->generalExceptionPage->getExceptionMessage()
);
}

/**
* @When /^the administrator (disables|enables) the setting "([^"]*)" in the section "([^"]*)"$/
*
Expand Down
79 changes: 79 additions & 0 deletions tests/acceptance/features/lib/GeneralExceptionPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* ownCloud
*
* @author Dipak Acharya <dipak@jankaritech.com>
* @copyright Copyright (c) 2019 Dipak Acharya dipak@jankaritech.com
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace Page;

use Behat\Mink\Session;
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;

/**
* GeneralExceptionPage page.
*/
class GeneralExceptionPage extends OwncloudPage {
protected $exceptionTitleXpath = ".//span[@class='error error-wide']//h2[1]";
protected $exceptionMessageXpath = ".//span[@class='error error-wide']//p[@class='hint']";

/**
*
* @throws ElementNotFoundException
* @return string
*/
public function getExceptionMessage() {
$exceptionMessageElement = $this->find("xpath", $this->exceptionMessageXpath);
$this->assertElementNotNull(
$exceptionMessageElement,
__METHOD__ .
" could not find exception message xpath: '$this->exceptionMessageXpath'"
);
return $exceptionMessageElement->getText();
}

/**
*
* @throws ElementNotFoundException
* @return string
*/
public function getExceptionTitle() {
$exceptionTitleElement = $this->find("xpath", $this->exceptionTitleXpath);
$this->assertElementNotNull(
$exceptionTitleElement,
__METHOD__ .
" could not find exception title xpath: '$this->exceptionTitleXpath'"
);
return $exceptionTitleElement->getText();
}

/**
*
* @param Session $session
* @param int $timeout_msec
*
* @return void
* @throws \Exception
*/
public function waitTillPageIsLoaded(
Session $session,
$timeout_msec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC
) {
$this->waitTillXpathIsVisible($this->exceptionTitleXpath, $timeout_msec);
}
}