diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2018-12-06 08:44:01 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2018-12-06 08:44:01 +0300 |
commit | 7b6a14626960795b0acdf4a064cd3982d7704f2b (patch) | |
tree | 1f8b5fc7d7869c77e91a1f8dc2ab592b3f8de4ca /plugins/CoreAdminHome/tests/Integration/TasksTest.php | |
parent | 1fe8a6ee582c2f61dc209b7df856695378007c23 (diff) |
Report tracking into wrong Site ID and missing token auth (#13493)
* log tracking failures
* added page
* tweak UI
* use a db column instead of option table to simplify code
* add system summary, notifiy super users by email, fixes, update, ...
* more fixes, needs tests next
* add widget for tracking failures
* ensure to not log any failure when visit is excluded
* some tests and fixes
* added tests
* added missing test
* apply review feedback
* fix tests
* trying to fix test
* fix tests
* fix update names
* fix tests
* Fix another test.
Diffstat (limited to 'plugins/CoreAdminHome/tests/Integration/TasksTest.php')
-rw-r--r-- | plugins/CoreAdminHome/tests/Integration/TasksTest.php | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/plugins/CoreAdminHome/tests/Integration/TasksTest.php b/plugins/CoreAdminHome/tests/Integration/TasksTest.php index d3ffc66518..ffab94c01d 100644 --- a/plugins/CoreAdminHome/tests/Integration/TasksTest.php +++ b/plugins/CoreAdminHome/tests/Integration/TasksTest.php @@ -14,12 +14,15 @@ use Piwik\Date; use Piwik\Db; use Piwik\Mail; use Piwik\Plugins\CoreAdminHome\Emails\JsTrackingCodeMissingEmail; +use Piwik\Plugins\CoreAdminHome\Emails\TrackingFailuresEmail; use Piwik\Plugins\CoreAdminHome\Tasks; use Piwik\Plugins\CoreAdminHome\Tasks\ArchivesToPurgeDistributedList; use Piwik\Scheduler\Task; use Piwik\Tests\Fixtures\RawArchiveDataWithTempAndInvalidated; use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; +use Piwik\Tracker\Failures; +use Piwik\Tracker\Request; use Psr\Log\NullLogger; /** @@ -66,7 +69,7 @@ class TasksTest extends IntegrationTestCase $archivePurger->setYesterdayDate(Date::factory('2015-02-26')); $archivePurger->setNow(Date::factory('2015-02-27 08:00:00')->getTimestamp()); - $this->tasks = new Tasks($archivePurger, new NullLogger()); + $this->tasks = new Tasks($archivePurger, new NullLogger(), new Failures()); $this->mail = null; } @@ -129,6 +132,8 @@ class TasksTest extends IntegrationTestCase 'purgeOutdatedArchives.', 'purgeInvalidatedArchives.', 'optimizeArchiveTable.', + 'cleanupTrackingFailures.', + 'notifyTrackingFailures.', 'updateSpammerBlacklist.', 'checkSiteHasTrackedVisits.2', 'checkSiteHasTrackedVisits.3', @@ -181,6 +186,35 @@ class TasksTest extends IntegrationTestCase $this->assertEquals($mail->getIdSite(), $idSite); } + public function test_cleanupTrackingFailures_doesNotCauseAnyException() + { + // it is only calling one method which is already tested... no need to write complex tests for it + $this->tasks->cleanupTrackingFailures(); + $this->assertTrue(true); + } + + public function test_notifyTrackingFailures_doesNotSendAnyMailWhenThereAreNoTrackingRequests() + { + $this->tasks->notifyTrackingFailures(); + $this->assertNull($this->mail); + } + + public function test_notifyTrackingFailures_sendsMailWhenThereAreTrackingFailures() + { + $failures = new Failures(); + $failures->logFailure(1, new Request(array('idsite' => 9999, 'rec' => 1))); + $failures->logFailure(1, new Request(array('idsite' => 9998, 'rec' => 1))); + Fixture::createSuperUser(false); + $this->tasks->notifyTrackingFailures(); + + /** @var TrackingFailuresEmail $mail */ + $mail = $this->mail; + $this->assertInstanceOf(TrackingFailuresEmail::class, $mail); + $this->assertEquals('superUserLogin', $mail->getLogin()); + $this->assertEquals('hello@example.org', $mail->getEmailAddress()); + $this->assertEquals(2, $mail->getNumFailures()); + } + /** * @param Date[] $dates */ |