Skip to content
Snippets Groups Projects
Commit c436c92f authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'hotline#109308_erreur_de_tracking_dans_matomo' into 'hotline'

hotline#109308: Tracking Errors in Matomo (logs show that a required parameter…

See merge request !3483
parents a7df2b24 136012e7
2 merge requests!3494Hotline,!3483hotline#109308: Tracking Errors in Matomo (logs show that a required parameter…
Pipeline #9943 passed with stage
in 43 minutes and 58 seconds
- ticket #109308 : Statistiques : Correction d'une erreur dans le connecteur Matomo
\ No newline at end of file
......@@ -34,8 +34,8 @@ class Class_WebService_Analytics_MatomoTracker extends Class_WebService_Analytic
require_once('matomo-php-tracker/PiwikTracker.php');
$this->_config = $config;
$this->_tracker = $this->_getTrackerFactory()
->newFor($config->getTrackerId(),
'https:' . $config->getMatomoUrl());
->newFor($config->getTrackerId(), 'https:' . $config->getMatomoUrl())
->setTokenAuth(Class_AdminVar::get('MATOMO_AUTH_TOKEN'));
}
......@@ -54,7 +54,6 @@ class Class_WebService_Analytics_MatomoTracker extends Class_WebService_Analytic
return $this;
}
protected function _getTrackerFactory() {
return static::$_tracker_factory
? static::$_tracker_factory
......@@ -67,6 +66,6 @@ class Class_WebService_Analytics_MatomoTracker extends Class_WebService_Analytic
class Class_WebService_Analytics_MatomoTrackerFactory {
public function newFor($id_site, $url) {
return new PiwikTracker($id_site, $url);
return (new PiwikTracker($id_site, $url));
}
}
......@@ -284,6 +284,7 @@ class MatomoStatControllerMatomoActionTest extends Admin_AbstractControllerTestC
class MatomoStatControllerMatomoActionWithBothMatomoAndGoogleAnalyticsTest
extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
protected $_matomo;
public function setUp() {
parent::setUp();
......@@ -319,6 +320,9 @@ _paq.push([\'enableLinkTracking\']);
</script>']);
$jsstat = new Class_AdminVar_JsStat();
$this->_matomo = new Class_WebService_Analytics_MatomoTracker($jsstat);
$this->dispatch('/admin/stat/matomo', true);
}
......@@ -414,7 +418,14 @@ _paq.push(['enableLinkTracking']);
<!-- End Piwik Code -->");
$jsstat = new Class_AdminVar_JsStat();
$this->_tracker_factory = $this->mock()->whenCalled('newFor')->answers(null);
Class_AdminVar::set('MATOMO_AUTH_TOKEN','1234');
$this->_matomotracker = $this->mock('Class_WebService_Analytics_MatomoTracker')
->whenCalled('setTokenAuth')
->answers(null);
$this->_tracker_factory = $this->mock()->whenCalled('newFor')->answers($this->_matomotracker);
Class_WebService_Analytics_MatomoTracker::setTrackerFactory($this->_tracker_factory);
$this->_matomo = new Class_WebService_Analytics_MatomoTracker($jsstat);
}
......@@ -427,8 +438,15 @@ _paq.push(['enableLinkTracking']);
/** @test */
public function onConstructShouldProvideUrlWithHttpsToThirdPartyLibrary() {
$this->assertEquals('https://tracker.analytics.afi-sa.net/',
$this->_tracker_factory->getAttributesForLastCallOn('newFor')[1]);
public function onConstructShouldProvideUrlWithTrackerId2AndHttpsUrl() {
$this->assertTrue($this->_tracker_factory
->methodHasBeenCalledWithParams('newFor',
[2, 'https://tracker.analytics.afi-sa.net/']));
}
/** @test */
public function methodSetTokenAuthShouldBeCalledWithParam1234() {
$this->assertTrue($this->_matomotracker->methodHasBeenCalledWithParams('setTokenAuth', ['1234']));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment