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:
Diffstat (limited to 'plugins/CustomDimensions/tests/Commands')
m---------plugins/CustomDimensions0
-rw-r--r--plugins/CustomDimensions/tests/Commands/AddCustomDimensionTest.php164
-rw-r--r--plugins/CustomDimensions/tests/Commands/InfoTest.php81
-rw-r--r--plugins/CustomDimensions/tests/Commands/RemoveCustomDimensionTest.php169
4 files changed, 414 insertions, 0 deletions
diff --git a/plugins/CustomDimensions b/plugins/CustomDimensions
deleted file mode 160000
-Subproject 318661a2fb1ef3b3e5d6d999ae8b9628cb5a113
diff --git a/plugins/CustomDimensions/tests/Commands/AddCustomDimensionTest.php b/plugins/CustomDimensions/tests/Commands/AddCustomDimensionTest.php
new file mode 100644
index 0000000000..b96286f0da
--- /dev/null
+++ b/plugins/CustomDimensions/tests/Commands/AddCustomDimensionTest.php
@@ -0,0 +1,164 @@
+<?php
+/**
+ * Matomo - free/libre analytics platform
+ *
+ * @link https://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+namespace Piwik\Plugins\CustomDimensions\tests\Commands;
+
+use Piwik\Plugins\CustomDimensions\Commands\AddCustomDimension;
+use Piwik\Plugins\CustomDimensions\CustomDimensions;
+use Piwik\Plugins\CustomDimensions\Dao\LogTable;
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+/**
+ * @group CustomDimensions
+ * @group CustomDimensionsTest
+ * @group Plugins
+ * @group Plugins
+ */
+class AddCustomDimensionTest extends IntegrationTestCase
+{
+ public function testExecute_ShouldThrowException_IfArgumentIsMissing()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('The specified scope is invalid. Use either');
+
+ $this->executeCommand(null, null);
+ }
+
+ public function testExecute_ShouldThrowException_IfScopeIsInvalid()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('The specified scope is invalid. Use either "--scope=visit" or "--scope=action"');
+
+ $this->executeCommand('invalidscope', null);
+ }
+
+ public function testExecute_ShouldThrowException_IfCountIsNotANumber()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Option "count" must be a number');
+
+ $this->executeCommand(CustomDimensions::SCOPE_VISIT, '545fddfd');
+ }
+
+ public function testExecute_ShouldThrowException_IfCountIsLessThanONe()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Option "count" must be at least one');
+
+ $this->executeCommand(CustomDimensions::SCOPE_VISIT, '0');
+ }
+
+ public function testExecute_ShouldThrowException_IfUserCancelsConfirmation()
+ {
+ $result = $this->executeCommand(CustomDimensions::SCOPE_VISIT, $count = 5, false);
+ $this->assertStringEndsWith('Are you sure you want to perform this action? (y/N)', $result);
+ }
+
+ public function testExecute_ShouldAddSpecifiedCount()
+ {
+ $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->assertSame(range(1,5), $logVisit->getInstalledIndexes());
+
+ $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $this->assertSame(range(1,5), $logConversion->getInstalledIndexes());
+
+ $logAction = new LogTable(CustomDimensions::SCOPE_ACTION);
+ $this->assertSame(range(1,5), $logAction->getInstalledIndexes());
+
+ $result = $this->executeCommand(CustomDimensions::SCOPE_ACTION, $count = 3);
+
+ self::assertStringContainsString('Adding 3 Custom Dimension(s) in scope action.', $result);
+ self::assertStringContainsString('Are you sure you want to perform this action?', $result);
+ self::assertStringContainsString('Starting to add Custom Dimension(s)', $result);
+ self::assertStringContainsString('Your Piwik is now configured for up to 8 Custom Dimensions in scope action.', $result);
+
+ $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->assertSame(range(1,5), $logVisit->getInstalledIndexes());
+
+ $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $this->assertSame(range(1,5), $logConversion->getInstalledIndexes());
+
+ $logAction = new LogTable(CustomDimensions::SCOPE_ACTION);
+ $this->assertSame(range(1,8), $logAction->getInstalledIndexes());
+ }
+
+ public function testExecute_ShouldAddSpecifiedCount_IfScopeIsVisitShouldAlsoUpdateConversion()
+ {
+ $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->assertSame(range(1,5), $logVisit->getInstalledIndexes());
+
+ $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $this->assertSame(range(1,5), $logConversion->getInstalledIndexes());
+
+ $logAction = new LogTable(CustomDimensions::SCOPE_ACTION);
+ $this->assertSame(range(1,8), $logAction->getInstalledIndexes());
+
+ $result = $this->executeCommand(CustomDimensions::SCOPE_VISIT, $count = 2);
+
+ self::assertStringContainsString('Adding 2 Custom Dimension(s) in scope visit.', $result);
+ self::assertStringContainsString('Are you sure you want to perform this action?', $result);
+ self::assertStringContainsString('Starting to add Custom Dimension(s)', $result);
+ self::assertStringContainsString('Your Piwik is now configured for up to 7 Custom Dimensions in scope visit.', $result);
+
+ $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->assertSame(range(1,7), $logVisit->getInstalledIndexes());
+
+ $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $this->assertSame(range(1,7), $logConversion->getInstalledIndexes());
+
+ $logAction = new LogTable(CustomDimensions::SCOPE_ACTION);
+ $this->assertSame(range(1,8), $logAction->getInstalledIndexes());
+ }
+
+ /**
+ * @param string|null $scope
+ * @param int|null $count
+ * @param bool $confirm
+ *
+ * @return string
+ */
+ private function executeCommand($scope, $count, $confirm = true)
+ {
+ $addCustomDimension = new AddCustomDimension();
+
+ $application = new Application();
+ $application->add($addCustomDimension);
+
+ $commandTester = new CommandTester($addCustomDimension);
+
+ $dialog = $addCustomDimension->getHelper('dialog');
+ $dialog->setInputStream($this->getInputStream($confirm ? 'yes' : 'no' . '\n'));
+
+ $params = array();
+ if (!is_null($scope)) {
+ $params['--scope'] = $scope;
+ }
+
+ if (!is_null($count)) {
+ $params['--count'] = $count;
+ }
+
+ $params['command'] = $addCustomDimension->getName();
+ $commandTester->execute($params);
+ $result = $commandTester->getDisplay();
+
+ return $result;
+ }
+
+ protected function getInputStream($input)
+ {
+ $stream = fopen('php://memory', 'r+', false);
+ fputs($stream, $input);
+ rewind($stream);
+
+ return $stream;
+ }
+}
diff --git a/plugins/CustomDimensions/tests/Commands/InfoTest.php b/plugins/CustomDimensions/tests/Commands/InfoTest.php
new file mode 100644
index 0000000000..ad47473fea
--- /dev/null
+++ b/plugins/CustomDimensions/tests/Commands/InfoTest.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Matomo - free/libre analytics platform
+ *
+ * @link https://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+namespace Piwik\Plugins\CustomDimensions\tests\Commands;
+
+use Piwik\Plugins\CustomDimensions\Commands\Info;
+use Piwik\Plugins\CustomDimensions\CustomDimensions;
+use Piwik\Plugins\CustomDimensions\Dao\LogTable;
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+/**
+ * @group CustomDimensions
+ * @group CustomDimensionsTest
+ * @group Plugins
+ * @group Plugins
+ */
+class InfoTest extends IntegrationTestCase
+{
+ public function testExecute_ShouldOutputInfoSuccess_IfEverythingIsOk()
+ {
+ $output = $this->executeCommand();
+
+ self::assertStringContainsString('./console customdimensions:add-custom-dimension --scope=visit"
+Installed indexes are:
+1 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=visit --index=1
+2 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=visit --index=2
+3 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=visit --index=3
+4 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=visit --index=4
+5 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=visit --index=5
+
+5 Custom Dimensions available in scope "action"
+To add a Custom Dimension execute "./console customdimensions:add-custom-dimension --scope=action"
+Installed indexes are:
+1 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=action --index=1
+2 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=action --index=2
+3 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=action --index=3
+4 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=action --index=4
+5 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=action --index=5
+
+5 Custom Dimensions available in scope "conversion"
+Custom Dimensions are automatically added via the scope "visit" and cannot be added manually
+Installed indexes are:
+1 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=conversion --index=1
+2 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=conversion --index=2
+3 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=conversion --index=3
+4 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=conversion --index=4
+5 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=conversion --index=5',
+ $output);
+ }
+
+ public function testExecute_ShouldOutputErrorMessage_IfColumnsDoNotMatch()
+ {
+ $model = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $model->removeCustomDimension(5);
+
+ self::assertStringContainsString('We found an error, Custom Dimensions in scope "conversion" are not correctly installed. Execute the following command to repair it:
+./console customdimensions:add-custom-dimension --scope=conversion --count=1', $this->executeCommand());
+ }
+
+ private function executeCommand()
+ {
+ $infoCmd = new Info();
+
+ $application = new Application();
+ $application->add($infoCmd);
+ $commandTester = new CommandTester($infoCmd);
+
+ $commandTester->execute(array('command' => $infoCmd->getName()));
+ $result = $commandTester->getDisplay();
+
+ return $result;
+ }
+}
diff --git a/plugins/CustomDimensions/tests/Commands/RemoveCustomDimensionTest.php b/plugins/CustomDimensions/tests/Commands/RemoveCustomDimensionTest.php
new file mode 100644
index 0000000000..f277fc0034
--- /dev/null
+++ b/plugins/CustomDimensions/tests/Commands/RemoveCustomDimensionTest.php
@@ -0,0 +1,169 @@
+<?php
+/**
+ * Matomo - free/libre analytics platform
+ *
+ * @link https://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+namespace Piwik\Plugins\CustomDimensions\tests\Commands;
+
+use Piwik\Plugins\CustomDimensions\Commands\RemoveCustomDimension;
+use Piwik\Plugins\CustomDimensions\CustomDimensions;
+use Piwik\Plugins\CustomDimensions\Dao\LogTable;
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+/**
+ * @group CustomDimensions
+ * @group CustomDimensionsTest
+ * @group Plugins
+ * @group Plugins
+ */
+class RemoveCustomDimensionTest extends IntegrationTestCase
+{
+ public function testExecute_ShouldThrowException_IfArgumentIsMissing()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('The specified scope is invalid. Use either');
+
+ $this->executeCommand(null, null);
+ }
+
+ public function testExecute_ShouldThrowException_IfScopeIsInvalid()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('The specified scope is invalid. Use either "--scope=visit" or "--scope=action"');
+
+ $this->executeCommand('invalidscope', null);
+ }
+
+ public function testExecute_ShouldThrowException_IfIndexIsNotSpecified()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('An option "index" must be specified');
+
+ $this->executeCommand(CustomDimensions::SCOPE_VISIT, null);
+ }
+
+ public function testExecute_ShouldThrowException_IfIndexIsNotANumber()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Option "index" must be a number');
+
+ $this->executeCommand(CustomDimensions::SCOPE_VISIT, '545fddfd');
+ }
+
+ public function testExecute_ShouldThrowException_IfCountIsLessThanONe()
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Specified index is not installed');
+
+ $this->executeCommand(CustomDimensions::SCOPE_VISIT, '14');
+ }
+
+ public function testExecute_ShouldThrowException_IfUserCancelsConfirmation()
+ {
+ $result = $this->executeCommand(CustomDimensions::SCOPE_VISIT, $index = 5, false);
+ $this->assertStringEndsWith('Are you sure you want to perform this action? (y/N)', $result);
+ }
+
+ public function testExecute_ShouldAddSpecifiedCount()
+ {
+ $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->assertSame(range(1,5), $logVisit->getInstalledIndexes());
+
+ $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $this->assertSame(range(1,5), $logConversion->getInstalledIndexes());
+
+ $logAction = new LogTable(CustomDimensions::SCOPE_ACTION);
+ $this->assertSame(range(1,5), $logAction->getInstalledIndexes());
+
+ $result = $this->executeCommand(CustomDimensions::SCOPE_ACTION, $index = 3);
+
+ self::assertStringContainsString('Remove Custom Dimension at index 3 in scope action.', $result);
+ self::assertStringContainsString('Are you sure you want to perform this action?', $result);
+ self::assertStringContainsString('Starting to remove this Custom Dimension', $result);
+ self::assertStringContainsString('Your Piwik is now configured for up to 4 Custom Dimensions in scope action.', $result);
+
+ $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->assertSame(range(1,5), $logVisit->getInstalledIndexes());
+
+ $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $this->assertSame(range(1,5), $logConversion->getInstalledIndexes());
+
+ $logAction = new LogTable(CustomDimensions::SCOPE_ACTION);
+ $this->assertSame(array(1,2,4,5), $logAction->getInstalledIndexes());
+ }
+
+ public function testExecute_ShouldAddSpecifiedCount_IfScopeIsVisitShouldAlsoUpdateConversion()
+ {
+ $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->assertSame(range(1,5), $logVisit->getInstalledIndexes());
+
+ $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $this->assertSame(range(1,5), $logConversion->getInstalledIndexes());
+
+ $result = $this->executeCommand(CustomDimensions::SCOPE_VISIT, $index = 2);
+
+ self::assertStringContainsString('Remove Custom Dimension at index 2 in scope visit', $result);
+ self::assertStringContainsString('Are you sure you want to perform this action?', $result);
+ self::assertStringContainsString('Starting to remove this Custom Dimension', $result);
+ self::assertStringContainsString('Your Piwik is now configured for up to 4 Custom Dimensions in scope visit.', $result);
+
+ $logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->assertSame(array(1,3,4,5), $logVisit->getInstalledIndexes());
+
+ $logConversion = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+ $this->assertSame(array(1,3,4,5), $logConversion->getInstalledIndexes());
+
+ $logAction = new LogTable(CustomDimensions::SCOPE_ACTION);
+ $this->assertSame(array(1,2,4,5), $logAction->getInstalledIndexes());
+ }
+
+ /**
+ * @param string|null $scope
+ * @param int|null $index
+ * @param bool $confirm
+ *
+ * @return string
+ */
+ private function executeCommand($scope, $index, $confirm = true)
+ {
+ $removeCustomDimension = new RemoveCustomDimension();
+
+ $application = new Application();
+ $application->add($removeCustomDimension);
+
+ $commandTester = new CommandTester($removeCustomDimension);
+
+ $dialog = $removeCustomDimension->getHelper('dialog');
+ $dialog->setInputStream($this->getInputStream($confirm ? 'yes' : 'no' . '\n'));
+
+ $params = array();
+ if (!is_null($scope)) {
+ $params['--scope'] = $scope;
+ }
+
+ if (!is_null($index)) {
+ $params['--index'] = $index;
+ }
+
+ $params['command'] = $removeCustomDimension->getName();
+ $commandTester->execute($params);
+ $result = $commandTester->getDisplay();
+
+ return $result;
+ }
+
+ protected function getInputStream($input)
+ {
+ $stream = fopen('php://memory', 'r+', false);
+ fputs($stream, $input);
+ rewind($stream);
+
+ return $stream;
+ }
+}