Skip to content

Commit

Permalink
Fixes functional tests so they pass, add details about selenium set up
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Mar 2, 2015
1 parent 1a0ed50 commit 9696375
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 29 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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');
27 changes: 26 additions & 1 deletion tests/UiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ protected function setUp()
$this->setBrowserUrl(TEST_SELENIUM_URL);
}

//
// OctoberCMS Helpers
//

protected function signInToBackend()
{
$this->open('backend');
Expand All @@ -32,6 +36,28 @@ protected function signInToBackend()
$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++) {
Expand Down Expand Up @@ -62,5 +88,4 @@ protected function waitForElementNotPresent($target, $timeout = 60)
}
}


}
4 changes: 2 additions & 2 deletions tests/functional/backend/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testSignInAndOut()

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());
Expand All @@ -37,7 +37,7 @@ public function testSignInAndOut()
/*
* Log out
*/
$this->click('css=a[title="Sign out"]');
$this->click('css=a[data-original-title="Sign out"]');
$this->waitForPageToLoad("30000");

try {
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/cms/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function testOpenTemplates()

// 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]");

/*
Expand Down Expand Up @@ -73,7 +74,7 @@ public function testOpenTemplates()

// 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");

/*
Expand Down Expand Up @@ -106,7 +107,7 @@ public function testOpenTemplates()

// 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");

/*
Expand Down Expand Up @@ -138,7 +139,7 @@ public function testOpenTemplates()

// 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");

}
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
stopOnFailure="true"
syntaxCheck="false"
>
<testsuites>
Expand Down

0 comments on commit 9696375

Please sign in to comment.