diff --git a/.gitignore b/.gitignore index 9b3d10dcedab6..9f283cf83d385 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,14 @@ /phpunit.xml /tests/system/webdriver/tests/logs/ /tests/system/servers/configdef.php +codecept.phar +tests/codeception/_output/* +tests/codeception/vendor/* +tests/codeception/testingsite* +tests/codeception/tests/acceptance.suite.yml +tests/codeception/tests/acceptance/*Tester.php +tests/codeception/tests/functional/*Tester.php +tests/codeception/tests/unit/*Tester.php # phpDocumentor Logs # phpdoc-* diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000000000..3fabcd073a4dd --- /dev/null +++ b/tests/README.md @@ -0,0 +1,10 @@ +Testing Joomla CMS +========== + +The current folder contains the Tests for Quality Assurance of the Joomla Content Management System. The Tests are divided in 3 main subfolders: + +* unit: contains the Joomla-cms unit tests based on PHPUnit +* system: contains the Webdriver-Nearsoft based Selenium tests +* codeception: contains the new System Tests based on Codeception Testing Framework + +Find more details inside each folder. diff --git a/tests/codeception/README.md b/tests/codeception/README.md new file mode 100644 index 0000000000000..aec27b62548fb --- /dev/null +++ b/tests/codeception/README.md @@ -0,0 +1,46 @@ +Testing Joomla CMS +========== + +## System testing +This folder contains a System Tests suite based on Codeception Testing Framework. For more information see: https://docs.joomla.org/Testing_Joomla_Extensions_with_Codeception + +### Getting Joomla +The first step to execute the System tests at Joomla-CMS a Joomla website. To do it automatically you can execute the following commands: + +``` +cd tests/codeception +composer install +# The following comand uses a Joomla Framework App that downloads the latests Joomla +php cli/getjoomlacli.php +``` + +note: to execute the previous commands you will need Composer in your system. See https://docs.joomla.org/Testing_Joomla_Extensions_with_Codeception#Testing_with_Codeception. + + +### Running the tests + +Rename tests/acceptance.suite.dist.yml to tests/acceptance.suite.yml + +Modify the configuration at tests/acceptance.suite.yml to fit your server details. Find the instructions in the same file: https://github.com/joomla/joomla-cms/tests/codeception/acceptance.suite.dist.yml#L3 + +Run Selenium server (is the software that drives your Firefox browser): + +``` +# Download Selenium Server +curl -O http://selenium-release.storage.googleapis.com/2.41/selenium-server-standalone-2.41.0.jar + +# Go to the folder were you have downloaded the file and start the Selenium Server +java -Xms40m -Xmx256m -jar ./selenium-server-standalone-2.41.0.jar +``` + + +Execute the tests: + +``` +php vendor/bin/codecept build +php vendor/bin/codecept run tests/acceptance/installation/ --steps +php vendor/bin/codecept run tests/acceptance/administrator/ --steps +``` + +You can also execute the tests using runsystemtests.sh file + diff --git a/tests/codeception/cli/getjoomlacli.php b/tests/codeception/cli/getjoomlacli.php new file mode 100644 index 0000000000000..06103b9e9067b --- /dev/null +++ b/tests/codeception/cli/getjoomlacli.php @@ -0,0 +1,102 @@ +input->get('h') || $this->input->get('help')) + { + $this->out(); + $this->out('GetJoomlaCLI ' . self::VERSION); + $this->out('--------------------------------------------------------'); + $this->out('GetJoomlaCLI is a Joomla Framework simple Command Line Apllication.'); + $this->out('With GetJoomlaCLI you can easily download the latest Joomla CMS into a folder.'); + $this->out('called "testingsite".'); + $this->out(); + $this->out(' -h | --help Prints this usage information.'); + $this->out(' -folder the folder name where to create the joomla site'); + $this->out(' "testingsite" will be used if no name is provided'); + $this->out('EXAMPLE USAGE:'); + $this->out(' php -f getjoomlacli.php -h'); + $this->out(' php -f getjoomlacli.php --folder=testingsite'); + $this->out(); + } + else + { + $folder = JPATH_ROOT . '/' . $this->input->get('folder', 'testingsite'); + + if (is_dir($folder)) + { + $this->out('Removing old files in the folder...'); + Folder::delete($folder); + } + + Folder::create($folder); + + $this->out('Downloading Joomla...'); + $repository = 'https://github.com/joomla/joomla-cms.git'; + $branch = 'staging'; + + $command = "git clone -b ${branch} --single-branch --depth 1 ${repository} ${folder}"; + $this->out($command); + + $output = array(); + + exec($command, $output, $returnValue); + + if ($returnValue) + { + $this->out('Sadly we were not able to download Joomla.'); + } + else + { + $this->out('Joomla Downloaded and ready for executing the tests.'); + } + } + } +} + +define('JPATH_ROOT', realpath(dirname(__DIR__))); + +$app = new GetJoomlaCli; +$app->execute(); + diff --git a/tests/codeception/codeception.yml b/tests/codeception/codeception.yml new file mode 100644 index 0000000000000..b9a584df57336 --- /dev/null +++ b/tests/codeception/codeception.yml @@ -0,0 +1,10 @@ +actor: Tester +paths: + tests: tests + log: tests/_output + data: tests/_data + helpers: tests/_support +settings: + bootstrap: _bootstrap.php + colors: true + memory_limit: 1024M diff --git a/tests/codeception/composer.json b/tests/codeception/composer.json new file mode 100644 index 0000000000000..f8557d158b334 --- /dev/null +++ b/tests/codeception/composer.json @@ -0,0 +1,14 @@ +{ + "name" : "joomla-cms", + "description": "The Joomla Content Management System", + "license" : "GPL-2.0+", + "require" : { + "php": ">=5.3.10" + }, + "require-dev": { + "codeception/codeception": "2.0.*@dev", + "joomla/application": "~1.0", + "joomla/filesystem": "~1.0", + "joomla/di" : "~1.0" + } +} diff --git a/tests/codeception/runsystemtests.sh b/tests/codeception/runsystemtests.sh new file mode 100755 index 0000000000000..676991e1dc425 --- /dev/null +++ b/tests/codeception/runsystemtests.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +printf "\nUpdating composer\n" +composer update +printf "\nDownloading Joomla\n" +php cli/getjoomlacli.php +printf "\nPreparing Codeception\n" +php vendor/bin/codecept build +printf "\nRunning Installation test\n" +php vendor/bin/codecept run tests/acceptance/installation --steps --debug +printf "\nSetting Error Reporting to Development\n" +php vendor/bin/codecept run tests/acceptance/administrator/setDevelopmentErrorReportingCept.php --steps \ No newline at end of file diff --git a/tests/codeception/tests/_bootstrap.php b/tests/codeception/tests/_bootstrap.php new file mode 100644 index 0000000000000..243f9c85bc6da --- /dev/null +++ b/tests/codeception/tests/_bootstrap.php @@ -0,0 +1,2 @@ +config[$element]; + } +} diff --git a/tests/codeception/tests/_support/FunctionalHelper.php b/tests/codeception/tests/_support/FunctionalHelper.php new file mode 100644 index 0000000000000..22cc714277faa --- /dev/null +++ b/tests/codeception/tests/_support/FunctionalHelper.php @@ -0,0 +1,10 @@ + "#mod-login-username", + 'password' => "#mod-login-password" + ); +} diff --git a/tests/codeception/tests/acceptance/administrator/_pages/system/globalconfigurationpage.php b/tests/codeception/tests/acceptance/administrator/_pages/system/globalconfigurationpage.php new file mode 100644 index 0000000000000..d04e911e124ab --- /dev/null +++ b/tests/codeception/tests/acceptance/administrator/_pages/system/globalconfigurationpage.php @@ -0,0 +1,27 @@ + "//div[@id='jform_error_reporting_chzn']/a", + 'option: Development' => "//div[@id='jform_error_reporting_chzn']/div/ul/li[contains(text(), 'Development')]", + ); +} diff --git a/tests/codeception/tests/acceptance/administrator/_steps/loginsteps.php b/tests/codeception/tests/acceptance/administrator/_steps/loginsteps.php new file mode 100644 index 0000000000000..f53a95d930e38 --- /dev/null +++ b/tests/codeception/tests/acceptance/administrator/_steps/loginsteps.php @@ -0,0 +1,30 @@ +am('Administrator'); + $I->amOnPage(\AdministratorLoginPage::$URL); + $I->fillField(\AdministratorLoginPage::$elements['username'], $user); + $I->fillField(\AdministratorLoginPage::$elements['password'], $password); + $I->click('Log in'); + $I->waitForText('Control Panel',10,'H1'); + } +} diff --git a/tests/codeception/tests/acceptance/administrator/setDevelopmentErrorReportingCept.php b/tests/codeception/tests/acceptance/administrator/setDevelopmentErrorReportingCept.php new file mode 100644 index 0000000000000..edbb17f01c2e9 --- /dev/null +++ b/tests/codeception/tests/acceptance/administrator/setDevelopmentErrorReportingCept.php @@ -0,0 +1,30 @@ +wantTo('set Joomla Error Reporting to Development'); + +// The following command is using a method defined in the Step Object (see _steps/loginsteps.php) +$I->doAdministratorLogin($I->getConfiguration('Username'), $I->getConfiguration('Password')); + +$I->amOnPage('/administrator/index.php?option=com_config'); + +$globalConfiguration = \GlobalconfigurationPage::$elements; +$I->waitForText('Global Configuration',10,'.page-title'); +$I->click('Server'); +$I->waitForElementVisible($globalConfiguration['Error Reporting Dropdown']); +$I->click($globalConfiguration['Error Reporting Dropdown']); +$I->click($globalConfiguration['option: Development']); +$I->click('Save'); +$I->waitForText('Global Configuration',10,'.page-title'); +$I->see('Configuration successfully saved.','#system-message-container'); \ No newline at end of file diff --git a/tests/codeception/tests/acceptance/installation/InstallJoomlaCept.php b/tests/codeception/tests/acceptance/installation/InstallJoomlaCept.php new file mode 100644 index 0000000000000..88b295d48ae8d --- /dev/null +++ b/tests/codeception/tests/acceptance/installation/InstallJoomlaCept.php @@ -0,0 +1,61 @@ +wantTo('Install Joomla CMS'); +$I->expect('no configuration.php is in the Joomla CMS folder'); +$I->dontSeeFileFound('configuration.php', $I->getConfiguration('Joomla folder')); + +$I->amOnPage('/installation/index.php'); + +// I Wait for the text Main Configuration, meaning that the page is loaded +$I->waitForText('Main Configuration',10,'h3'); + +// I instantiate the Installation Configuration Page Elements: +$configurationPage = \JoomlaInstallationConfigurationPage::$elements; +$I->click($configurationPage['Language Selector']); +$I->click($configurationPage[$I->getConfiguration('Language')]); +$I->fillField('Site Name','Joomla CMS test'); +$I->fillField('Description','Site for testing Joomla CMS'); +// I get the configuration from acceptance.suite.yml (see: tests/_support/acceptancehelper.php) +$I->fillField('Admin Email',$I->getConfiguration('Admin email')); +$I->fillField('Admin Username',$I->getConfiguration('Username')); +$I->fillField('Admin Password',$I->getConfiguration('Password')); +$I->fillField('Confirm Admin Password',$I->getConfiguration('Password')); +$I->click($configurationPage['No Site Offline']); +$I->click('Next'); + +$I->wantTo('Fill the form for creating the Joomla site Database'); +$I->waitForText('Database Configuration', 10, 'h3'); +// I instance the Install Joomla Database Page +$databasePage = \JoomlaInstallationDatabasePage::$elements; +$I->selectOption($databasePage['Database Type'], $I->getConfiguration('Database Type')); +$I->fillField('Host Name',$I->getConfiguration('Database Host')); +$I->fillField('Username',$I->getConfiguration('Database User')); +$I->fillField('Password',$I->getConfiguration('Database Password')); +$I->fillField('Database Name',$I->getConfiguration('Database Name')); +$I->fillField('Table Prefix',$I->getConfiguration('Database Prefix')); +$I->click($databasePage['Remove Old Database button']); +$I->click('Next'); + +$I->wantTo('Fill the form for creating the Joomla site database'); +$I->waitForText('Finalisation', 10, 'h3'); +$overviewPage = \JoomlaInstallationOverviewPage::$elements; + +if ($I->getConfiguration('Install Sample Data')) : + $I->selectOption($overviewPage['Sample Data'], $I->getConfiguration('Sample Data')); +else : + $I->selectOption($overviewPage['Sample Data'], $overviewPage['No sample Data']); +endif; + +$I->click('Install'); + +// Wait while Joomla gets installed +$I->waitForText('Congratulations! Joomla! is now installed.',30,'h3'); diff --git a/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationconfigurationpage.php b/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationconfigurationpage.php new file mode 100644 index 0000000000000..63d7a1b2993bd --- /dev/null +++ b/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationconfigurationpage.php @@ -0,0 +1,30 @@ + "//div[@id='jform_language_chzn']/a", + 'English (United Kingdom)' => "//li[text()='English (United Kingdom)']", + 'No Site Offline' => "//fieldset[@id='jform_site_offline']/label[2]" + ); +} diff --git a/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationdatabasepage.php b/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationdatabasepage.php new file mode 100644 index 0000000000000..5a2ea892529ea --- /dev/null +++ b/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationdatabasepage.php @@ -0,0 +1,30 @@ + "#jform_db_type", + 'Remove Old Database button' => "//label[@for='jform_db_old1']" + ); +} + diff --git a/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationoverviewpage.php b/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationoverviewpage.php new file mode 100644 index 0000000000000..806623932c992 --- /dev/null +++ b/tests/codeception/tests/acceptance/installation/_pages/joomlainstallationoverviewpage.php @@ -0,0 +1,30 @@ + '#jform_sample_file', + 'No sample Data' => '#jform_sample_file0', + 'Default English (GB) Sample Data' => '#jform_sample_file3' + ); +} diff --git a/tests/codeception/tests/functional.suite.yml b/tests/codeception/tests/functional.suite.yml new file mode 100644 index 0000000000000..3b17a39dc7c53 --- /dev/null +++ b/tests/codeception/tests/functional.suite.yml @@ -0,0 +1,9 @@ +# Codeception Test Suite Configuration + +# suite for functional (integration) tests. +# emulate web requests and make application process them. +# Include one of framework modules (Symfony2, Yii2, Laravel4) to use it. + +class_name: FunctionalTester +modules: + enabled: [Filesystem, FunctionalHelper] diff --git a/tests/codeception/tests/functional/_bootstrap.php b/tests/codeception/tests/functional/_bootstrap.php new file mode 100644 index 0000000000000..8a885558065a1 --- /dev/null +++ b/tests/codeception/tests/functional/_bootstrap.php @@ -0,0 +1,2 @@ +