Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pr/105
Browse files Browse the repository at this point in the history
  • Loading branch information
javigomez committed Oct 31, 2015
2 parents 28d96c3 + 3f6288b commit 7fb20c1
Show file tree
Hide file tree
Showing 9 changed files with 438 additions and 216 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ vendor/*

# Robo
robo.phar
RoboFile.ini

# Test related files
tests/acceptance.suite.yml
Expand All @@ -55,3 +56,4 @@ tests/_output*
selenium-server-standalone.jar
codecept.phar
selenium.log
tests/cache
32 changes: 19 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@ language: php
php:
- 5.5
- 5.6
- 7.0
matrix:
allow_failures:
- php: 5.6
- php: 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
- sudo apt-get install -y --force-yes apache2 libapache2-mod-fastcgi php5-curl php5-mysql php5-intl php5-gd > /dev/null
- sudo mkdir $(pwd)/.run
- sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo sed -e "s,listen = 127.0.0.1:9000,listen = /tmp/php5-fpm.sock,g" --in-place ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo sed -e "s,;listen.owner = nobody,listen.owner = $USER,g" --in-place ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo sed -e "s,;listen.group = nobody,listen.group = $USER,g" --in-place ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo sed -e "s,;listen.mode = 0660,listen.mode = 0666,g" --in-place ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo sed -e "s,user = nobody,;user = $USER,g" --in-place ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo sed -e "s,group = nobody,;group = $USER,g" --in-place ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- cat ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo a2enmod rewrite actions fastcgi alias
- echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
- sudo cp -f tests/travis-ci-apache.conf /etc/apache2/sites-available/default
- sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/default
- git submodule update --init --recursive
- sudo service apache2 restart
# Xvfb
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
Expand All @@ -27,8 +32,9 @@ before_script:
- sudo apt-get install fluxbox -y --force-yes
- fluxbox &
- sleep 3 # give fluxbox some time to start
# Composer
- composer install

script:
- mv tests/acceptance.suite.dist.yml tests/acceptance.suite.yml
- vendor/bin/robo run:tests
- vendor/bin/robo run:tests true
57 changes: 46 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ 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.

## Optional: extra configuration for RoboFile

This is not required, and if in doubt you can just skip this section, but there may be some specific use cases when you need (or want) to override the default behaviour of RoboFile.php. To do this, copy `RoboFile.dist.ini` to `RoboFile.ini` and add options in INI format, one per line, e.g.

skipClone = true
cmsPath = tests/joomla-cms3

The currently available options are as follows:

* `skipClone`: set to `true` to avoid the cms repo being deleted and re-cloned at each test execution. Useful to save time and bandwidth while you're debugging your test environment. But please be aware that if you don't refresh the repo you'll have to manually check the `installation` folder is present and the `configuration.php` is not.
* `cmsPath`: set to the local path (absolute or relative) where you'd like the test website to be installed. Default is `tests/joomla-cms3`.
* `branch`: set to whatever existing branch from the `joomla-cms` project if you want to clone that specific branch. Default is `staging`.

## Run the tests

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
Expand All @@ -13,25 +28,45 @@ $ vendor/bin/robo
$ vendor/bin/robo run:tests
```


##For Windows:

You need to install:
- Git for windows (https://msysgit.github.io/)
- GitHub for windows (https://windows.github.com/)
- Curl for windows if necesssary.
- Curl for Windows if necesssary.

Note: For commands line is better if you use the 'Git shell' program.

Create a symbolic link from your tests\joomla-cms3 to a subfolder of your web server. For example, I'm creating a link between the tests folder of my weblinks folder and the tests folder of my web server:
mklink /J C:\wamp\www\tests\joomla-cms3 C:\Users\Nicolas\Documents\GitHub\weblinks\tests\joomla-cms3
First you should create a fork of the official repository and clone the fork into your web server folder.

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.

The next step is only required if you don't place the weblinks folder into your web server folder. Create a symbolic link from your tests\joomla-cms3 to a subfolder of your web server. For example:

```bash
mklink /J C:\wamp\www\tests\joomla-cms3 C:\Users\Name\Documents\GitHub\weblinks\tests\joomla-cms3
```

Open the console and go in the folder of weblinks, for example:

Go in the folder of weblinks, for example:
cd C:\Users\Nicolas\Documents\GitHub\weblinks
```bash
cd C:\wamp\www\weblinks
```

Then run the command:

```bash
$ composer install
```

Then, run the command:
composer install
You can then run the following command to start the tests:

That will add all the dependencies for the testing of weblinks
You can then run the command:
vendor\bin\robo.bat test:acceptance
```bash
$ vendor/bin/robo run:tests
```

Once all tests were executed, you may also run a specific test:

```bash
$ vendor/bin/robo run:test // Then select the test you want to run!
```
10 changes: 10 additions & 0 deletions RoboFile.dist.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; If set to true, the repo will not be cloned from GitHub and the local copy will be reused.
; This setting will be obsolete once we have local Git cache enabled
skipClone = false

; If you want to setup your test website in a different folder, you can do that here.
; You can also set an absolute path, i.e. /path/to/my/cms/folder
cmsPath = tests/joomla-cms3

; If you want to clone a different branch, you can set it here
branch = staging
143 changes: 123 additions & 20 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ class RoboFile extends \Robo\Tasks

private $extension = '';

private $configuration = array();

private $cmsPath = '';

/**
* Set the Execute extension for Windows Operating System
*
* @return void
*/
private function setExecExtension()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
if ($this->isWindows())
{
$this->extension = '.exe';
}
Expand All @@ -33,24 +37,28 @@ private function setExecExtension()
/**
* Executes all the Selenium System Tests in a suite on your machine
*
* @param string $seleniumPath Optional path to selenium-standalone-server-x.jar
* @param string $suite Optional, the name of the tests suite
* @param bool $use_htaccess Renames and enable embedded Joomla .htaccess file
*
* @return mixed
*/
public function runTests($seleniumPath = null, $suite = 'acceptance')
public function runTests($use_htaccess = false)
{
$this->configuration = $this->getConfiguration();

$this->cmsPath = $this->getCmsPath();

$this->setExecExtension();

$this->createTestingSite();
$this->createTestingSite($use_htaccess);

$this->getComposer();

$this->taskComposerInstall()->run();

$this->runSelenium();

$this->_exec('php' . $this->extension . ' vendor/bin/codecept build');
// Make sure to run the build command to generate AcceptanceTester
$this->_exec($this->isWindows() ? 'vendor\bin\codecept.bat build' : 'php vendor/bin/codecept build');

$this->taskCodecept()
->arg('--steps')
Expand All @@ -75,10 +83,6 @@ public function runTests($seleniumPath = null, $suite = 'acceptance')
->arg('tests/acceptance/frontend/')
->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');
Expand All @@ -104,8 +108,8 @@ public function runTest($pathToTestFile = null, $suite = 'acceptance')
{
$this->runSelenium();

// Make sure to Run the Build Command to Generate AcceptanceTester
$this->_exec("php vendor/bin/codecept build");
// Make sure to run the build command to generate AcceptanceTester
$this->_exec($this->isWindows() ? 'vendor\bin\codecept.bat build' : 'php vendor/bin/codecept build');

if (!$pathToTestFile)
{
Expand Down Expand Up @@ -150,24 +154,111 @@ public function runTest($pathToTestFile = null, $suite = 'acceptance')
->arg('--debug')
->run()
->stopOnFail();

// Kill selenium server
// $this->_exec('curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer');
}

/**
* Creates a testing Joomla site for running the tests (use it before run:test)
*
* @param bool $use_htaccess (1/0) Rename and enable embedded Joomla .htaccess file
*/
public function createTestingSite()
public function createTestingSite($use_htaccess = false)
{
if (!empty($this->configuration->skipClone))
{
$this->say('Reusing Joomla CMS site already present at ' . $this->cmsPath);
return;
}

// Caching cloned installations locally
if (!is_dir('tests/cache') || (time() - filemtime('tests/cache') > 60 * 60 * 24))
{
$this->_exec($this->buildGitCloneCommand());
}

// Get Joomla Clean Testing sites
if (is_dir('tests/joomla-cms3'))
if (is_dir($this->cmsPath))
{
$this->taskDeleteDir($this->cmsPath)->run();
}

$this->_copyDir('tests/cache', $this->cmsPath);
$this->say('Joomla CMS site created at ' . $this->cmsPath);

// Optionally uses Joomla default htaccess file. Used by TravisCI
if ($use_htaccess == true)
{
$this->_copy('/tests/joomla-cms3/htaccess.txt', 'tests/joomla-cms3/.htaccess');
$this->_exec('sed -e "s,# RewriteBase /,RewriteBase /tests/joomla-cms3/,g" --in-place tests/joomla-cms3/.htaccess');
}
}

/**
* Get (optional) configuration from an external file
*
* @return \stdClass|null
*/
public function getConfiguration()
{
$configurationFile = __DIR__ . '/RoboFile.ini';

if (!file_exists($configurationFile))
{
$this->say("No local configuration file");
return null;
}

$configuration = parse_ini_file($configurationFile);
if ($configuration === false)
{
$this->taskDeleteDir('tests/joomla-cms3')->run();
$this->say('Local configuration file is empty or wrong (check is it in correct .ini format');
return null;
}

$this->_exec('git' . $this->extension . ' 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');
return json_decode(json_encode($configuration));
}

/**
* Build correct git clone command according to local configuration and OS
*
* @return string
*/
private function buildGitCloneCommand()
{
$branch = empty($this->configuration->branch) ? 'staging' : $this->configuration->branch;
$insecure = $this->isWindows() ? ' --insecure' : '';

return "git" . $this->extension . " clone -b $branch $insecure --single-branch --depth 1 https://github.com/joomla/joomla-cms.git tests/cache";
}

/**
* Check if local OS is Windows
*
* @return bool
*/
private function isWindows()
{
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}

/**
* Get the correct CMS root path
*
* @return string
*/
private function getCmsPath()
{
if (empty($this->configuration->cmsPath))
{
return 'tests/joomla-cms3';
}

if (!file_exists(dirname($this->configuration->cmsPath)))
{
$this->say("Cms path written in local configuration does not exists or is not readable");
return 'tests/joomla-cms3';
}

return $this->configuration->cmsPath;
}

/**
Expand Down Expand Up @@ -211,4 +302,16 @@ private function getComposer()
$this->_exec('curl --retry 3 --retry-delay 5 -sS https://getcomposer.org/installer | php');
}
}

/**
* Kills the selenium server running
*
* @param string $host Web host of the remote server.
* @param string $port Server port.
*/
public function killSelenium($host = 'localhost', $port = '4444')
{
$this->say('Trying to kill the selenium server.');
$this->_exec("curl http://$host:$port/selenium-server/driver/?cmd=shutDownSeleniumServer");
}
}
Loading

0 comments on commit 7fb20c1

Please sign in to comment.