From 14e277e030553de0459a108864baf80b71808ebd Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Tue, 17 Jun 2014 18:53:47 +1000 Subject: [PATCH] Create functional tests Move unit tests to unit folder --- .gitignore | 3 +- composer.json | 3 +- tests/UiTestCase.php | 50 +++++++++++ tests/functional/Cms/TemplateTest.php | 41 +++++++++ tests/functional/backend/AuthTest.php | 90 +++++++++++++++++++ .../backend/classes/WidgetManagerTest.php | 0 .../cms/classes/CmsCompoundObjectTest.php | 0 .../cms/classes/CmsExceptionTest.php | 2 +- .../{ => unit}/cms/classes/CmsObjectTest.php | 0 .../{ => unit}/cms/classes/CodeParserTest.php | 0 .../cms/classes/CombineAssetsTest.php | 0 .../cms/classes/ComponentManagerTest.php | 0 .../{ => unit}/cms/classes/ControllerTest.php | 2 +- .../{ => unit}/cms/classes/FileHelperTest.php | 0 tests/{ => unit}/cms/classes/RouterTest.php | 0 .../cms/classes/SectionParserTest.php | 0 tests/{ => unit}/cms/classes/ThemeTest.php | 0 .../system/classes/PluginManagerTest.php | 0 .../system/classes/TranslatorTest.php | 0 .../system/classes/VersionManagerTest.php | 0 20 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 tests/UiTestCase.php create mode 100644 tests/functional/Cms/TemplateTest.php create mode 100644 tests/functional/backend/AuthTest.php rename tests/{ => unit}/backend/classes/WidgetManagerTest.php (100%) rename tests/{ => unit}/cms/classes/CmsCompoundObjectTest.php (100%) rename tests/{ => unit}/cms/classes/CmsExceptionTest.php (97%) rename tests/{ => unit}/cms/classes/CmsObjectTest.php (100%) rename tests/{ => unit}/cms/classes/CodeParserTest.php (100%) rename tests/{ => unit}/cms/classes/CombineAssetsTest.php (100%) rename tests/{ => unit}/cms/classes/ComponentManagerTest.php (100%) rename tests/{ => unit}/cms/classes/ControllerTest.php (99%) rename tests/{ => unit}/cms/classes/FileHelperTest.php (100%) rename tests/{ => unit}/cms/classes/RouterTest.php (100%) rename tests/{ => unit}/cms/classes/SectionParserTest.php (100%) rename tests/{ => unit}/cms/classes/ThemeTest.php (100%) rename tests/{ => unit}/system/classes/PluginManagerTest.php (100%) rename tests/{ => unit}/system/classes/TranslatorTest.php (100%) rename tests/{ => unit}/system/classes/VersionManagerTest.php (100%) diff --git a/.gitignore b/.gitignore index e03ecc0e2..44273319d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ nginx-access.log nginx-ssl.access.log nginx-ssl.error.log php-errors.log -sftp-config.json \ No newline at end of file +sftp-config.json +selenium.php \ No newline at end of file diff --git a/composer.json b/composer.json index 00900fdd6..067c57867 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ }, "autoload": { "classmap": [ - "tests/TestCase.php" + "tests/TestCase.php", + "tests/UiTestCase.php" ] }, "___scripts": { diff --git a/tests/UiTestCase.php b/tests/UiTestCase.php new file mode 100644 index 000000000..cbeb1c875 --- /dev/null +++ b/tests/UiTestCase.php @@ -0,0 +1,50 @@ +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); + } + + 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"); + } + + protected function waitForElementPresent($target, $timeout = 120) + { + for ($second = 0; ; $second++) { + if ($second >= $timeout) + $this->fail("timeout"); + + try { + if ($this->isElementPresent($target)) break; + } + catch (Exception $e) {} + + sleep(1); + } + } + +} diff --git a/tests/functional/Cms/TemplateTest.php b/tests/functional/Cms/TemplateTest.php new file mode 100644 index 000000000..cfdad9bb4 --- /dev/null +++ b/tests/functional/Cms/TemplateTest.php @@ -0,0 +1,41 @@ +signInToBackend(); + $this->open('cms'); + $this->waitForPageToLoad("30000"); + + // Fix the sidebar + $this->click("xpath=(//a[@class='fix-button'])[1]"); + + // Create a new page + $this->click("xpath=(//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-website-xxx_functional_test_page.htm'])[1]"); + + // Close the tab + $this->click("xpath=(//li[@data-tab-id='page-website-xxx_functional_test_page.htm']/span[@class='tab-close'])[1]"); + + // Reopen the tab + $this->waitForElementPresent("xpath=(//div[@id='TemplateList-pageList-template-list']/ul/li[@data-item-path='xxx_functional_test_page.htm']/a)[1]"); + $this->click("xpath=(//div[@id='TemplateList-pageList-template-list']/ul/li[@data-item-path='xxx_functional_test_page.htm']/a)[1]"); + $this->waitForElementPresent("name=settings[title]"); + + // 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())); + } + +} \ No newline at end of file diff --git a/tests/functional/backend/AuthTest.php b/tests/functional/backend/AuthTest.php new file mode 100644 index 000000000..6b3d36468 --- /dev/null +++ b/tests/functional/backend/AuthTest.php @@ -0,0 +1,90 @@ +open('backend'); + + // 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=a[title="Sign out"]')); + // } + // catch (PHPUnit_Framework_AssertionFailedError $e) { + // array_push($this->verificationErrors, $e->toString()); + // } + + // /* + // * Log out + // */ + // $this->click('css=a[title="Sign out"]'); + // $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/backend/classes/WidgetManagerTest.php b/tests/unit/backend/classes/WidgetManagerTest.php similarity index 100% rename from tests/backend/classes/WidgetManagerTest.php rename to tests/unit/backend/classes/WidgetManagerTest.php diff --git a/tests/cms/classes/CmsCompoundObjectTest.php b/tests/unit/cms/classes/CmsCompoundObjectTest.php similarity index 100% rename from tests/cms/classes/CmsCompoundObjectTest.php rename to tests/unit/cms/classes/CmsCompoundObjectTest.php diff --git a/tests/cms/classes/CmsExceptionTest.php b/tests/unit/cms/classes/CmsExceptionTest.php similarity index 97% rename from tests/cms/classes/CmsExceptionTest.php rename to tests/unit/cms/classes/CmsExceptionTest.php index 612a218c7..22074864d 100644 --- a/tests/cms/classes/CmsExceptionTest.php +++ b/tests/unit/cms/classes/CmsExceptionTest.php @@ -87,7 +87,7 @@ class CmsExceptionTest extends TestCase $router = new Router($theme); $page = $router->findByUrl('/throw-php'); - $foreignException = new \Symfony\Component\Debug\Exception\FatalErrorException('This is a general error'); + $foreignException = new \Symfony\Component\Debug\Exception\FatalErrorException('This is a general error', 100, 1, 'test.php', 20); $this->setProtectedProperty($foreignException, 'file', "/modules/cms/classes/CodeParser.php(165) : eval()'d code line 7"); $exception = new CmsException($page, 300); diff --git a/tests/cms/classes/CmsObjectTest.php b/tests/unit/cms/classes/CmsObjectTest.php similarity index 100% rename from tests/cms/classes/CmsObjectTest.php rename to tests/unit/cms/classes/CmsObjectTest.php diff --git a/tests/cms/classes/CodeParserTest.php b/tests/unit/cms/classes/CodeParserTest.php similarity index 100% rename from tests/cms/classes/CodeParserTest.php rename to tests/unit/cms/classes/CodeParserTest.php diff --git a/tests/cms/classes/CombineAssetsTest.php b/tests/unit/cms/classes/CombineAssetsTest.php similarity index 100% rename from tests/cms/classes/CombineAssetsTest.php rename to tests/unit/cms/classes/CombineAssetsTest.php diff --git a/tests/cms/classes/ComponentManagerTest.php b/tests/unit/cms/classes/ComponentManagerTest.php similarity index 100% rename from tests/cms/classes/ComponentManagerTest.php rename to tests/unit/cms/classes/ComponentManagerTest.php diff --git a/tests/cms/classes/ControllerTest.php b/tests/unit/cms/classes/ControllerTest.php similarity index 99% rename from tests/cms/classes/ControllerTest.php rename to tests/unit/cms/classes/ControllerTest.php index 64aa9c21d..51c1de4ca 100644 --- a/tests/cms/classes/ControllerTest.php +++ b/tests/unit/cms/classes/ControllerTest.php @@ -301,7 +301,7 @@ ESC; public function testComponentAliases() { - include_once dirname(dirname(__DIR__)) . '/fixtures/System/plugins/October/Test/Components/Archive.php'; + include_once base_path() . '/tests/fixtures/System/plugins/October/Test/Components/Archive.php'; $theme = new Theme(); $theme->load('test'); diff --git a/tests/cms/classes/FileHelperTest.php b/tests/unit/cms/classes/FileHelperTest.php similarity index 100% rename from tests/cms/classes/FileHelperTest.php rename to tests/unit/cms/classes/FileHelperTest.php diff --git a/tests/cms/classes/RouterTest.php b/tests/unit/cms/classes/RouterTest.php similarity index 100% rename from tests/cms/classes/RouterTest.php rename to tests/unit/cms/classes/RouterTest.php diff --git a/tests/cms/classes/SectionParserTest.php b/tests/unit/cms/classes/SectionParserTest.php similarity index 100% rename from tests/cms/classes/SectionParserTest.php rename to tests/unit/cms/classes/SectionParserTest.php diff --git a/tests/cms/classes/ThemeTest.php b/tests/unit/cms/classes/ThemeTest.php similarity index 100% rename from tests/cms/classes/ThemeTest.php rename to tests/unit/cms/classes/ThemeTest.php diff --git a/tests/system/classes/PluginManagerTest.php b/tests/unit/system/classes/PluginManagerTest.php similarity index 100% rename from tests/system/classes/PluginManagerTest.php rename to tests/unit/system/classes/PluginManagerTest.php diff --git a/tests/system/classes/TranslatorTest.php b/tests/unit/system/classes/TranslatorTest.php similarity index 100% rename from tests/system/classes/TranslatorTest.php rename to tests/unit/system/classes/TranslatorTest.php diff --git a/tests/system/classes/VersionManagerTest.php b/tests/unit/system/classes/VersionManagerTest.php similarity index 100% rename from tests/system/classes/VersionManagerTest.php rename to tests/unit/system/classes/VersionManagerTest.php