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/Integration/Dao/LogTableTest.php')
m---------plugins/CustomDimensions0
-rw-r--r--plugins/CustomDimensions/tests/Integration/Dao/LogTableTest.php239
2 files changed, 239 insertions, 0 deletions
diff --git a/plugins/CustomDimensions b/plugins/CustomDimensions
deleted file mode 160000
-Subproject 318661a2fb1ef3b3e5d6d999ae8b9628cb5a113
diff --git a/plugins/CustomDimensions/tests/Integration/Dao/LogTableTest.php b/plugins/CustomDimensions/tests/Integration/Dao/LogTableTest.php
new file mode 100644
index 0000000000..d3ede5e672
--- /dev/null
+++ b/plugins/CustomDimensions/tests/Integration/Dao/LogTableTest.php
@@ -0,0 +1,239 @@
+<?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\Integration\Dao;
+
+use Piwik\Common;
+use Piwik\DbHelper;
+use Piwik\Plugins\CustomDimensions\CustomDimensions;
+use Piwik\Plugins\CustomDimensions\Dao\LogTable;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+/**
+ * @group CustomDimensions
+ * @group LogTableTest
+ * @group LogTable
+ * @group Dao
+ * @group Plugins
+ */
+class LogTableTest extends IntegrationTestCase
+{
+ /**
+ * @var LogTable
+ */
+ private $logVisit;
+
+ /**
+ * @var LogTable
+ */
+ private $logAction;
+
+ /**
+ * @var LogTable
+ */
+ private $logConverison;
+
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
+ $this->logAction = new LogTable(CustomDimensions::SCOPE_ACTION);
+ $this->logConverison = new LogTable(CustomDimensions::SCOPE_CONVERSION);
+
+ $this->logVisit->install();
+ $this->logAction->install();
+ $this->logConverison->install();
+ }
+
+ public function tearDown(): void
+ {
+ $this->logVisit->uninstall();
+ $this->logAction->uninstall();
+ $this->logConverison->uninstall();
+
+ parent::tearDown();
+ }
+
+ public function test_shouldInstall5Indexes_ByDefault()
+ {
+ $this->assertSame(5, $this->logVisit->getNumInstalledIndexes());
+ $this->assertSame(5, $this->logAction->getNumInstalledIndexes());
+ $this->assertSame(5, $this->logConverison->getNumInstalledIndexes());
+ }
+
+ public function test_install_shouldInstallColumn_LogLinkVisitAction_TimeSpent()
+ {
+ $columnn = DbHelper::getTableColumns(Common::prefixTable('log_link_visit_action'));
+ $this->assertArrayHasKey('time_spent', $columnn);
+ }
+
+ public function test_install_shouldInstallColumn_LogVisit_LastIdlinkVa()
+ {
+ $columnn = DbHelper::getTableColumns(Common::prefixTable('log_visit'));
+ $this->assertArrayHasKey('last_idlink_va', $columnn);
+ }
+
+ public function test_uninstall_shouldRemoveAllInstalledColumns()
+ {
+ $this->logVisit->uninstall();
+ $this->logAction->uninstall();
+ $this->logConverison->uninstall();
+
+ $this->assertSame(0, $this->logVisit->getNumInstalledIndexes());
+ $this->assertSame(0, $this->logAction->getNumInstalledIndexes());
+ $this->assertSame(0, $this->logConverison->getNumInstalledIndexes());
+ }
+
+ public function test_uninstall_shouldInstallColumn_LogLinkVisitAction_TimeSpent()
+ {
+ $this->logAction->uninstall();
+
+ $columnn = DbHelper::getTableColumns(Common::prefixTable('log_link_visit_action'));
+ $this->assertArrayNotHasKey('time_spent', $columnn);
+ }
+
+ public function test_uninstall_shouldInstallColumn_LogVisit_LastIdlinkVa()
+ {
+ $this->logVisit->uninstall();
+
+ $columnn = DbHelper::getTableColumns(Common::prefixTable('log_visit'));
+ $this->assertArrayNotHasKey('last_idlink_va', $columnn);
+ }
+
+ public function test_install_shouldMakeSureThereAreAtLeast5Installed()
+ {
+ $this->logVisit->removeCustomDimension(3);
+ $this->logVisit->removeCustomDimension(4);
+ $this->logVisit->removeCustomDimension(1);
+
+ $this->assertSame(2, $this->logVisit->getNumInstalledIndexes());
+
+ // should automatically detect to install 3
+ $this->logVisit->install();
+
+ $this->assertSame(5, $this->logVisit->getNumInstalledIndexes());
+ $this->assertSame(array(2,5,6,7,8), $this->logVisit->getInstalledIndexes());
+ }
+
+ public function test_getInstalledIndexes_shouldReturnInstalledIndexes()
+ {
+ $expected = range(1, 5);
+ $this->assertSame($expected, $this->logVisit->getInstalledIndexes());
+ $this->assertSame($expected, $this->logAction->getInstalledIndexes());
+ $this->assertSame($expected, $this->logConverison->getInstalledIndexes());
+
+ $this->logAction->addManyCustomDimensions(1);
+
+ $this->assertSame($expected, $this->logVisit->getInstalledIndexes());
+ $this->assertSame(range(1,6), $this->logAction->getInstalledIndexes());
+ $this->assertSame($expected, $this->logConverison->getInstalledIndexes());
+
+ $this->logVisit->removeCustomDimension(2);
+
+ $this->assertSame(array(1,3,4,5), $this->logVisit->getInstalledIndexes());
+ $this->assertSame(range(1,6), $this->logAction->getInstalledIndexes());
+ $this->assertSame($expected, $this->logConverison->getInstalledIndexes());
+ }
+
+ public function test_getNumInstalledIndexes_shouldReturnInstalledIndexes()
+ {
+ $expected = 5;
+ $this->assertSame($expected, $this->logVisit->getNumInstalledIndexes());
+ $this->assertSame($expected, $this->logAction->getNumInstalledIndexes());
+ $this->assertSame($expected, $this->logConverison->getNumInstalledIndexes());
+
+ $this->logAction->addManyCustomDimensions(1);
+
+ $this->assertSame($expected, $this->logVisit->getNumInstalledIndexes());
+ $this->assertSame(6, $this->logAction->getNumInstalledIndexes());
+ $this->assertSame($expected, $this->logConverison->getNumInstalledIndexes());
+
+ $this->logVisit->removeCustomDimension(2);
+
+ $this->assertSame(4, $this->logVisit->getNumInstalledIndexes());
+ $this->assertSame(6, $this->logAction->getNumInstalledIndexes());
+ $this->assertSame($expected, $this->logConverison->getNumInstalledIndexes());
+ }
+
+ public function test_buildCustomDimensionColumnName()
+ {
+ $this->assertNull(LogTable::buildCustomDimensionColumnName('0'));
+ $this->assertNull(LogTable::buildCustomDimensionColumnName(''));
+ $this->assertNull(LogTable::buildCustomDimensionColumnName(null));
+ $this->assertNull(LogTable::buildCustomDimensionColumnName(array()));
+ $this->assertNull(LogTable::buildCustomDimensionColumnName(array('index' => '')));
+
+ $this->assertSame('custom_dimension_1', LogTable::buildCustomDimensionColumnName('1'));
+ $this->assertSame('custom_dimension_1', LogTable::buildCustomDimensionColumnName('1'));
+ $this->assertSame('custom_dimension_99', LogTable::buildCustomDimensionColumnName('99'));
+ $this->assertSame('custom_dimension_94', LogTable::buildCustomDimensionColumnName('94te'));
+ $this->assertSame('custom_dimension_95', LogTable::buildCustomDimensionColumnName(array('index' => '95')));
+ }
+
+ public function test_removeCustomDimension_shouldRemoveASpecificIndex()
+ {
+ // should remove nothing as not a valid index
+ $this->logVisit->removeCustomDimension(0);
+ $this->logVisit->removeCustomDimension(null);
+
+ $this->assertSame(range(1, 5), $this->logVisit->getInstalledIndexes());
+
+ $this->logVisit->removeCustomDimension(3);
+ $this->assertSame(array(1,2,4,5), $this->logVisit->getInstalledIndexes());
+
+ $this->logVisit->removeCustomDimension('1');
+ $this->assertSame(array(2,4,5), $this->logVisit->getInstalledIndexes());
+ }
+
+ public function test_addManyCustomDimensions_shouldAddNewColumns()
+ {
+ // should add nothing as not a valid index
+ $this->logVisit->addManyCustomDimensions(0);
+ $this->logVisit->addManyCustomDimensions(null);
+
+ $this->assertSame(range(1, 5), $this->logVisit->getInstalledIndexes());
+
+ $this->logVisit->addManyCustomDimensions(1);
+ $this->assertSame(range(1,6), $this->logVisit->getInstalledIndexes());
+
+ $this->logVisit->addManyCustomDimensions(4);
+ $this->assertSame(range(1,10), $this->logVisit->getInstalledIndexes());
+
+ // should automatically add after highest index if some indexes are missing in between
+ $this->logVisit->removeCustomDimension('8');
+ $this->logVisit->removeCustomDimension('2');
+ $this->logVisit->removeCustomDimension('1');
+ $this->logVisit->addManyCustomDimensions(2);
+
+ $this->assertSame(array(3,4,5,6,7,9,10,11,12), $this->logVisit->getInstalledIndexes());
+ }
+
+ /**
+ * @dataProvider getDimensionColumnTestNames
+ */
+ public function test_isCustomDimensionColumn($expected, $name)
+ {
+ $this->assertSame($expected, LogTable::isCustomDimensionColumn($name));
+ }
+
+ public function getDimensionColumnTestNames()
+ {
+ return array(
+ array(true, 'custom_dimension_5'),
+ array(true, 'custom_dimension_99'),
+ array(true, 'custom_dimension_0'), // this one should be in theory false, but to keep things simple we return true, logic will be handled somewhere else
+ array(false, 'custom_dimension_'),
+ array(false, 'dimension_5'),
+ array(false, 'anything_6'),
+ array(false, ''),
+ array(false, 5),
+ );
+ }
+
+}