update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* Piwik - Open source web analytics
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
@ -24,54 +24,53 @@ class GenerateTest extends GeneratePluginBase
->setDescription('Adds a test to an existing plugin')
->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin')
->addOption('testname', null, InputOption::VALUE_REQUIRED, 'The name of the test to create')
->addOption('testtype', null, InputOption::VALUE_REQUIRED, 'Whether you want to create a "unit", "integration" or "database" test');
->addOption('testtype', null, InputOption::VALUE_REQUIRED, 'Whether you want to create a "unit", "integration", "system", or "ui" test');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginName = $this->getPluginName($input, $output);
$testName = $this->getTestName($input, $output);
$testType = $this->getTestType($input, $output);
$testName = $this->getTestName($input, $output, $testType);
$exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePlugin';
$replace = array(
'ExamplePlugin' => $pluginName,
'SimpleTest' => $testName,
'SimpleIntegrationTest' => $testName,
'@group Plugins' => '@group ' . $testType
'ExamplePlugin' => $pluginName,
'SimpleTest' => $testName,
'SimpleSystemTest' => $testName,
'SimpleUITest_spec.js' => $testName . '_spec.js',
'SimpleUITest' => $testName,
);
$testClass = $this->getTestClass($testType);
if(!empty($testClass)) {
$replace['\PHPUnit_Framework_TestCase'] = $testClass;
}
$whitelistFiles = $this->getTestFilesWhitelist($testType);
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);
$this->writeSuccessMessage($output, array(
sprintf('Test %s for plugin %s generated.', $testName, $pluginName),
'You can now start writing beautiful tests!',
$messages = array(
sprintf('Test %s for plugin %s generated.', $testName, $pluginName),
);
));
if (strtolower($testType) === 'ui') {
$messages[] = 'To run this test execute the command: ';
$messages[] = '<comment>' . sprintf('./console tests:run-ui %s', $testName) . '</comment>';
} else {
$messages[] = 'To run all your plugin tests, execute the command: ';
$messages[] = '<comment>' . sprintf('./console tests:run %s', $pluginName) . '</comment>';
$messages[] = 'To run only this test: ';
$messages[] = '<comment>' . sprintf('./console tests:run %s', $testName) . '</comment>';
}
$this->writeSuccessMessage($output, array(
'To run all your plugin tests, execute the command: ',
sprintf('./console tests:run %s', $pluginName),
'To run only this test: ',
sprintf('./console tests:run %s', $testName),
'Enjoy!'
));
$messages[] = 'Enjoy!';
$this->writeSuccessMessage($output, $messages);
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return string
* @throws \RunTimeException
* @throws \RuntimeException
*/
private function getTestName(InputInterface $input, OutputInterface $output)
private function getTestName(InputInterface $input, OutputInterface $output, $testType)
{
$testname = $input->getOption('testname');
@ -90,7 +89,7 @@ class GenerateTest extends GeneratePluginBase
$validate($testname);
}
if (!Common::stringEndsWith(strtolower($testname), 'test')) {
if (strtolower($testType) !== 'ui' && !Common::stringEndsWith(strtolower($testname), 'test')) {
$testname = $testname . 'Test';
}
@ -103,7 +102,7 @@ class GenerateTest extends GeneratePluginBase
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws \RunTimeException
* @throws \RuntimeException
*/
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
@ -113,30 +112,15 @@ class GenerateTest extends GeneratePluginBase
return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName);
}
/**
* @param InputInterface $input
* @return string
*/
private function getTestClass($testType)
{
if ('Database' == $testType) {
return '\DatabaseTestCase';
}
if ('Unit' == $testType) {
return '\PHPUnit_Framework_TestCase';
}
return false;
}
public function getValidTypes()
{
return array('unit', 'integration', 'database');
return array('unit', 'integration', 'system', 'ui');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return string Unit, Integration, Database
* @return string Unit, Integration, System
*/
private function getTestType(InputInterface $input, OutputInterface $output)
{
@ -167,23 +151,46 @@ class GenerateTest extends GeneratePluginBase
*/
protected function getTestFilesWhitelist($testType)
{
if('Integration' == $testType) {
if ('Ui' == $testType) {
return array(
'/tests',
'/tests/UI',
'/tests/UI/.gitignore',
'/tests/UI/expected-ui-screenshots',
'/tests/UI/expected-ui-screenshots/.gitkeep',
'/tests/UI/SimpleUITest_spec.js',
);
}
if ('System' == $testType) {
return array(
'/.gitignore',
'/tests',
'/tests/SimpleIntegrationTest.php',
'/tests/expected',
'/tests/expected/test___API.get_day.xml',
'/tests/expected/test___Goals.getItemsSku_day.xml',
'/tests/processed',
'/tests/processed/.gitignore',
'/tests/fixtures',
'/tests/fixtures/SimpleFixtureTrackFewVisits.php'
'/tests/System',
'/tests/System/SimpleSystemTest.php',
'/tests/System/expected',
'/tests/System/expected/test___API.get_day.xml',
'/tests/System/expected/test___Goals.getItemsSku_day.xml',
'/tests/System/processed',
'/tests/System/processed/.gitignore',
'/tests/Fixtures',
'/tests/Fixtures/SimpleFixtureTrackFewVisits.php'
);
}
if ('Integration' == $testType) {
return array(
'/tests',
'/tests/Integration',
'/tests/Integration/SimpleTest.php'
);
}
return array(
'/tests',
'/tests/SimpleTest.php'
'/tests/Unit',
'/tests/Unit/SimpleTest.php'
);
}
}