Remove selenium tests

This commit is contained in:
Samuel Georges 2020-02-27 19:59:47 +11:00
parent 6e607361dc
commit 9d94271977
5 changed files with 2 additions and 399 deletions

View File

@ -58,7 +58,7 @@ The test class should extend the base class `PluginTestCase` and this is a speci
class BaseTestCase extends PluginTestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
@ -72,7 +72,7 @@ The test class should extend the base class `PluginTestCase` and this is a speci
$pluginManager->bootAll(true);
}
public function tearDown()
public function tearDown(): void
{
parent::tearDown();
@ -97,38 +97,3 @@ To perform unit testing on the core October files, you should download a develop
### Unit tests
Unit tests can be performed by running `phpunit` in the root directory or inside `/tests/unit`.
### Functional tests
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_BROWSER', '*firefox');
// Back-end URL
define('TEST_SELENIUM_URL', 'http://localhost/backend/');
// Active Theme
define('TEST_SELENIUM_THEME', 'demo');
// Back-end credentials
define('TEST_SELENIUM_USER', 'admin');
define('TEST_SELENIUM_PASS', 'admin');

View File

@ -1,111 +0,0 @@
<?php
class UiTestCase extends PHPUnit\Extensions\Selenium2TestCase
{
protected function setUp()
{
/*
* Look for selenium configuration
*/
if (file_exists($seleniumEnv = __DIR__.'/../selenium.php')) {
require_once $seleniumEnv;
}
/*
* Configure selenium
*/
if (!defined('TEST_SELENIUM_URL')) {
return $this->markTestSkipped('Selenium skipped');
}
if (defined('TEST_SELENIUM_HOST')) {
$this->setHost(TEST_SELENIUM_HOST);
}
if (defined('TEST_SELENIUM_PORT')) {
$this->setPort(TEST_SELENIUM_PORT);
}
if (defined('TEST_SELENIUM_BROWSER')) {
$this->setBrowser(TEST_SELENIUM_BROWSER);
}
$this->setBrowserUrl(TEST_SELENIUM_URL);
}
//
// OctoberCMS Helpers
//
protected function signInToBackend()
{
$this->open('backend');
$this->type("name=login", TEST_SELENIUM_USER);
$this->type("name=password", TEST_SELENIUM_PASS);
$this->click("//button[@type='submit']");
$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)
{
$second = 0;
while (true) {
if ($second >= $timeout) {
$this->fail('timeout');
}
try {
if ($this->isElementPresent($target)) {
break;
}
}
catch (Exception $e) {
}
sleep(1);
++$second;
}
}
protected function waitForElementNotPresent($target, $timeout = 60)
{
$second = 0;
while (true) {
if ($second >= $timeout) {
$this->fail('timeout');
}
try {
if (!$this->isElementPresent($target)) {
break;
}
}
catch (Exception $e) {
}
sleep(1);
++$second;
}
}
}

View File

@ -1,90 +0,0 @@
<?php
class AuthTest extends UiTestCase
{
public function testSignInAndOut()
{
$this->open('backend');
$cssLogoutLink = '#layout-mainmenu .mainmenu-accountmenu > ul > li:first-child > a';
try {
$this->assertTitle('Administration Area');
$this->assertTrue($this->isElementPresent("name=login"));
$this->assertTrue($this->isElementPresent("name=password"));
$this->assertTrue($this->isElementPresent("//button[@type='submit']"));
$this->verifyText("//button[@type='submit']", "Login");
}
catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
/*
* Sign in
*/
$this->type("name=login", TEST_SELENIUM_USER);
$this->type("name=password", TEST_SELENIUM_PASS);
$this->click("//button[@type='submit']");
$this->waitForPageToLoad("30000");
try {
$this->assertTitle('Dashboard | October CMS');
$this->assertTrue($this->isElementPresent('css='.$cssLogoutLink));
}
catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
$this->verifyText('css='.$cssLogoutLink, "Sign out");
/*
* Log out
*/
$this->click('css='.$cssLogoutLink);
$this->waitForPageToLoad("30000");
try {
$this->assertTitle('Administration Area');
}
catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
}
public function testPasswordReset()
{
$this->open('backend');
try {
$this->assertTrue($this->isElementPresent("link=exact:Forgot your password?"));
}
catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
$this->click('link=exact:Forgot your password?');
$this->waitForPageToLoad("30000");
try {
$this->assertTrue($this->isElementPresent("//button[@type='submit']"));
$this->verifyText("//button[@type='submit']", "Restore");
$this->assertTrue($this->isElementPresent("link=Cancel"));
}
catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
$this->type("name=login", TEST_SELENIUM_USER);
sleep(1);
$this->click("//button[@type='submit']");
$this->waitForPageToLoad("30000");
try {
$this->assertTitle('Administration Area');
$this->assertTrue($this->isElementPresent("css=p.flash-message.success"));
$this->verifyText("css=p.flash-message.success", "An email has been sent to your email address with password restore instructions.×");
}
catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
}
}

View File

@ -1,143 +0,0 @@
<?php
class TemplateTest extends UiTestCase
{
public function testOpenTemplates()
{
$this->signInToBackend();
$this->open('cms');
$this->waitForPageToLoad("30000");
// Fix the sidebar
$this->click("xpath=(//a[@class='fix-button'])[1]");
/*
* Page
*/
// Create a new page
$this->click("xpath=(//form[@data-template-type='page']//button[@data-control='create-template'])[1]");
$this->waitForElementPresent("name=settings[title]");
// Populate page details
$this->type('name=settings[title]', 'Functional Test Page');
$this->type('name=settings[url]', '/xxx/functional/test/page');
$this->type('name=fileName', 'xxx_functional_test_page');
// Save the new page
$this->click("xpath=(//a[@data-request='onSave'])[1]");
$this->waitForElementPresent("xpath=(//li[@data-tab-id='page-".TEST_SELENIUM_THEME."-xxx_functional_test_page.htm'])[1]");
// Close the tab
$this->click("xpath=(//li[@data-tab-id='page-".TEST_SELENIUM_THEME."-xxx_functional_test_page.htm']/span[@class='tab-close'])[1]");
// Reopen the tab
$this->waitForElementPresent("xpath=(//div[@id='TemplateList-pageList-template-list']//li[@data-item-path='xxx_functional_test_page.htm']/a)[1]");
$this->click("xpath=(//div[@id='TemplateList-pageList-template-list']//li[@data-item-path='xxx_functional_test_page.htm']/a)[1]");
$this->waitForElementPresent("name=settings[title]");
sleep(1);
// Delete the page
$this->click("xpath=(//button[@data-request='onDelete'])[1]");
$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]");
/*
* Partial
*/
// Click partials menu item
$this->click("xpath=(//li[@data-menu-item='partials']/a)[1]");
// Create a new partial
$this->click("xpath=(//form[@data-template-type='partial']//button[@data-control='create-template'])[1]");
$this->waitForElementPresent("name=fileName");
// Populate partial details
$this->type('name=fileName', 'xxx_functional_test_partial');
$this->type('name=settings[description]', 'Test partial');
// Save the new partial
$this->click("xpath=(//a[@data-request='onSave'])[1]");
$this->waitForElementPresent("xpath=(//li[@data-tab-id='partial-".TEST_SELENIUM_THEME."-xxx_functional_test_partial.htm'])[1]");
// Close the tab
$this->click("xpath=(//li[@data-tab-id='partial-".TEST_SELENIUM_THEME."-xxx_functional_test_partial.htm']/span[@class='tab-close'])[1]");
// Reopen the tab
$this->waitForElementPresent("xpath=(//div[@id='TemplateList-partialList-template-list']//li[@data-item-path='xxx_functional_test_partial.htm']/a)[1]");
$this->click("xpath=(//div[@id='TemplateList-partialList-template-list']//li[@data-item-path='xxx_functional_test_partial.htm']/a)[1]");
$this->waitForElementPresent("name=fileName");
sleep(1);
// Delete the partial
$this->click("xpath=(//button[@data-request='onDelete'])[1]");
$this->getSweetConfirmation('Do you really want delete this partial?');
$this->waitForElementNotPresent("name=fileName");
/*
* Layout
*/
// Click layouts menu item
$this->click("xpath=(//li[@data-menu-item='layouts']/a)[1]");
// Create a new layout
$this->click("xpath=(//form[@data-template-type='layout']//button[@data-control='create-template'])[1]");
$this->waitForElementPresent("name=fileName");
// Populate layout details
$this->type('name=fileName', 'xxx_functional_test_layout');
$this->type('name=settings[description]', 'Test layout');
// Save the new layout
$this->click("xpath=(//a[@data-request='onSave'])[1]");
$this->waitForElementPresent("xpath=(//li[@data-tab-id='layout-".TEST_SELENIUM_THEME."-xxx_functional_test_layout.htm'])[1]");
// Close the tab
$this->click("xpath=(//li[@data-tab-id='layout-".TEST_SELENIUM_THEME."-xxx_functional_test_layout.htm']/span[@class='tab-close'])[1]");
// Reopen the tab
$this->waitForElementPresent("xpath=(//div[@id='TemplateList-layoutList-template-list']//li[@data-item-path='xxx_functional_test_layout.htm']/a)[1]");
$this->click("xpath=(//div[@id='TemplateList-layoutList-template-list']//li[@data-item-path='xxx_functional_test_layout.htm']/a)[1]");
$this->waitForElementPresent("name=fileName");
sleep(1);
// Delete the layout
$this->click("xpath=(//button[@data-request='onDelete'])[1]");
$this->getSweetConfirmation('Do you really want delete this layout?');
$this->waitForElementNotPresent("name=fileName");
/*
* Content
*/
// Click contents menu item
$this->click("xpath=(//li[@data-menu-item='content']/a)[1]");
// Create a new content
$this->click("xpath=(//form[@data-template-type='content']//button[@data-control='create-template'])[1]");
$this->waitForElementPresent("name=fileName");
// Populate content details
$this->type('name=fileName', 'xxx_functional_test_content.txt');
// Save the new content
$this->click("xpath=(//a[@data-request='onSave'])[1]");
$this->waitForElementPresent("xpath=(//li[@data-tab-id='content-".TEST_SELENIUM_THEME."-xxx_functional_test_content.txt'])[1]");
// Close the tab
$this->click("xpath=(//li[@data-tab-id='content-".TEST_SELENIUM_THEME."-xxx_functional_test_content.txt']/span[@class='tab-close'])[1]");
// Reopen the tab
$this->waitForElementPresent("xpath=(//div[@id='TemplateList-contentList-template-list']//li[@data-item-path='xxx_functional_test_content.txt']/a)[1]");
$this->click("xpath=(//div[@id='TemplateList-contentList-template-list']//li[@data-item-path='xxx_functional_test_content.txt']/a)[1]");
$this->waitForElementPresent("name=fileName");
sleep(1);
// Delete the content
$this->click("xpath=(//button[@data-request='onDelete'])[1]");
$this->getSweetConfirmation('Do you really want delete this content file?');
$this->waitForElementNotPresent("name=fileName");
}
}

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../../bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="false"
>
<testsuites>
<testsuite name="October Test Suite">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>