Fixes functional tests so they pass, add details about selenium set up

This commit is contained in:
Samuel Georges 2015-03-02 20:18:24 +11:00
parent 1a0ed50d82
commit 9696375099
6 changed files with 67 additions and 9 deletions

View File

@ -31,6 +31,10 @@
"laravel/framework": "5.0.*", "laravel/framework": "5.0.*",
"illuminate/html": "5.0.*" "illuminate/html": "5.0.*"
}, },
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpunit/phpunit-selenium": ">=1.2"
},
"autoload-dev": { "autoload-dev": {
"classmap": [ "classmap": [
"tests/TestCase.php", "tests/TestCase.php",

View File

@ -4,4 +4,32 @@ Unit tests can be performed by running `phpunit` in the root directory or inside
### Functional tests ### Functional tests
Functional tests can be performed by running `phpunit` in the `/tests/functional` directory. 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:
<?php
// Selenium server details
define('TEST_SELENIUM_HOST', '127.0.0.1');
define('TEST_SELENIUM_PORT', 4444);
define('TEST_SELENIUM_URL', 'http://localhost/backend/');
define('TEST_SELENIUM_BROWSER', '*firefox');
// OctoberCMS details
define('TEST_SELENIUM_THEME', 'demo');
define('TEST_SELENIUM_USER', 'admin');
define('TEST_SELENIUM_PASS', 'admin');

View File

@ -23,6 +23,10 @@ class UiTestCase extends PHPUnit_Extensions_SeleniumTestCase
$this->setBrowserUrl(TEST_SELENIUM_URL); $this->setBrowserUrl(TEST_SELENIUM_URL);
} }
//
// OctoberCMS Helpers
//
protected function signInToBackend() protected function signInToBackend()
{ {
$this->open('backend'); $this->open('backend');
@ -32,6 +36,28 @@ class UiTestCase extends PHPUnit_Extensions_SeleniumTestCase
$this->waitForPageToLoad("30000"); $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) protected function waitForElementPresent($target, $timeout = 60)
{ {
for ($second = 0; ; $second++) { for ($second = 0; ; $second++) {
@ -62,5 +88,4 @@ class UiTestCase extends PHPUnit_Extensions_SeleniumTestCase
} }
} }
} }

View File

@ -28,7 +28,7 @@ class AuthTest extends UiTestCase
try { try {
$this->assertTitle('Dashboard | October CMS'); $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) { catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString()); array_push($this->verificationErrors, $e->toString());
@ -37,7 +37,7 @@ class AuthTest extends UiTestCase
/* /*
* Log out * Log out
*/ */
$this->click('css=a[title="Sign out"]'); $this->click('css=a[data-original-title="Sign out"]');
$this->waitForPageToLoad("30000"); $this->waitForPageToLoad("30000");
try { try {

View File

@ -40,7 +40,8 @@ class TemplateTest extends UiTestCase
// Delete the page // Delete the page
$this->click("xpath=(//button[@data-request='onDelete'])[1]"); $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]"); $this->waitForElementNotPresent("name=settings[title]");
/* /*
@ -73,7 +74,7 @@ class TemplateTest extends UiTestCase
// Delete the partial // Delete the partial
$this->click("xpath=(//button[@data-request='onDelete'])[1]"); $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"); $this->waitForElementNotPresent("name=fileName");
/* /*
@ -106,7 +107,7 @@ class TemplateTest extends UiTestCase
// Delete the layout // Delete the layout
$this->click("xpath=(//button[@data-request='onDelete'])[1]"); $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"); $this->waitForElementNotPresent("name=fileName");
/* /*
@ -138,7 +139,7 @@ class TemplateTest extends UiTestCase
// Delete the content // Delete the content
$this->click("xpath=(//button[@data-request='onDelete'])[1]"); $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"); $this->waitForElementNotPresent("name=fileName");
} }

View File

@ -7,7 +7,7 @@
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="true"
syntaxCheck="false" syntaxCheck="false"
> >
<testsuites> <testsuites>