From 969637509979c36c8d650d529d6e5098f5bae321 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Mon, 2 Mar 2015 20:18:24 +1100 Subject: [PATCH] Fixes functional tests so they pass, add details about selenium set up --- composer.json | 4 ++++ tests/README.md | 30 ++++++++++++++++++++++++++- tests/UiTestCase.php | 27 +++++++++++++++++++++++- tests/functional/backend/AuthTest.php | 4 ++-- tests/functional/cms/TemplateTest.php | 9 ++++---- tests/functional/phpunit.xml | 2 +- 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 39af9a447..d54889606 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,10 @@ "laravel/framework": "5.0.*", "illuminate/html": "5.0.*" }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "phpunit/phpunit-selenium": ">=1.2" + }, "autoload-dev": { "classmap": [ "tests/TestCase.php", diff --git a/tests/README.md b/tests/README.md index 851111ac1..793205466 100644 --- a/tests/README.md +++ b/tests/README.md @@ -4,4 +4,32 @@ Unit tests can be performed by running `phpunit` in the root directory or inside ### Functional tests -Functional tests can be performed by running `phpunit` in the `/tests/functional` directory. \ No newline at end of file +Functional tests can be performed by running `phpunit` in the `/tests/functional` directory. Ensure the following configuration is met: + +- Active theme is `demo` +- Language preference is `en` + +#### Selenium set up + +1. Download latest Java SE from http://java.sun.com/ and install +1. Download a distribution archive of [Selenium Server](http://seleniumhq.org/download/). +1. Unzip the distribution archive and copy selenium-server-standalone-2.42.2.jar (check the version suffix) to /usr/local/bin, for instance. +1. Start the Selenium Server server by running `java -jar /usr/local/bin/selenium-server-standalone-2.42.2.jar`. + +#### Selenium configuration + +Create a new file `selenium.php` in the root directory, add the following content: + + setBrowserUrl(TEST_SELENIUM_URL); } + // + // OctoberCMS Helpers + // + protected function signInToBackend() { $this->open('backend'); @@ -32,6 +36,28 @@ class UiTestCase extends PHPUnit_Extensions_SeleniumTestCase $this->waitForPageToLoad("30000"); } + /** + * Similar to the native getConfirmation() function + */ + protected function getSweetConfirmation($expectedText = null, $clickOk = true) + { + $this->waitForElementPresent("xpath=(//div[@class='sweet-alert showSweetAlert visible'])[1]"); + + if ($expectedText) { + $this->verifyText("//div[@class='sweet-alert showSweetAlert visible']//h4", $expectedText); + } + + $this->verifyText("//div[@class='sweet-alert showSweetAlert visible']//button[@class='confirm btn btn-primary']", "OK"); + + if ($clickOk) { + $this->click("xpath=(//div[@class='sweet-alert showSweetAlert visible']//button[@class='confirm btn btn-primary'])[1]"); + } + } + + // + // Selenium helpers + // + protected function waitForElementPresent($target, $timeout = 60) { for ($second = 0; ; $second++) { @@ -62,5 +88,4 @@ class UiTestCase extends PHPUnit_Extensions_SeleniumTestCase } } - } diff --git a/tests/functional/backend/AuthTest.php b/tests/functional/backend/AuthTest.php index 69554086d..9b3f44d11 100644 --- a/tests/functional/backend/AuthTest.php +++ b/tests/functional/backend/AuthTest.php @@ -28,7 +28,7 @@ class AuthTest extends UiTestCase try { $this->assertTitle('Dashboard | October CMS'); - $this->assertTrue($this->isElementPresent('css=a[title="Sign out"]')); + $this->assertTrue($this->isElementPresent('css=a[data-original-title="Sign out"]')); } catch (PHPUnit_Framework_AssertionFailedError $e) { array_push($this->verificationErrors, $e->toString()); @@ -37,7 +37,7 @@ class AuthTest extends UiTestCase /* * Log out */ - $this->click('css=a[title="Sign out"]'); + $this->click('css=a[data-original-title="Sign out"]'); $this->waitForPageToLoad("30000"); try { diff --git a/tests/functional/cms/TemplateTest.php b/tests/functional/cms/TemplateTest.php index 5e25f93d7..90ba3486b 100644 --- a/tests/functional/cms/TemplateTest.php +++ b/tests/functional/cms/TemplateTest.php @@ -40,7 +40,8 @@ class TemplateTest extends UiTestCase // Delete the page $this->click("xpath=(//button[@data-request='onDelete'])[1]"); - $this->assertTrue((bool)preg_match('/^Do you really want delete this page[\s\S]$/',$this->getConfirmation())); + $this->getSweetConfirmation('Do you really want delete this page?'); + // $this->assertTrue((bool)preg_match('/^Do you really want delete this page[\s\S]$/',$this->getConfirmation())); $this->waitForElementNotPresent("name=settings[title]"); /* @@ -73,7 +74,7 @@ class TemplateTest extends UiTestCase // Delete the partial $this->click("xpath=(//button[@data-request='onDelete'])[1]"); - $this->assertTrue((bool)preg_match('/^Do you really want delete this partial[\s\S]$/',$this->getConfirmation())); + $this->getSweetConfirmation('Do you really want delete this partial?'); $this->waitForElementNotPresent("name=fileName"); /* @@ -106,7 +107,7 @@ class TemplateTest extends UiTestCase // Delete the layout $this->click("xpath=(//button[@data-request='onDelete'])[1]"); - $this->assertTrue((bool)preg_match('/^Do you really want delete this layout[\s\S]$/',$this->getConfirmation())); + $this->getSweetConfirmation('Do you really want delete this layout?'); $this->waitForElementNotPresent("name=fileName"); /* @@ -138,7 +139,7 @@ class TemplateTest extends UiTestCase // Delete the content $this->click("xpath=(//button[@data-request='onDelete'])[1]"); - $this->assertTrue((bool)preg_match('/^Do you really want delete this content file[\s\S]$/',$this->getConfirmation())); + $this->getSweetConfirmation('Do you really want delete this content file?'); $this->waitForElementNotPresent("name=fileName"); } diff --git a/tests/functional/phpunit.xml b/tests/functional/phpunit.xml index a5415e7e5..c8043149c 100644 --- a/tests/functional/phpunit.xml +++ b/tests/functional/phpunit.xml @@ -7,7 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" syntaxCheck="false" >