Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-04-07 06:32:58 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-04-07 06:32:58 +0400
commit801cbef9d986e3697c43e0da56bd3f7fe3d96791 (patch)
tree92dfbd870d564547ca0d0ad7e3a03b61b552256b
parent61f42e89cd9f31d876b271fb777d499b1981ec58 (diff)
simplify tests
-rw-r--r--plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php4
-rw-r--r--plugins/CustomVariables/tests/Commands/InfoTest.php14
-rw-r--r--plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php80
3 files changed, 52 insertions, 46 deletions
diff --git a/plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php b/plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php
index 7b26b32d0f..0f5419029c 100644
--- a/plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php
+++ b/plugins/CustomVariables/Commands/SetNumberOfCustomVariables.php
@@ -116,8 +116,8 @@ class SetNumberOfCustomVariables extends ConsoleCommand
$maxCustomVars = (int) $maxCustomVars;
- if ($maxCustomVars <= 1) {
- throw new \InvalidArgumentException('There has to be at least two custom variables');
+ if ($maxCustomVars < 5) {
+ throw new \InvalidArgumentException('There has to be at least five custom variables');
}
return $maxCustomVars;
diff --git a/plugins/CustomVariables/tests/Commands/InfoTest.php b/plugins/CustomVariables/tests/Commands/InfoTest.php
index 82c9d3803e..586fbc09a8 100644
--- a/plugins/CustomVariables/tests/Commands/InfoTest.php
+++ b/plugins/CustomVariables/tests/Commands/InfoTest.php
@@ -27,7 +27,7 @@ class InfoTest extends \DatabaseTestCase
{
public function testExecute_ShouldOutputInfoSuccess_IfEverythingIsOk()
{
- $this->assertEquals('Your Piwik is configured for 5 custom variables.', $this->executeCommand());
+ $this->assertContains('Your Piwik is configured for 5 custom variables.', $this->executeCommand());
}
public function testExecute_ShouldOutputErrorMessage_IfColumnsDoNotMatch()
@@ -35,18 +35,18 @@ class InfoTest extends \DatabaseTestCase
$model = new Model(Model::SCOPE_PAGE);
$model->removeCustomVariable();
- $this->assertEquals('There is a problem with your custom variables configuration', $this->executeCommand());
+ $this->assertContains('There is a problem with your custom variables configuration', $this->executeCommand());
}
private function executeCommand()
{
- $application = new Application();
- $application->add(new Info());
+ $infoCmd = new Info();
- $command = $application->find('customvariables:info');
- $commandTester = new CommandTester($command);
+ $application = new Application();
+ $application->add($infoCmd);
+ $commandTester = new CommandTester($infoCmd);
- $commandTester->execute(array('command' => $command->getName()));
+ $commandTester->execute(array('command' => $infoCmd->getName()));
$result = $commandTester->getDisplay();
return $result;
diff --git a/plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php b/plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php
index 9be01c55b0..0fbbb9d299 100644
--- a/plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php
+++ b/plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php
@@ -31,7 +31,7 @@ class SetNumberOfCustomVariablesTest extends \DatabaseTestCase
*/
public function testExecute_ShouldThrowException_IfArgumentIsMissing()
{
- $this->executeCommand(array(), true);
+ $this->executeCommand(null);
}
/**
@@ -40,53 +40,36 @@ class SetNumberOfCustomVariablesTest extends \DatabaseTestCase
*/
public function testExecute_ShouldThrowException_HasToBeANumber()
{
- $this->executeCommand(array('maxCustomVars' => 'a'), true);
+ $this->executeCommand('a');
}
/**
* @expectedException \InvalidArgumentException
- * @expectedExceptionMessage There has to be at least two custom variables
+ * @expectedExceptionMessage There has to be at least five custom variables
*/
public function testExecute_ShouldThrowException_Minimum2CustomVarsRequired()
{
- $this->executeCommand(array('maxCustomVars' => 1), true);
+ $this->executeCommand(4);
}
public function testExecute_ShouldThrowException_IfUserCancelsConfirmation()
{
- $result = $this->executeCommand(array('maxCustomVars' => 4), false);
+ $result = $this->executeCommand(7, false);
$this->assertStringEndsWith('Are you sure you want to perform these actions? (y/N)', $result);
}
public function testExecute_ShouldDoNothingIfExpectedResult_IsAlreadyTheCase()
{
- $result = $this->executeCommand(array('maxCustomVars' => 5), true);
+ $result = $this->executeCommand(5);
$this->assertContains('Your Piwik is already configured for 5 custom variables', $result);
}
- public function testExecute_ShouldRemoveMaxCustomVars_IfNumberIsLessThanActual()
- {
- $this->assertEquals(5, CustomVariables::getMaxCustomVariables());
-
- $result = $this->executeCommand(array('maxCustomVars' => 4), true);
-
- $this->assertContains('Configuring Piwik for 4 custom variables', $result);
- $this->assertContains('1 existing custom variables having the index(es) 5 will be REMOVED.', $result);
- $this->assertContains('Starting to apply changes', $result);
- $this->assertContains('Removed a variable in scope "Page" having the index 5', $result);
- $this->assertContains('Removed a variable in scope "Visit" having the index 5', $result);
- $this->assertContains('Removed a variable in scope "Conversion" having the index 5', $result);
- $this->assertContains('Your Piwik is now configured for 4 custom variables.', $result);
-
- $this->assertEquals(4, CustomVariables::getMaxCustomVariables());
- }
-
public function testExecute_ShouldAddMaxCustomVars_IfNumberIsHigherThanActual()
{
$this->assertEquals(5, CustomVariables::getMaxCustomVariables());
- $result = $this->executeCommand(array('maxCustomVars' => 6), true);
+ $result = $this->executeCommand(6);
$this->assertContains('Configuring Piwik for 6 custom variables', $result);
$this->assertContains('1 new custom variables having the index(es) 6 will be ADDED', $result);
@@ -99,37 +82,60 @@ class SetNumberOfCustomVariablesTest extends \DatabaseTestCase
$this->assertEquals(6, CustomVariables::getMaxCustomVariables());
}
+ public function testExecute_ShouldRemoveMaxCustomVars_IfNumberIsLessThanActual()
+ {
+ $this->executeCommand(6, true);
+ $this->assertEquals(6, CustomVariables::getMaxCustomVariables());
+
+ $result = $this->executeCommand(5);
+
+ $this->assertContains('Configuring Piwik for 5 custom variables', $result);
+ $this->assertContains('1 existing custom variables having the index(es) 6 will be REMOVED.', $result);
+ $this->assertContains('Starting to apply changes', $result);
+ $this->assertContains('Removed a variable in scope "Page" having the index 6', $result);
+ $this->assertContains('Removed a variable in scope "Visit" having the index 6', $result);
+ $this->assertContains('Removed a variable in scope "Conversion" having the index 6', $result);
+ $this->assertContains('Your Piwik is now configured for 5 custom variables.', $result);
+
+ $this->assertEquals(5, CustomVariables::getMaxCustomVariables());
+ }
+
public function testExecute_AddMultiple_RemoveMultiple()
{
$this->assertEquals(5, CustomVariables::getMaxCustomVariables());
- $this->executeCommand(array('maxCustomVars' => 8), true);
- $this->assertEquals(8, CustomVariables::getMaxCustomVariables());
+ $this->executeCommand(9);
+ $this->assertEquals(9, CustomVariables::getMaxCustomVariables());
- $this->executeCommand(array('maxCustomVars' => 3), true);
- $this->assertEquals(3, CustomVariables::getMaxCustomVariables());
+ $this->executeCommand(6);
+ $this->assertEquals(6, CustomVariables::getMaxCustomVariables());
}
/**
- * @param array $params
+ * @param int|null $maxCustomVars
* @param bool $confirm
*
* @return string
*/
- private function executeCommand(array $params, $confirm)
+ private function executeCommand($maxCustomVars, $confirm = true)
{
- $confirm = $confirm ? 'yes' : 'no';
+ $setNumberCmd = new SetNumberOfCustomVariables();
$application = new Application();
- $application->add(new SetNumberOfCustomVariables());
+ $application->add($setNumberCmd);
+
+ $commandTester = new CommandTester($setNumberCmd);
- $command = $application->find('customvariables:set-max-custom-variables');
- $commandTester = new CommandTester($command);
+ $dialog = $setNumberCmd->getHelper('dialog');
+ $dialog->setInputStream($this->getInputStream($confirm ? 'yes' : 'no' . '\n'));
- $dialog = $command->getHelper('dialog');
- $dialog->setInputStream($this->getInputStream($confirm . '\n'));
+ if (is_null($maxCustomVars)) {
+ $params = array();
+ } else {
+ $params = array('maxCustomVars' => $maxCustomVars);
+ }
- $params['command'] = $command->getName();
+ $params['command'] = $setNumberCmd->getName();
$commandTester->execute($params);
$result = $commandTester->getDisplay();