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@gmail.com>2016-10-17 23:39:22 +0300
committerThomas Steur <thomas.steur@gmail.com>2016-10-17 23:39:22 +0300
commit0f79427f3959d019ef36671409fa02cbc6c38518 (patch)
tree0685c6853b3dc5b53ea3b86ef78463f64ace093a /plugins/CustomPiwikJs
parent7b8da6e793e62465d1d0f1b080518aa521b60e6e (diff)
fix filechecks may falsely mark piwikjs as invalid
Diffstat (limited to 'plugins/CustomPiwikJs')
-rw-r--r--plugins/CustomPiwikJs/TrackerUpdater.php18
-rw-r--r--plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php52
2 files changed, 67 insertions, 3 deletions
diff --git a/plugins/CustomPiwikJs/TrackerUpdater.php b/plugins/CustomPiwikJs/TrackerUpdater.php
index 6370287882..d90d8c166d 100644
--- a/plugins/CustomPiwikJs/TrackerUpdater.php
+++ b/plugins/CustomPiwikJs/TrackerUpdater.php
@@ -62,16 +62,28 @@ class TrackerUpdater
$this->toFile->checkWritable();
}
+ public function getCurrentTrackerFileContent()
+ {
+ return $this->toFile->getContent();
+ }
+
+ public function getUpdatedTrackerFileContent()
+ {
+ $trackingCode = new PiwikJsManipulator($this->fromFile->getContent(), $this->trackerFiles);
+ $newContent = $trackingCode->manipulateContent();
+
+ return $newContent;
+ }
+
public function update()
{
if (!$this->toFile->hasWriteAccess() || !$this->fromFile->hasReadAccess()) {
return;
}
- $trackingCode = new PiwikJsManipulator($this->fromFile->getContent(), $this->trackerFiles);
- $newContent = $trackingCode->manipulateContent();
+ $newContent = $this->getUpdatedTrackerFileContent();
- if ($newContent !== $this->toFile->getContent()) {
+ if ($newContent !== $this->getCurrentTrackerFileContent()) {
$this->toFile->save($newContent);
}
}
diff --git a/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php b/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
index 58650adf7e..ef90785a5f 100644
--- a/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
+++ b/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
@@ -74,6 +74,58 @@ class TrackerUpdaterTest extends IntegrationTestCase
$updater->checkWillSucceed();
}
+ public function test_getCurrentTrackerFileContent()
+ {
+ $targetFile = $this->dir . 'testpiwik.js';
+
+ $updater = $this->makeUpdater(null, $targetFile);
+ $content = $updater->getCurrentTrackerFileContent();
+
+ $this->assertSame(file_get_contents($targetFile), $content);
+ }
+
+ public function test_getUpdatedTrackerFileContent_returnsGeneratedPiwikJsWithMergedTrackerFiles_WhenTheyExist()
+ {
+ $source = $this->dir . 'testpiwik.js';
+ $target = $this->dir . 'MyTestTarget.js';
+
+ $updater = $this->makeUpdater($source, $target);
+ $updater->setTrackerFiles(new PluginTrackerFilesMock(array(
+ $this->dir . 'tracker.js', $this->dir . 'tracker.min.js'
+ )));
+ $content = $updater->getUpdatedTrackerFileContent();
+
+ $this->assertSame('/** MyHeader*/
+var PiwikJs = "mytest";
+
+/*!!! pluginTrackerHook */
+
+/* GENERATED: tracker.min.js */
+
+/* END GENERATED: tracker.min.js */
+
+
+/* GENERATED: tracker.js */
+
+/* END GENERATED: tracker.js */
+
+
+var myArray = [];
+', $content);
+ }
+
+ public function test_getUpdatedTrackerFileContent_returnsSourceFile_IfNoTrackerFilesFound()
+ {
+ $source = $this->dir . 'testpiwik.js';
+ $target = $this->dir . 'MyTestTarget.js';
+
+ $updater = $this->makeUpdater($source, $target);
+ $updater->setTrackerFiles(new PluginTrackerFilesMock(array()));
+ $content = $updater->getUpdatedTrackerFileContent();
+
+ $this->assertSame(file_get_contents($source), $content);
+ }
+
public function test_update_shouldNotThrowAnError_IfTargetFileIsNotWritable()
{
$updater = $this->makeUpdater(null, $this->dir . 'MyNotExisIngFilessss.js');