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:
authordiosmosis <benaka@piwik.pro>2015-08-25 22:13:17 +0300
committerdiosmosis <benaka@piwik.pro>2015-09-01 23:08:18 +0300
commitce2dfe180b222176b0c7022a3f024fa2b036d5df (patch)
tree9ef6cfdb0c99b1409a598b0af71dc88687720e00
parent48ababe8bc86b73e592daea171211dbf9c6ab148 (diff)
Adding tests for related log importer PR here: https://github.com/piwik/piwik-log-analytics/pull/94
-rw-r--r--tests/PHPUnit/Fixtures/ManySitesImportedLogs.php6
-rwxr-xr-xtests/PHPUnit/System/ImportLogsTest.php58
-rw-r--r--tests/resources/access-logs/fake_logs_dynamic.log4
3 files changed, 55 insertions, 13 deletions
diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
index 133f490889..3a107c26bd 100644
--- a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
+++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
@@ -192,7 +192,7 @@ class ManySitesImportedLogs extends Fixture
* Logs a couple visits for the site we created and two new sites that do not
* exist yet. Visits are from Aug 12, 13 & 14 of 2012.
*/
- public function logVisitsWithDynamicResolver()
+ public function logVisitsWithDynamicResolver($maxPayloadSize = 1)
{
$logFile = PIWIK_INCLUDE_PATH . '/tests/resources/access-logs/fake_logs_dynamic.log'; # log file
@@ -201,8 +201,8 @@ class ManySitesImportedLogs extends Fixture
$opts = array('--add-sites-new-hosts' => false,
'--enable-testmode' => false,
'--recorders' => '1',
- '--recorder-max-payload-size' => '1');
- self::executeLogImporter($logFile, $opts);
+ '--recorder-max-payload-size' => $maxPayloadSize);
+ return implode("\n", self::executeLogImporter($logFile, $opts));
}
/**
diff --git a/tests/PHPUnit/System/ImportLogsTest.php b/tests/PHPUnit/System/ImportLogsTest.php
index 952154b535..725b2fba16 100755
--- a/tests/PHPUnit/System/ImportLogsTest.php
+++ b/tests/PHPUnit/System/ImportLogsTest.php
@@ -8,11 +8,14 @@
namespace Piwik\Tests\System;
use Piwik\Access;
+use Piwik\Common;
use Piwik\Plugins\SitesManager\API;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\ManySitesImportedLogs;
use Piwik\Tests\Framework\TestingEnvironmentVariables;
+use Piwik\Tracker\Request;
+use Piwik\Tracker\RequestSet;
/**
* Tests the log importer.
@@ -103,10 +106,15 @@ class ImportLogsTest extends SystemTestCase
/**
* NOTE: This test must be last since the new sites that get added are added in
* random order.
+ * NOTE: This test combines two tests in order to avoid executing the log importer another time.
+ * If the log importer were refactored, the invalid requests test could be a unit test in
+ * python.
*/
- public function testDynamicResolverSitesCreated()
+ public function test_LogImporter_CreatesSitesWhenDynamicResolverUsed_AndReportsOnInvalidRequests()
{
- self::$fixture->logVisitsWithDynamicResolver();
+ $this->simulateInvalidTrackerRequest();
+
+ $output = self::$fixture->logVisitsWithDynamicResolver($maxPayloadSize = 3);
// reload access so new sites are viewable
Access::getInstance()->setSuperUserAccess(true);
@@ -120,6 +128,10 @@ class ImportLogsTest extends SystemTestCase
$whateverDotCom = API::getInstance()->getSitesIdFromSiteUrl('http://whatever.com');
$this->assertEquals(1, count($whateverDotCom));
+
+ // make sure invalid requests are reported correctly
+ $this->assertContains('The Piwik tracker identified 2 invalid requests on lines: 10, 11', $output);
+ $this->assertContains("The following lines were not tracked by Piwik, either due to a malformed tracker request or error in the tracker:\n\n10, 11", $output);
}
public function test_LogImporter_RetriesWhenServerFails()
@@ -163,23 +175,53 @@ class ImportLogsTest extends SystemTestCase
{
$testingEnvironment = new TestingEnvironmentVariables();
$testingEnvironment->_triggerTrackerFailure = null;
+ $testingEnvironment->_triggerInvalidRequests = null;
$testingEnvironment->save();
}
+ private function simulateInvalidTrackerRequest()
+ {
+ $testEnvironment = new TestingEnvironmentVariables();
+ $testEnvironment->_triggerInvalidRequests = true;
+ $testEnvironment->save();
+ }
+
public static function provideContainerConfigBeforeClass()
{
$result = array();
+ $observers = array();
$testingEnvironment = new TestingEnvironmentVariables();
if ($testingEnvironment->_triggerTrackerFailure) {
- $result['observers.global'] = \DI\add(array(
- array('Tracker.newHandler', function () {
- @http_response_code(500);
+ $observers[] = array('Tracker.newHandler', function () {
+ @http_response_code(500);
- throw new \Exception("injected exception");
- })
- ));
+ throw new \Exception("injected exception");
+ });
}
+
+ if ($testingEnvironment->_triggerInvalidRequests) {
+ // we trigger an invalid request by checking for triggerInvalid=1 in a request, and if found replacing the
+ // request w/ a request that has an nonexistent idsite
+ $observers[] = array('Tracker.initRequestSet', function (RequestSet $requestSet) {
+ $requests = $requestSet->getRequests();
+ foreach ($requests as $index => $request) {
+ $url = $request->getParam('url');
+ if (strpos($url, 'triggerInvalid=1') !== false) {
+ $newParams = $request->getParams();
+ $newParams['idsite'] = 1000;
+
+ $requests[$index] = new Request($newParams);
+ }
+ }
+ $requestSet->setRequests($requests);
+ });
+ }
+
+ if (!empty($observers)) {
+ $result['observers.global'] = \DI\add($observers);
+ }
+
return $result;
}
}
diff --git a/tests/resources/access-logs/fake_logs_dynamic.log b/tests/resources/access-logs/fake_logs_dynamic.log
index 75ef54c1d4..04ad6c2384 100644
--- a/tests/resources/access-logs/fake_logs_dynamic.log
+++ b/tests/resources/access-logs/fake_logs_dynamic.log
@@ -8,8 +8,8 @@ whatever.com 72.44.32.10 - - [12/Aug/2012:15:49:48 +0200] "GET /translations/ HT
piwik.net 175.41.192.09 - - [12/Aug/2012:22:56:45 +0200] "GET /docs/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0"
piwik.net 175.41.192.09 - - [12/Aug/2012:23:00:42 +0200] "GET /docs/manage-users/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3"
whatever.com 79.125.00.21 - - [13/Aug/2012:20:03:40 +0200] "GET /newsletter/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)"
-whatever.com 175.41.192.34 - - [13/Aug/2012:21:59:50 +0200] "GET /faq/how-to/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)"
-anothersite.com 175.41.192.34 - - [13/Aug/2012:22:01:17 +0200] "GET /faq/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; U; Linux x86_64; fr-FR) AppleWebKit/534.7 (KHTML, like Gecko) Epiphany/2.30.6 Safari/534.7"
+whatever.com 175.41.192.34 - - [13/Aug/2012:21:59:50 +0200] "GET /faq/how-to/?triggerInvalid=1 HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)"
+anothersite.com 175.41.192.34 - - [13/Aug/2012:22:01:17 +0200] "GET /faq/?triggerInvalid=1 HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; U; Linux x86_64; fr-FR) AppleWebKit/534.7 (KHTML, like Gecko) Epiphany/2.30.6 Safari/534.7"
anothersite.com 177.71.128.21 - - [13/Aug/2012:22:21:03 +0200] "GET /docs/manage-websites/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0"
anothersite.com 177.71.128.21 - - [13/Aug/2012:22:21:28 +0200] "GET /intranet-analytics/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; U; Linux x86_64; fr-FR) AppleWebKit/534.7 (KHTML, like Gecko) Epiphany/2.30.6 Safari/534.7"
whatever.com 177.71.128.21 - - [13/Aug/2012:22:22:08 +0200] "GET /blog/2012/08/survey-your-opinion-matters/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6"