From 17d223b4c1e8240a9246690b957ee5cc5f0f7552 Mon Sep 17 00:00:00 2001 From: javier gomez Date: Sun, 24 May 2015 21:32:32 +0200 Subject: [PATCH] Add system tests codebase This pull adds the base for testing Weblinks component with an Firefox automated browser via Selenium and Codeception Framework. See it in action in the following video: https://www.youtube.com/watch?v=gpsZVZCsawg This pull will launch the tests in Travis, however you can run the tests in your local machine too. Find the instructions at: README.md --- .gitignore | 54 +++++++++++- .travis.yml | 31 +++++++ README.md | 11 +++ RoboFile.php | 85 +++++++++++++++++++ codeception.yml | 17 ++++ composer.json | 14 +++ tests/_bootstrap.php | 2 + tests/_data/dump.sql | 1 + .../acceptance/01-Install_Weblinks.txt | 10 +++ tests/_support/AcceptanceHelper.php | 25 ++++++ tests/_support/FunctionalHelper.php | 10 +++ tests/_support/UnitHelper.php | 10 +++ tests/acceptance.suite.dist.yml | 40 +++++++++ tests/acceptance/01-InstallWeblinksCest.php | 28 ++++++ .../AdministratorCategoriesCest.php | 55 ++++++++++++ tests/acceptance/_bootstrap.php | 2 + tests/functional.suite.yml | 9 ++ tests/functional/_bootstrap.php | 2 + tests/unit.suite.yml | 6 ++ tests/unit/_bootstrap.php | 2 + 20 files changed, 413 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 RoboFile.php create mode 100644 codeception.yml create mode 100644 composer.json create mode 100644 tests/_bootstrap.php create mode 100644 tests/_data/dump.sql create mode 100644 tests/_data/scenarios/acceptance/01-Install_Weblinks.txt create mode 100644 tests/_support/AcceptanceHelper.php create mode 100644 tests/_support/FunctionalHelper.php create mode 100644 tests/_support/UnitHelper.php create mode 100644 tests/acceptance.suite.dist.yml create mode 100644 tests/acceptance/01-InstallWeblinksCest.php create mode 100644 tests/acceptance/AdministratorCategoriesCest.php create mode 100644 tests/acceptance/_bootstrap.php create mode 100644 tests/functional.suite.yml create mode 100644 tests/functional/_bootstrap.php create mode 100644 tests/unit.suite.yml create mode 100644 tests/unit/_bootstrap.php diff --git a/.gitignore b/.gitignore index 0515599..e0c78b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,56 @@ -.idea +# Builds build releases + +# OSX .DS_Store +._* +.Spotlight-V100 +.Trashes + +# Windows +Thumbs.db +Desktop.ini + +# PHPStorm +.idea/ + +# Sublime Text +*.sublime* + +# Eclipse +.buildpath +.project +.settings + +# Temp files +*.tmp +*.bak +*.swp +*~.nib +*~ + +# Phing +build.properties +phing-latest.phar + +# Github pages and Jekyll files +/_site/ +/Gemfile +/Gemfile.lock + +# composer +composer.lock +composer.phar +vendor/* + +# Robo +robo.phar + +# Test related files +tests/acceptance.suite.yml +tests/*/*Tester.php +tests/joomla-cms3* +selenium-server-standalone.jar +codecept.phar +selenium.log diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..96e906a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: php +php: +- 5.4 +- 5.5 +- 5.6 +- 7.0 +before_script: +- sudo apt-get update -qq +# Install Apache +- sudo apt-get install -y --force-yes apache2 libapache2-mod-php5 php5-curl php5-mysql php5-intl php5-gd > /dev/null +- sudo /etc/init.d/apache2 stop +- sudo sed -i -e "s,APACHE_RUN_USER=www-data,APACHE_RUN_USER=$USER,g" /etc/apache2/envvars +- sudo sed -i -e "s,APACHE_RUN_GROUP=www-data,APACHE_RUN_GROUP=$USER,g" /etc/apache2/envvars +- sudo chown -R $USER /var/lock/apache2 +- sudo chown -R $USER:$USER /var/www +- ln -s $TRAVIS_BUILD_DIR/tests/ /var/www/tests +- sudo sed -i -e "s,AllowOverride[ ]None,AllowOverride All,g" /etc/apache2/sites-available/default +- sudo /etc/init.d/apache2 start +# Xvfb +- "export DISPLAY=:99.0" +- "sh -e /etc/init.d/xvfb start" +- sleep 3 # give xvfb some time to start +# Fluxbox +- sudo apt-get install fluxbox -y --force-yes +- fluxbox & +- sleep 3 # give fluxbox some time to start +- composer update + +script: +- mv tests/acceptance.suite.dist.yml tests/acceptance.suite.yml +- php vendor/bin/robo test:acceptance diff --git a/README.md b/README.md index b69f128..6a3ea40 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # Weblinks for Joomla! This repo is meant to hold the decoupled com_weblinks component and related code. + +# Tests +To prepare the system tests (Selenium) to be run in your local machine you are asked to rename the file `tests/acceptance.suite.dist.yml` to `tests/acceptance.suite.yml`. Afterwards, please edit the file according to your system needs. + +To run the tests please execute the following commands (for the moment only working in Linux and MacOS, for more information see: https://docs.joomla.org/Testing_Joomla_Extensions_with_Codeception): + +```bash +$ composer update +$ vendor/bin/robo +$ vendor/bin/robo test:acceptance +``` diff --git a/RoboFile.php b/RoboFile.php new file mode 100644 index 0000000..75754ba --- /dev/null +++ b/RoboFile.php @@ -0,0 +1,85 @@ +taskDeleteDir('tests/joomla-cms3')->run(); + } + + $this->_exec('git clone -b staging --single-branch --depth 1 https://github.com/joomla/joomla-cms.git tests/joomla-cms3'); + $this->say('Joomla CMS site created at tests/joomla-cms3'); + + if (!$seleniumPath) { + if (!file_exists('selenium-server-standalone.jar')) { + $this->say('Downloading Selenium Server, this may take a while.'); + $this->taskExec('wget') + ->arg('http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar') + ->arg('-O selenium-server-standalone.jar') + ->printed(false) + ->run(); + } + $seleniumPath = 'selenium-server-standalone.jar'; + } + + // Make sure we have Composer + if (!file_exists('./composer.phar')) { + $this->_exec('curl -sS https://getcomposer.org/installer | php'); + } + $this->taskComposerUpdate()->run(); + + // Running Selenium server + $this->_exec("java -jar $seleniumPath >> selenium.log 2>&1 &"); + + $this->taskWaitForSeleniumStandaloneServer() + ->run() + ->stopOnFail(); + + // Loading Symfony Command and running with passed argument + $this->_exec('php vendor/bin/codecept build'); + + $this->taskCodecept() + ->suite('acceptance') + ->arg('--steps') + ->arg('--debug') + ->run() + ->stopOnFail(); + + // Kill selenium server + // $this->_exec('curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer'); + + /* + // Uncomment this lines if you need to debug selenium errors + $seleniumErrors = file_get_contents('selenium.log'); + if ($seleniumErrors) { + $this->say('Printing Selenium Log files'); + $this->say('------ selenium.log (start) ---------'); + $this->say($seleniumErrors); + $this->say('------ selenium.log (end) -----------'); + } + */ + } +} \ No newline at end of file diff --git a/codeception.yml b/codeception.yml new file mode 100644 index 0000000..306e739 --- /dev/null +++ b/codeception.yml @@ -0,0 +1,17 @@ +actor: Tester +paths: + tests: tests + log: tests/_output + data: tests/_data + helpers: tests/_support +settings: + bootstrap: _bootstrap.php + colors: true + memory_limit: 1024M +modules: + config: + Db: + dsn: '' + user: '' + password: '' + dump: tests/_data/dump.sql diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..00b70ea --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name" : "joomla-extensions/weblinks", + "description": "The Open Source PHP Framework for creating complex Joomla extensions", + "license" : "GPL-2.0+", + "require" : { + "php": ">=5.3.10" + }, + "require-dev": { + "codeception/codeception": "2.0.13", + "joomla-projects/joomla-browser": "dev-develop", + "codegyre/robo": "~0.5", + "joomla-projects/robo": "dev-master" + } +} diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php new file mode 100644 index 0000000..243f9c8 --- /dev/null +++ b/tests/_bootstrap.php @@ -0,0 +1,2 @@ +config[$element]; + } +} diff --git a/tests/_support/FunctionalHelper.php b/tests/_support/FunctionalHelper.php new file mode 100644 index 0000000..22cc714 --- /dev/null +++ b/tests/_support/FunctionalHelper.php @@ -0,0 +1,10 @@ +am('Administrator'); + $I->installJoomla(); + $I->doAdministratorLogin(); + $I->setErrorReportingToDevelopment(); + + $I->comment('get Weblinks repository folder from acceptance.suite.yml (see _support/AcceptanceHelper.php)'); + $path = $I->getConfiguration('repo_folder'); + $I->installExtensionFromDirectory($path . 'src/com_weblinks/'); + $I->doAdministratorLogout(); + + } +} \ No newline at end of file diff --git a/tests/acceptance/AdministratorCategoriesCest.php b/tests/acceptance/AdministratorCategoriesCest.php new file mode 100644 index 0000000..36edbc2 --- /dev/null +++ b/tests/acceptance/AdministratorCategoriesCest.php @@ -0,0 +1,55 @@ +am('Administrator'); + $I->wantToTest('Category creation in /administrator/'); + + $I->doAdministratorLogin(); + + $I->amGoingTo('Navigate to Categories page in /administrator/'); + $I->amOnPage('administrator/index.php?option=com_categories&extension=com_weblinks'); + $I->waitForText('Category Manager: Weblinks','5',['css' => 'h1']); + $I->expectTo('see categories page'); + $I->checkForPhpNoticesOrWarnings(); + + $I->amGoingTo('try to save a category with a filled title'); + $I->click(['xpath'=> "//button[@onclick=\"Joomla.submitbutton('category.add')\"]"]); + $I->waitForText('Category Manager: Add A New Weblinks Category','5',['css' => 'h1']); + $I->fillField(['id' => 'jform_title'],'automated testing' . rand(1,100)); + $I->click(['xpath'=> "//button[@onclick=\"Joomla.submitbutton('category.apply')\"]"]); + $I->expectTo('see a success message after saving the category'); + $I->see('Category successfully saved',['id' => 'system-message-container']); + } + + public function administratorCreateCategoryWithoutTitleFails(AcceptanceTester $I) + { + $I->am('Administrator'); + $I->wantToTest('Category creation in /administrator/ without title'); + + $I->doAdministratorLogin(); + + $I->amGoingTo('Navigate to Categories page in /administrator/'); + $I->amOnPage('administrator/index.php?option=com_categories&extension=com_weblinks'); + $I->waitForText('Category Manager: Weblinks','5',['css' => 'h1']); + $I->expectTo('see categories page'); + + $I->amGoingTo('try to save a category with empty title and it should fail'); + $I->click(['xpath'=> "//button[@onclick=\"Joomla.submitbutton('category.add')\"]"]); + $I->waitForText('Category Manager: Add A New Weblinks Category','5',['css' => 'h1']); + $I->click(['xpath'=> "//button[@onclick=\"Joomla.submitbutton('category.apply')\"]"]); + $I->expectTo('see an error when trying to save a category without title'); + $I->see('Invalid field: Title',['id' => 'system-message-container']); + } +} \ No newline at end of file diff --git a/tests/acceptance/_bootstrap.php b/tests/acceptance/_bootstrap.php new file mode 100644 index 0000000..8a88555 --- /dev/null +++ b/tests/acceptance/_bootstrap.php @@ -0,0 +1,2 @@ +