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/Diagnostics/tests/Integration/Diagnostic/ArchiveInvalidationsInformationalTest.php')
-rw-r--r--plugins/Diagnostics/tests/Integration/Diagnostic/ArchiveInvalidationsInformationalTest.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/plugins/Diagnostics/tests/Integration/Diagnostic/ArchiveInvalidationsInformationalTest.php b/plugins/Diagnostics/tests/Integration/Diagnostic/ArchiveInvalidationsInformationalTest.php
new file mode 100644
index 0000000000..fec8cb5a73
--- /dev/null
+++ b/plugins/Diagnostics/tests/Integration/Diagnostic/ArchiveInvalidationsInformationalTest.php
@@ -0,0 +1,85 @@
+<?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\Diagnostics\tests\Integration\Diagnostic;
+
+use Piwik\Common;
+use Piwik\Container\StaticContainer;
+use Piwik\Db;
+use Piwik\Plugins\Diagnostics\Diagnostic\ArchiveInvalidationsInformational;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+use Piwik\Translation\Translator;
+
+class ArchiveInvalidationsInformationalTest extends IntegrationTestCase
+{
+ public function test_execute()
+ {
+ $segmentHash = md5('something');
+ $anotherSegmentHash = md5('anothersomething');
+ $this->insertInvalidations([
+ ['idsite' => '1', 'name' => 'done', 'date1' => '2020-01-13', 'date2' => '2020-01-13', 'period' => '1', 'report' => '', 'ts_started' => '2020-01-13 02:00:00', 'ts_invalidated' => '2020-01-12 02:00:00', 'status' => 1],
+ ['idsite' => '1', 'name' => 'done.MyPlugin', 'date1' => '2020-01-13', 'date2' => '2020-01-19', 'period' => '2', 'report' => '', 'ts_started' => NULL, 'ts_invalidated' => '2020-01-12 06:00:00', 'status' => 0],
+ ['idsite' => '1', 'name' => 'done' . $segmentHash, 'date1' => '2020-01-01', 'date2' => '2020-01-31', 'period' => '3', 'report' => '', 'ts_started' => NULL, 'ts_invalidated' => '2020-01-12 04:00:00', 'status' => 0],
+ ['idsite' => '2', 'name' => 'done' . $segmentHash . '.MyPlugin', 'date1' => '2020-01-15', 'date2' => '2020-01-15', 'period' => '1', 'report' => '', 'ts_started' => '2020-01-14 02:00:00', 'ts_invalidated' => '2020-01-12 03:00:00', 'status' => 1],
+ ['idsite' => '2', 'name' => 'done.MyOtherPlugin', 'date1' => '2020-01-15', 'date2' => '2020-01-15', 'period' => '1', 'report' => '', 'ts_started' => NULL, 'ts_invalidated' => '2020-01-12 12:00:00', 'status' => 0],
+ ['idsite' => '3', 'name' => 'done' . $anotherSegmentHash, 'date1' => '2020-01-06', 'date2' => '2020-01-12', 'period' => '2', 'report' => '', 'ts_started' => NULL, 'ts_invalidated' => '2020-01-12 02:30:00', 'status' => 0],
+ ['idsite' => '3', 'name' => 'done' . $anotherSegmentHash . '.AThirdPlugin', 'date1' => '2020-01-01', 'date2' => '2020-01-31', 'period' => '3', 'report' => 'aReport', 'ts_started' => '2020-01-13 07:00:00', 'ts_invalidated' => '2020-01-11 02:00:00', 'status' => 1],
+ ['idsite' => '3', 'name' => 'done', 'date1' => '2020-02-06', 'date2' => '2020-02-06', 'period' => '1', 'report' => '', 'ts_started' => NULL, 'ts_invalidated' => '2020-01-10 02:00:00', 'status' => 0],
+ ['idsite' => '3', 'name' => 'done', 'date1' => '2020-01-16', 'date2' => '2020-01-16', 'period' => '1', 'report' => '', 'ts_started' => NULL, 'ts_invalidated' => '2020-01-20 02:00:00', 'status' => 0],
+ ['idsite' => '3', 'name' => 'done' . $segmentHash, 'date1' => '2020-01-16', 'date2' => '2020-01-16', 'period' => '1', 'report' => '', 'ts_started' => NULL, 'ts_invalidated' => '2020-01-12 02:00:00', 'status' => 0],
+ ]);
+
+ $diagnostic = new ArchiveInvalidationsInformational(StaticContainer::get(Translator::class));
+
+ $counts = $diagnostic->getInvalidationCounts();
+ $this->assertEquals([
+ 0 => '7',
+ 1 => '3',
+ 'all' => 10,
+ ], $counts);
+
+ $minMaxes = $diagnostic->getInvalidationMinMaxes();
+ $this->assertEquals([
+ 'min_ts_started' => '2020-01-13 02:00:00',
+ 'max_ts_started' => '2020-01-14 02:00:00',
+ 'min_ts_invalidated' => '2020-01-10 02:00:00',
+ 'max_ts_invalidated' => '2020-01-20 02:00:00',
+ ], $minMaxes);
+
+ $types = $diagnostic->getInvalidationTypes();
+ $this->assertEquals([
+ 'count_segment' => 5,
+ 'count_plugin' => 4,
+ 'plugins' => [
+ 'AThirdPlugin',
+ 'MyOtherPlugin',
+ 'MyPlugin',
+ ],
+ ], $types);
+ }
+
+
+ private function insertInvalidations(array $invalidations)
+ {
+ $table = Common::prefixTable('archive_invalidations');
+ foreach ($invalidations as $invalidation) {
+ $sql = "INSERT INTO $table (name, idsite, date1, date2, period, report, status, ts_started, ts_invalidated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ Db::query($sql, [
+ $invalidation['name'],
+ $invalidation['idsite'],
+ $invalidation['date1'],
+ $invalidation['date2'],
+ $invalidation['period'],
+ $invalidation['report'],
+ $invalidation['status'],
+ $invalidation['ts_started'],
+ $invalidation['ts_invalidated'],
+ ]);
+ }
+ }
+} \ No newline at end of file