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:
authorBenaka <diosmosis@users.noreply.github.com>2017-09-26 01:23:18 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2017-09-26 01:23:18 +0300
commitda6e68b04ff532d125e2c1e38be23814c5b8ecd9 (patch)
treefcdd5c46e85f3373a7c69378f85cc195339f3090 /plugins/CustomPiwikJs
parent5819e6ef2441d00115dac633e8a9845e2a2690a6 (diff)
Adding new events triggered when dynamic files are changed by Piwik. (#12106)
* Adding new events triggered when dynamic files are changed by Piwik. * Fixing broken test in TrackerUpdaterTest.php.
Diffstat (limited to 'plugins/CustomPiwikJs')
-rw-r--r--plugins/CustomPiwikJs/.gitignore3
-rw-r--r--plugins/CustomPiwikJs/TrackerUpdater.php8
-rw-r--r--plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php22
3 files changed, 31 insertions, 2 deletions
diff --git a/plugins/CustomPiwikJs/.gitignore b/plugins/CustomPiwikJs/.gitignore
index c8c9480010..8f30992923 100644
--- a/plugins/CustomPiwikJs/.gitignore
+++ b/plugins/CustomPiwikJs/.gitignore
@@ -1 +1,2 @@
-tests/System/processed/*xml \ No newline at end of file
+tests/System/processed/*xml
+tests/resources/MyNotExisIngFilessss.js
diff --git a/plugins/CustomPiwikJs/TrackerUpdater.php b/plugins/CustomPiwikJs/TrackerUpdater.php
index add1c0dd20..37476a7423 100644
--- a/plugins/CustomPiwikJs/TrackerUpdater.php
+++ b/plugins/CustomPiwikJs/TrackerUpdater.php
@@ -11,6 +11,7 @@ namespace Piwik\Plugins\CustomPiwikJs;
use Piwik\Container\StaticContainer;
use Piwik\Plugins\CustomPiwikJs\TrackingCode\PiwikJsManipulator;
use Piwik\Plugins\CustomPiwikJs\TrackingCode\PluginTrackerFiles;
+use Piwik\Piwik;
/**
* Updates the Piwik JavaScript Tracker "piwik.js" in case plugins extend the tracker.
@@ -130,6 +131,13 @@ class TrackerUpdater
if ($newContent !== $this->getCurrentTrackerFileContent()) {
$this->toFile->save($newContent);
+
+ /**
+ * Triggered after the tracker JavaScript content (the content of the piwik.js file) is changed.
+ *
+ * @param string $absolutePath The path to the new piwik.js file.
+ */
+ Piwik::postEvent('CustomPiwikJs.piwikJsChanged', [$this->toFile->getPath()]);
}
}
}
diff --git a/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php b/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
index 95d44f9c07..653c5105c5 100644
--- a/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
+++ b/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
@@ -22,11 +22,13 @@ use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
class TrackerUpdaterTest extends IntegrationTestCase
{
private $dir;
+ private $piwikJsChangedEventPath = null;
public function setUp()
{
parent::setUp();
$this->dir = PIWIK_DOCUMENT_ROOT . '/plugins/CustomPiwikJs/tests/resources/';
+ $this->piwikJsChangedEventPath = null;
$this->cleanUp();
}
@@ -44,6 +46,11 @@ class TrackerUpdaterTest extends IntegrationTestCase
if (file_exists($target)) {
unlink($target);
}
+
+ $nonExistentFile = $this->dir . 'MyNotExisIngFilessss.js';
+ if (file_exists($nonExistentFile)) {
+ unlink($nonExistentFile);
+ }
}
private function makeUpdater($from = null, $to = null)
@@ -175,9 +182,10 @@ var myArray = [];
public function test_update_shouldNotThrowAnError_IfTargetFileIsNotWritable()
{
- $updater = $this->makeUpdater(null, $this->dir . 'MyNotExisIngFilessss.js');
+ $updater = $this->makeUpdater(null, $this->dir . 'not-writable/MyNotExisIngFilessss.js');
$updater->update();
$this->assertTrue(true);
+ $this->assertNull($this->piwikJsChangedEventPath);
}
public function test_update_shouldNotWriteToFileIfThereIsNothingToChange()
@@ -191,6 +199,7 @@ var myArray = [];
$updater->update();
$this->assertSame(file_get_contents($source), file_get_contents($target));
+ $this->assertNull($this->piwikJsChangedEventPath);
}
public function test_update_targetFileIfPluginsDefineDifferentFiles()
@@ -221,6 +230,17 @@ var PiwikJs = "mytest";
var myArray = [];
', file_get_contents($target));
+ $this->assertEquals($target, $this->piwikJsChangedEventPath);
}
+ public function provideContainerConfig()
+ {
+ return [
+ 'observers.global' => \DI\add([
+ ['CustomPiwikJs.piwikJsChanged', function ($path) {
+ $this->piwikJsChangedEventPath = $path;
+ }],
+ ]),
+ ];
+ }
}