diff --git a/tests/README.md b/tests/README.md index a9e7b78b5..1828e6cfb 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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: - - 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; - } - } -} diff --git a/tests/functional/backend/AuthTest.php b/tests/functional/backend/AuthTest.php deleted file mode 100644 index 4c1fe925d..000000000 --- a/tests/functional/backend/AuthTest.php +++ /dev/null @@ -1,90 +0,0 @@ -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()); - } - } -} diff --git a/tests/functional/cms/TemplateTest.php b/tests/functional/cms/TemplateTest.php deleted file mode 100644 index 5ff2a0a9e..000000000 --- a/tests/functional/cms/TemplateTest.php +++ /dev/null @@ -1,143 +0,0 @@ -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"); - } -} diff --git a/tests/functional/phpunit.xml b/tests/functional/phpunit.xml deleted file mode 100644 index cb4586424..000000000 --- a/tests/functional/phpunit.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - ./ - - -