2015-05-24 19:32:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This is project's console commands configuration for Robo task runner.
|
|
|
|
*
|
|
|
|
* Download robo.phar from http://robo.li/robo.phar and type in the root of the repo: $ php robo.phar
|
|
|
|
* Or do: $ composer update, and afterwards you will be able to execute robo like $ php vendor/bin/robo
|
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @package Joomla.Site
|
|
|
|
* @subpackage RoboFile
|
|
|
|
*
|
|
|
|
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
2015-05-24 19:32:32 +00:00
|
|
|
*/
|
|
|
|
|
2019-08-13 19:58:00 +00:00
|
|
|
use Joomla\Jorobo\Tasks\loadTasks as loadReleaseTasks;
|
|
|
|
use Joomla\Testing\Robo\Tasks\loadTasks as loadTestingTasks;
|
2019-08-13 02:18:48 +00:00
|
|
|
use Robo\Tasks;
|
|
|
|
|
2015-05-30 20:11:54 +00:00
|
|
|
require_once 'vendor/autoload.php';
|
2015-05-24 19:32:32 +00:00
|
|
|
|
2015-11-01 07:44:16 +00:00
|
|
|
if (!defined('JPATH_BASE'))
|
|
|
|
{
|
|
|
|
define('JPATH_BASE', __DIR__);
|
|
|
|
}
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
/**
|
|
|
|
* Modern php task runner for Joomla! Browser Automated Tests execution
|
|
|
|
*
|
|
|
|
* @package RoboFile
|
|
|
|
*
|
|
|
|
* @since 1.0
|
|
|
|
*/
|
2019-08-13 02:18:48 +00:00
|
|
|
class RoboFile extends Tasks
|
2015-05-24 19:32:32 +00:00
|
|
|
{
|
2015-05-30 20:11:54 +00:00
|
|
|
// Load tasks from composer, see composer.json
|
2019-08-13 19:58:00 +00:00
|
|
|
use loadTestingTasks;
|
|
|
|
use loadReleaseTasks;
|
2015-05-24 19:32:32 +00:00
|
|
|
|
2015-11-01 08:57:02 +00:00
|
|
|
/**
|
|
|
|
* File extension for executables
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $executableExtension = '';
|
2015-05-30 20:11:54 +00:00
|
|
|
|
2015-11-01 08:57:02 +00:00
|
|
|
/**
|
|
|
|
* Local configuration parameters
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-10-29 10:12:58 +00:00
|
|
|
private $configuration = array();
|
|
|
|
|
2015-11-01 08:57:02 +00:00
|
|
|
/**
|
|
|
|
* Path to the local CMS root
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2015-10-29 13:52:04 +00:00
|
|
|
private $cmsPath = '';
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
/**
|
|
|
|
* @var array | null
|
|
|
|
* @since version
|
|
|
|
*/
|
|
|
|
private $suiteConfig;
|
|
|
|
|
2015-10-31 10:31:08 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->configuration = $this->getConfiguration();
|
|
|
|
|
|
|
|
$this->cmsPath = $this->getCmsPath();
|
|
|
|
|
2015-11-01 08:57:02 +00:00
|
|
|
$this->executableExtension = $this->getExecutableExtension();
|
2015-11-02 10:22:39 +00:00
|
|
|
|
|
|
|
// Set default timezone (so no warnings are generated if it is not set)
|
|
|
|
date_default_timezone_set('UTC');
|
2015-10-31 10:31:08 +00:00
|
|
|
}
|
|
|
|
|
2015-05-30 20:11:54 +00:00
|
|
|
/**
|
2015-11-01 08:57:02 +00:00
|
|
|
* Get the executable extension according to Operating System
|
|
|
|
*
|
2019-08-13 02:18:48 +00:00
|
|
|
* @return string
|
2015-11-01 08:57:02 +00:00
|
|
|
*/
|
|
|
|
private function getExecutableExtension()
|
2015-05-30 20:11:54 +00:00
|
|
|
{
|
2015-10-30 09:38:10 +00:00
|
|
|
if ($this->isWindows())
|
2015-05-30 20:11:54 +00:00
|
|
|
{
|
2019-08-13 02:18:48 +00:00
|
|
|
return '.exe';
|
2015-05-30 19:31:14 +00:00
|
|
|
}
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-11-01 08:57:02 +00:00
|
|
|
return '';
|
2015-05-30 19:31:14 +00:00
|
|
|
}
|
2015-05-30 20:11:54 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-01 08:57:02 +00:00
|
|
|
* Executes all the Selenium System Tests in a suite on your machine
|
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @param array $opts Array of configuration options:
|
2019-08-13 02:18:48 +00:00
|
|
|
* - 'use-htaccess': renames and enable embedded Joomla .htaccess file
|
|
|
|
* - 'env': set a specific environment to get configuration from
|
2017-03-24 03:11:54 +00:00
|
|
|
*
|
2015-11-01 08:57:02 +00:00
|
|
|
* @return mixed
|
2019-08-13 02:18:48 +00:00
|
|
|
* @throws \Codeception\Exception\ConfigurationException
|
2015-11-01 08:57:02 +00:00
|
|
|
*/
|
2015-11-01 12:09:58 +00:00
|
|
|
public function runTests($opts = ['use-htaccess' => false, 'env' => 'desktop'])
|
2015-05-30 20:11:54 +00:00
|
|
|
{
|
2015-11-01 12:09:58 +00:00
|
|
|
$this->createTestingSite($opts['use-htaccess']);
|
2015-05-30 20:11:54 +00:00
|
|
|
|
2015-09-30 17:29:14 +00:00
|
|
|
$this->getComposer();
|
2015-05-30 20:11:54 +00:00
|
|
|
|
2015-09-30 17:29:14 +00:00
|
|
|
$this->taskComposerInstall()->run();
|
2015-05-30 20:11:54 +00:00
|
|
|
|
2015-09-30 17:29:14 +00:00
|
|
|
$this->runSelenium();
|
2015-05-24 19:32:32 +00:00
|
|
|
|
2015-10-30 15:38:49 +00:00
|
|
|
// Make sure to run the build command to generate AcceptanceTester
|
2015-10-30 15:11:05 +00:00
|
|
|
$this->_exec($this->isWindows() ? 'vendor\bin\codecept.bat build' : 'php vendor/bin/codecept build');
|
2015-05-24 19:32:32 +00:00
|
|
|
|
2015-09-30 17:29:14 +00:00
|
|
|
$this->taskCodecept()
|
|
|
|
->arg('--steps')
|
|
|
|
->arg('--debug')
|
|
|
|
->arg('--fail-fast')
|
2017-03-24 03:11:54 +00:00
|
|
|
->env($opts['env'])
|
2015-09-30 17:29:14 +00:00
|
|
|
->arg('tests/acceptance/install/')
|
2015-05-30 20:11:54 +00:00
|
|
|
->run()
|
|
|
|
->stopOnFail();
|
2015-05-24 19:32:32 +00:00
|
|
|
|
2015-09-30 17:29:14 +00:00
|
|
|
$this->taskCodecept()
|
|
|
|
->arg('--steps')
|
|
|
|
->arg('--debug')
|
|
|
|
->arg('--fail-fast')
|
2017-03-24 03:11:54 +00:00
|
|
|
->env($opts['env'])
|
2015-09-30 17:29:14 +00:00
|
|
|
->arg('tests/acceptance/administrator/')
|
|
|
|
->run()
|
|
|
|
->stopOnFail();
|
2015-05-30 20:11:54 +00:00
|
|
|
|
|
|
|
$this->taskCodecept()
|
|
|
|
->arg('--steps')
|
|
|
|
->arg('--debug')
|
2015-09-30 17:29:14 +00:00
|
|
|
->arg('--fail-fast')
|
2017-03-24 03:11:54 +00:00
|
|
|
->env($opts['env'])
|
2015-09-30 17:29:14 +00:00
|
|
|
->arg('tests/acceptance/frontend/')
|
2015-05-30 20:11:54 +00:00
|
|
|
->run()
|
|
|
|
->stopOnFail();
|
2015-11-01 12:09:58 +00:00
|
|
|
|
2015-05-30 20:11:54 +00:00
|
|
|
/*
|
2017-01-12 20:22:50 +00:00
|
|
|
Uncomment this lines if you need to debug selenium errors
|
2015-05-30 20:11:54 +00:00
|
|
|
$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) -----------');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2015-06-09 11:53:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes a specific Selenium System Tests in your machine
|
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @param string $pathToTestFile Optional name of the test to be run
|
|
|
|
* @param string $suite Optional name of the suite containing the tests, Acceptance by default.
|
2015-06-09 11:53:47 +00:00
|
|
|
*
|
|
|
|
* @return mixed
|
2019-08-13 02:18:48 +00:00
|
|
|
* @throws ReflectionException
|
|
|
|
* @throws \Codeception\Exception\ConfigurationException
|
2015-06-09 11:53:47 +00:00
|
|
|
*/
|
2015-09-30 17:29:14 +00:00
|
|
|
public function runTest($pathToTestFile = null, $suite = 'acceptance')
|
2015-06-09 11:53:47 +00:00
|
|
|
{
|
2015-09-30 17:29:14 +00:00
|
|
|
$this->runSelenium();
|
2015-06-09 11:53:47 +00:00
|
|
|
|
2015-10-30 15:38:49 +00:00
|
|
|
// Make sure to run the build command to generate AcceptanceTester
|
2015-10-30 15:11:05 +00:00
|
|
|
$this->_exec($this->isWindows() ? 'vendor\bin\codecept.bat build' : 'php vendor/bin/codecept build');
|
2015-06-09 11:53:47 +00:00
|
|
|
|
|
|
|
if (!$pathToTestFile)
|
|
|
|
{
|
|
|
|
$this->say('Available tests in the system:');
|
2015-09-30 17:29:14 +00:00
|
|
|
|
|
|
|
$iterator = new RecursiveIteratorIterator(
|
|
|
|
new RecursiveDirectoryIterator(
|
|
|
|
'tests/' . $suite,
|
|
|
|
RecursiveDirectoryIterator::SKIP_DOTS
|
|
|
|
),
|
|
|
|
RecursiveIteratorIterator::SELF_FIRST
|
|
|
|
);
|
|
|
|
|
|
|
|
$tests = array();
|
|
|
|
|
|
|
|
$iterator->rewind();
|
2015-06-09 11:53:47 +00:00
|
|
|
$i = 1;
|
2015-06-09 17:10:05 +00:00
|
|
|
|
2015-09-30 17:29:14 +00:00
|
|
|
while ($iterator->valid())
|
2015-06-09 11:53:47 +00:00
|
|
|
{
|
2015-09-30 17:29:14 +00:00
|
|
|
if (strripos($iterator->getSubPathName(), 'cept.php')
|
|
|
|
|| strripos($iterator->getSubPathName(), 'cest.php'))
|
2015-06-09 11:53:47 +00:00
|
|
|
{
|
2015-09-30 17:29:14 +00:00
|
|
|
$this->say('[' . $i . '] ' . $iterator->getSubPathName());
|
|
|
|
$tests[$i] = $iterator->getSubPathName();
|
2015-06-09 11:53:47 +00:00
|
|
|
$i++;
|
|
|
|
}
|
2015-09-30 17:29:14 +00:00
|
|
|
|
|
|
|
$iterator->next();
|
2015-06-09 11:53:47 +00:00
|
|
|
}
|
2015-06-09 17:10:05 +00:00
|
|
|
|
2015-06-09 11:53:47 +00:00
|
|
|
$this->say('');
|
2019-08-13 02:18:48 +00:00
|
|
|
$testNumber = $this->ask('Type the number of the test in the list that you want to run...');
|
|
|
|
$test = $tests[$testNumber];
|
2015-06-09 11:53:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 17:29:14 +00:00
|
|
|
$pathToTestFile = 'tests/' . $suite . '/' . $test;
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
// Loading the class to display the methods in the class
|
2015-10-31 16:04:54 +00:00
|
|
|
require 'tests/' . $suite . '/' . $test;
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
// Logic to fetch the class name from the file name
|
2019-08-13 02:18:48 +00:00
|
|
|
$fileName = explode("/", $test);
|
2015-10-31 16:04:54 +00:00
|
|
|
$className = explode(".", $fileName[1]);
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
// If the selected file is cest only than we will give the option to execute individual methods, we don't need this in cept file
|
2015-10-31 16:04:54 +00:00
|
|
|
$i = 1;
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-31 16:04:54 +00:00
|
|
|
if (strripos($className[0], 'cest'))
|
|
|
|
{
|
|
|
|
$class_methods = get_class_methods($className[0]);
|
|
|
|
$this->say('[' . $i . '] ' . 'All');
|
|
|
|
$methods[$i] = 'All';
|
|
|
|
$i++;
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-31 16:04:54 +00:00
|
|
|
foreach ($class_methods as $method_name)
|
|
|
|
{
|
|
|
|
$reflect = new ReflectionMethod($className[0], $method_name);
|
2017-01-12 20:22:50 +00:00
|
|
|
|
|
|
|
if (!$reflect->isConstructor())
|
2015-10-31 16:04:54 +00:00
|
|
|
{
|
|
|
|
if ($reflect->isPublic())
|
|
|
|
{
|
|
|
|
$this->say('[' . $i . '] ' . $method_name);
|
|
|
|
$methods[$i] = $method_name;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-31 16:04:54 +00:00
|
|
|
$this->say('');
|
|
|
|
$methodNumber = $this->ask('Please choose the method in the test that you would want to run...');
|
2019-08-13 02:18:48 +00:00
|
|
|
$method = $methods[$methodNumber];
|
2015-10-31 16:04:54 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
if (isset($method) && $method != 'All')
|
2015-10-31 16:04:54 +00:00
|
|
|
{
|
2015-11-01 15:19:12 +00:00
|
|
|
$pathToTestFile = $pathToTestFile . ':' . $method;
|
2015-10-31 16:04:54 +00:00
|
|
|
}
|
2015-11-01 15:19:12 +00:00
|
|
|
|
2015-06-09 11:53:47 +00:00
|
|
|
$this->taskCodecept()
|
2015-11-01 08:57:02 +00:00
|
|
|
->test($pathToTestFile)
|
|
|
|
->arg('--steps')
|
|
|
|
->arg('--debug')
|
|
|
|
->run()
|
|
|
|
->stopOnFail();
|
2015-06-09 11:53:47 +00:00
|
|
|
}
|
2015-10-29 10:14:35 +00:00
|
|
|
|
2015-10-31 11:54:14 +00:00
|
|
|
/**
|
|
|
|
* Run the specified checker tool. Valid options are phpmd, phpcs, phpcpd
|
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @param string $tool The tool
|
2015-10-31 11:54:14 +00:00
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @return bool
|
2015-10-31 11:54:14 +00:00
|
|
|
*/
|
2015-10-31 10:04:54 +00:00
|
|
|
public function runChecker($tool = null)
|
|
|
|
{
|
2017-01-12 20:22:50 +00:00
|
|
|
if ($tool === null)
|
|
|
|
{
|
2015-10-31 10:04:54 +00:00
|
|
|
$this->say('You have to specify a tool name as argument. Valid tools are phpmd, phpcs, phpcpd.');
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-31 10:04:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
if (!in_array($tool, array('phpmd', 'phpcs', 'phpcpd')))
|
|
|
|
{
|
2015-10-31 10:04:54 +00:00
|
|
|
$this->say('The tool you required is not known. Valid tools are phpmd, phpcs, phpcpd.');
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-31 10:04:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
switch ($tool)
|
|
|
|
{
|
2015-10-31 10:04:54 +00:00
|
|
|
case 'phpmd':
|
|
|
|
return $this->runPhpmd();
|
|
|
|
|
|
|
|
case 'phpcs':
|
|
|
|
return $this->runPhpcs();
|
|
|
|
|
|
|
|
case 'phpcpd':
|
|
|
|
return $this->runPhpcpd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 11:53:47 +00:00
|
|
|
/**
|
|
|
|
* Creates a testing Joomla site for running the tests (use it before run:test)
|
2015-10-30 09:43:37 +00:00
|
|
|
*
|
|
|
|
* @param bool $use_htaccess (1/0) Rename and enable embedded Joomla .htaccess file
|
2017-03-24 03:11:54 +00:00
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @return bool
|
2015-06-09 11:53:47 +00:00
|
|
|
*/
|
2015-10-30 09:43:37 +00:00
|
|
|
public function createTestingSite($use_htaccess = false)
|
2015-06-09 11:53:47 +00:00
|
|
|
{
|
2015-10-29 15:06:04 +00:00
|
|
|
if (!empty($this->configuration->skipClone))
|
|
|
|
{
|
2015-10-29 13:52:04 +00:00
|
|
|
$this->say('Reusing Joomla CMS site already present at ' . $this->cmsPath);
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-29 10:12:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-29 14:49:33 +00:00
|
|
|
// Caching cloned installations locally
|
|
|
|
if (!is_dir('tests/cache') || (time() - filemtime('tests/cache') > 60 * 60 * 24))
|
|
|
|
{
|
2015-11-02 11:11:36 +00:00
|
|
|
if (file_exists('tests/cache'))
|
|
|
|
{
|
|
|
|
$this->taskDeleteDir('tests/cache')->run();
|
|
|
|
}
|
|
|
|
|
2015-10-30 09:38:10 +00:00
|
|
|
$this->_exec($this->buildGitCloneCommand());
|
2015-10-29 10:12:58 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 11:53:47 +00:00
|
|
|
// Get Joomla Clean Testing sites
|
2015-10-29 13:52:04 +00:00
|
|
|
if (is_dir($this->cmsPath))
|
2015-06-09 11:53:47 +00:00
|
|
|
{
|
2015-10-31 10:09:22 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
$this->taskDeleteDir($this->cmsPath)->run();
|
|
|
|
}
|
|
|
|
catch (Exception $e)
|
|
|
|
{
|
|
|
|
// Sorry, we tried :(
|
|
|
|
$this->say('Sorry, you will have to delete ' . $this->cmsPath . ' manually. ');
|
|
|
|
exit(1);
|
|
|
|
}
|
2015-06-09 11:53:47 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 16:46:09 +00:00
|
|
|
$this->_copyDir('tests/cache', $this->cmsPath);
|
2015-10-30 14:56:05 +00:00
|
|
|
|
|
|
|
// Optionally change owner to fix permissions issues
|
|
|
|
if (!empty($this->configuration->localUser) && !$this->isWindows())
|
|
|
|
{
|
|
|
|
$this->_exec('chown -R ' . $this->configuration->localUser . ' ' . $this->cmsPath);
|
|
|
|
}
|
|
|
|
|
2015-11-01 07:44:16 +00:00
|
|
|
// Copy current package
|
|
|
|
if (!file_exists('dist/pkg-weblinks-current.zip'))
|
|
|
|
{
|
|
|
|
$this->build(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_copy('dist/pkg-weblinks-current.zip', $this->cmsPath . "/pkg-weblinks-current.zip");
|
|
|
|
|
2015-10-29 13:52:04 +00:00
|
|
|
$this->say('Joomla CMS site created at ' . $this->cmsPath);
|
2015-10-29 14:49:33 +00:00
|
|
|
|
2015-10-30 13:36:20 +00:00
|
|
|
// Optionally uses Joomla default htaccess file. Used by TravisCI
|
2015-10-30 09:43:37 +00:00
|
|
|
if ($use_htaccess == true)
|
|
|
|
{
|
2016-12-14 18:08:42 +00:00
|
|
|
$this->_copy('./tests/joomla/htaccess.txt', './tests/joomla/.htaccess');
|
|
|
|
$this->_exec('sed -e "s,# RewriteBase /,RewriteBase /tests/joomla/,g" -in-place tests/joomla/.htaccess');
|
2015-10-30 09:43:37 +00:00
|
|
|
}
|
2015-06-09 11:53:47 +00:00
|
|
|
}
|
2015-09-30 17:29:14 +00:00
|
|
|
|
2015-10-29 10:12:58 +00:00
|
|
|
/**
|
|
|
|
* Get (optional) configuration from an external file
|
|
|
|
*
|
2015-10-29 11:58:49 +00:00
|
|
|
* @return \stdClass|null
|
2015-10-29 10:12:58 +00:00
|
|
|
*/
|
|
|
|
public function getConfiguration()
|
|
|
|
{
|
|
|
|
$configurationFile = __DIR__ . '/RoboFile.ini';
|
2015-10-29 11:58:49 +00:00
|
|
|
|
2015-10-29 15:06:04 +00:00
|
|
|
if (!file_exists($configurationFile))
|
|
|
|
{
|
2015-10-29 10:12:58 +00:00
|
|
|
$this->say("No local configuration file");
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-29 11:58:49 +00:00
|
|
|
return null;
|
2015-10-29 10:12:58 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 11:58:49 +00:00
|
|
|
$configuration = parse_ini_file($configurationFile);
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-29 15:06:04 +00:00
|
|
|
if ($configuration === false)
|
|
|
|
{
|
2015-10-29 11:58:49 +00:00
|
|
|
$this->say('Local configuration file is empty or wrong (check is it in correct .ini format');
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2015-10-29 11:58:49 +00:00
|
|
|
return null;
|
2015-10-29 10:12:58 +00:00
|
|
|
}
|
2015-10-29 11:58:49 +00:00
|
|
|
|
|
|
|
return json_decode(json_encode($configuration));
|
2015-10-29 10:12:58 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 09:38:10 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2015-11-01 08:57:02 +00:00
|
|
|
return "git" . $this->executableExtension . " clone -b $branch --single-branch --depth 1 https://github.com/joomla/joomla-cms.git tests/cache";
|
2015-10-30 09:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if local OS is Windows
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isWindows()
|
|
|
|
{
|
|
|
|
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:52:04 +00:00
|
|
|
/**
|
|
|
|
* Get the correct CMS root path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getCmsPath()
|
|
|
|
{
|
2015-10-29 15:06:04 +00:00
|
|
|
if (empty($this->configuration->cmsPath))
|
|
|
|
{
|
2016-12-14 18:08:42 +00:00
|
|
|
return 'tests/joomla';
|
2015-10-29 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 15:06:04 +00:00
|
|
|
if (!file_exists(dirname($this->configuration->cmsPath)))
|
|
|
|
{
|
2015-10-29 13:52:04 +00:00
|
|
|
$this->say("Cms path written in local configuration does not exists or is not readable");
|
2017-01-12 20:22:50 +00:00
|
|
|
|
2016-12-14 18:08:42 +00:00
|
|
|
return 'tests/joomla';
|
2015-10-29 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->configuration->cmsPath;
|
|
|
|
}
|
|
|
|
|
2015-09-30 17:29:14 +00:00
|
|
|
/**
|
|
|
|
* Runs Selenium Standalone Server.
|
|
|
|
*
|
|
|
|
* @return void
|
2019-08-13 02:18:48 +00:00
|
|
|
* @throws \Codeception\Exception\ConfigurationException
|
2015-09-30 17:29:14 +00:00
|
|
|
*/
|
|
|
|
public function runSelenium()
|
|
|
|
{
|
2019-08-12 17:59:36 +00:00
|
|
|
if ($this->isWindows())
|
2015-09-30 17:29:14 +00:00
|
|
|
{
|
2019-08-12 17:59:36 +00:00
|
|
|
// TODO: Move this logic to the selenium standalone server task in the parent joomla repo
|
2019-08-13 02:18:48 +00:00
|
|
|
$this->_exec('START java.exe -jar ' . $this->getWebDriver() .
|
|
|
|
' .\\vendor\\joomla-projects\\selenium-server-standalone\\bin\\selenium-server-standalone.jar ');
|
2017-01-12 20:22:50 +00:00
|
|
|
sleep(3);
|
2015-09-30 17:29:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-12 17:59:36 +00:00
|
|
|
$this->taskSeleniumStandaloneServer()
|
2019-08-13 02:18:48 +00:00
|
|
|
->setWebdriver($this->getWebdriver())
|
2019-08-12 17:59:36 +00:00
|
|
|
->runSelenium()
|
|
|
|
->waitForSelenium()
|
2015-09-30 17:29:14 +00:00
|
|
|
->run()
|
|
|
|
->stopOnFail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Downloads Composer
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function getComposer()
|
|
|
|
{
|
|
|
|
// Make sure we have Composer
|
|
|
|
if (!file_exists('./composer.phar'))
|
|
|
|
{
|
2016-10-15 13:47:47 +00:00
|
|
|
$insecure = '';
|
|
|
|
|
|
|
|
if (!empty($this->configuration->insecure))
|
|
|
|
{
|
|
|
|
$insecure = '--insecure';
|
|
|
|
}
|
|
|
|
|
2015-10-31 10:28:05 +00:00
|
|
|
$this->_exec('curl ' . $insecure . ' --retry 3 --retry-delay 5 -sS https://getcomposer.org/installer | php');
|
2015-09-30 17:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-30 10:27:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Kills the selenium server running
|
|
|
|
*
|
|
|
|
* @param string $host Web host of the remote server.
|
|
|
|
* @param string $port Server port.
|
2017-03-24 03:11:54 +00:00
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @return void
|
2015-10-30 10:27:28 +00:00
|
|
|
*/
|
|
|
|
public function killSelenium($host = 'localhost', $port = '4444')
|
|
|
|
{
|
|
|
|
$this->say('Trying to kill the selenium server.');
|
2019-08-13 23:24:46 +00:00
|
|
|
|
|
|
|
$this->taskSeleniumStandaloneServer()
|
|
|
|
->setUrl("http://$host:$port")
|
|
|
|
->killSelenium()
|
|
|
|
->run()
|
|
|
|
->stopOnFail();
|
2015-10-30 10:27:28 +00:00
|
|
|
}
|
2015-10-31 10:04:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the phpmd tool
|
2017-03-24 03:11:54 +00:00
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @return void
|
2015-10-31 10:04:54 +00:00
|
|
|
*/
|
|
|
|
private function runPhpmd()
|
|
|
|
{
|
|
|
|
return $this->_exec('phpmd' . $this->extension . ' ' . __DIR__ . '/src xml cleancode,codesize,controversial,design,naming,unusedcode');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the phpcs tool
|
2017-03-24 03:11:54 +00:00
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @return void
|
2015-10-31 10:04:54 +00:00
|
|
|
*/
|
|
|
|
private function runPhpcs()
|
|
|
|
{
|
|
|
|
$this->_exec('phpcs' . $this->extension . ' ' . __DIR__ . '/src');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the phpcpd tool
|
2017-03-24 03:11:54 +00:00
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @return void
|
2015-10-31 10:04:54 +00:00
|
|
|
*/
|
|
|
|
private function runPhpcpd()
|
|
|
|
{
|
|
|
|
$this->_exec('phpcpd' . $this->extension . ' ' . __DIR__ . '/src');
|
|
|
|
}
|
2015-11-01 07:44:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the joomla extension package
|
|
|
|
*
|
|
|
|
* @param array $params Additional params
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function build($params = ['dev' => false])
|
|
|
|
{
|
2016-02-01 12:36:56 +00:00
|
|
|
if (!file_exists('jorobo.ini'))
|
2015-11-01 07:44:16 +00:00
|
|
|
{
|
2016-02-01 12:36:56 +00:00
|
|
|
$this->_copy('jorobo.dist.ini', 'jorobo.ini');
|
2015-11-01 07:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->taskBuild($params)->run();
|
|
|
|
}
|
2016-02-24 19:15:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes all unit tests
|
2017-03-24 03:11:54 +00:00
|
|
|
*
|
2017-01-12 20:22:50 +00:00
|
|
|
* @return void
|
2016-02-24 19:15:38 +00:00
|
|
|
*/
|
|
|
|
public function runUnit()
|
|
|
|
{
|
|
|
|
$this->createTestingSite();
|
|
|
|
$this->getComposer();
|
|
|
|
$this->taskComposerInstall()->run();
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
->suite('unit')
|
|
|
|
->run()
|
|
|
|
->stopOnFail();
|
|
|
|
}
|
2016-10-22 22:08:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update copyright headers for this project. (Set the text up in the jorobo.ini)
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function headers()
|
|
|
|
{
|
|
|
|
if (!file_exists('jorobo.ini'))
|
|
|
|
{
|
|
|
|
$this->_copy('jorobo.dist.ini', 'jorobo.ini');
|
|
|
|
}
|
|
|
|
|
2017-01-12 20:22:50 +00:00
|
|
|
(new \Joomla\Jorobo\Tasks\CopyrightHeader)->run();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detect the correct driver for selenium
|
|
|
|
*
|
|
|
|
* @return string the webdriver string to use with selenium
|
|
|
|
*
|
|
|
|
* @since version
|
2019-08-13 02:18:48 +00:00
|
|
|
* @throws \Codeception\Exception\ConfigurationException
|
2017-01-12 20:22:50 +00:00
|
|
|
*/
|
|
|
|
public function getWebdriver()
|
|
|
|
{
|
|
|
|
$suiteConfig = $this->getSuiteConfig();
|
|
|
|
$codeceptMainConfig = \Codeception\Configuration::config();
|
|
|
|
$browser = $suiteConfig['modules']['config']['JoomlaBrowser']['browser'];
|
|
|
|
|
|
|
|
if ($browser == 'chrome')
|
|
|
|
{
|
|
|
|
$driver['type'] = 'webdriver.chrome.driver';
|
|
|
|
}
|
|
|
|
elseif ($browser == 'firefox')
|
|
|
|
{
|
|
|
|
$driver['type'] = 'webdriver.gecko.driver';
|
|
|
|
}
|
|
|
|
elseif ($browser == 'MicrosoftEdge')
|
|
|
|
{
|
|
|
|
$driver['type'] = 'webdriver.edge.driver';
|
|
|
|
|
|
|
|
// Check if we are using Windows Insider builds
|
|
|
|
if ($suiteConfig['modules']['config']['AcceptanceHelper']['MicrosoftEdgeInsiders'])
|
|
|
|
{
|
|
|
|
$browser = 'MicrosoftEdgeInsiders';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($browser == 'internet explorer')
|
|
|
|
{
|
|
|
|
$driver['type'] = 'webdriver.ie.driver';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we have a path for this browser and OS in the codeception settings
|
|
|
|
if (isset($codeceptMainConfig['webdrivers'][$browser][$this->getOs()]))
|
|
|
|
{
|
|
|
|
$driverPath = $codeceptMainConfig['webdrivers'][$browser][$this->getOs()];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->yell(
|
2019-08-13 02:18:48 +00:00
|
|
|
print_r($codeceptMainConfig) .
|
|
|
|
'No driver for your browser. Check your browser in acceptance.suite.yml and the webDrivers in codeception.yml');
|
2017-01-12 20:22:50 +00:00
|
|
|
|
|
|
|
// We can't do anything without a driver, exit
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$driver['path'] = $driverPath;
|
|
|
|
|
|
|
|
return '-D' . implode('=', $driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the suite configuration
|
|
|
|
*
|
|
|
|
* @param string $suite The suite
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getSuiteConfig($suite = 'acceptance')
|
|
|
|
{
|
|
|
|
if (!$this->suiteConfig)
|
|
|
|
{
|
|
|
|
$this->suiteConfig = Symfony\Component\Yaml\Yaml::parse(file_get_contents("tests/{$suite}.suite.yml"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->suiteConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the os name
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*
|
|
|
|
* @since version
|
|
|
|
*/
|
|
|
|
private function getOs()
|
|
|
|
{
|
|
|
|
$os = php_uname('s');
|
|
|
|
|
|
|
|
if (strpos(strtolower($os), 'windows') !== false)
|
|
|
|
{
|
|
|
|
$os = 'windows';
|
|
|
|
}
|
|
|
|
// Who have thought that Mac is actually Darwin???
|
|
|
|
elseif (strpos(strtolower($os), 'darwin') !== false)
|
|
|
|
{
|
|
|
|
$os = 'mac';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$os = 'linux';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $os;
|
2016-10-22 22:08:16 +00:00
|
|
|
}
|
2017-01-14 10:22:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update Version __DEPLOY_VERSION__ in Weblinks. (Set the version up in the jorobo.ini)
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function bump()
|
|
|
|
{
|
|
|
|
(new \Joomla\Jorobo\Tasks\BumpVersion())->run();
|
|
|
|
}
|
2017-11-06 11:55:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map into Joomla installation.
|
|
|
|
*
|
|
|
|
* @param String $target The target joomla instance
|
|
|
|
*
|
2019-08-13 02:18:48 +00:00
|
|
|
* @return void
|
2017-11-06 11:55:24 +00:00
|
|
|
* @since __DEPLOY_VERSION__
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function map($target)
|
|
|
|
{
|
|
|
|
(new \Joomla\Jorobo\Tasks\Map($target))->run();
|
|
|
|
}
|
2015-06-09 17:10:05 +00:00
|
|
|
}
|