diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-12-04 05:04:02 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-12-04 05:04:02 +0300 |
commit | 9d71fc8e92e5b434fd69c7ab4b83a69169064cf3 (patch) | |
tree | 8cb2798746e4defb1a978cd758df72006ec419ae /tests/PHPUnit/System/TrackerResponseTest.php | |
parent | 784b738f9c4a92c42a9d8e6b85c28a82a3af0a2f (diff) |
Tracker refactoring
Diffstat (limited to 'tests/PHPUnit/System/TrackerResponseTest.php')
-rwxr-xr-x | tests/PHPUnit/System/TrackerResponseTest.php | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/PHPUnit/System/TrackerResponseTest.php b/tests/PHPUnit/System/TrackerResponseTest.php new file mode 100755 index 0000000000..7bd0f7aef7 --- /dev/null +++ b/tests/PHPUnit/System/TrackerResponseTest.php @@ -0,0 +1,106 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Tests\System; + +use Piwik\Tests\Framework\Fixture; +use Piwik\Tests\Framework\TestCase\SystemTestCase; + +/** + * @group TrackerTest + * @group Plugins + */ +class TrackerResponseTest extends SystemTestCase +{ + public static $fixture = null; + + /** + * @var \PiwikTracker + */ + private $tracker; + + public function setUp() + { + parent::setUp(); + + $idSite = 1; + $dateTime = '2014-01-01 00:00:01'; + + if (!Fixture::siteCreated($idSite)) { + Fixture::createWebsite($dateTime); + } + + $this->tracker = Fixture::getTracker($idSite, $dateTime, $defaultInit = true); + } + + public function test_response_ShouldContainAnImage() + { + $response = $this->tracker->doTrackPageView('Test'); + + Fixture::checkResponse($response); + $this->assertNotEmpty($response); + } + + public function test_response_ShouldBeEmpty_IfImageIsDisabled() + { + $this->tracker->disableSendImageResponse(); + + $response = $this->tracker->doTrackPageView('Test'); + + $this->assertSame('', $response); + } + + public function test_response_ShouldSend200ResponseCode_IfImageIsEnabled() + { + $url = $this->tracker->getUrlTrackPageView('Test'); + + $this->assertResponseCode(200, $url); + } + + public function test_response_ShouldSend204ResponseCode_IfImageIsDisabled() + { + $url = $this->tracker->getUrlTrackPageView('Test'); + $url .= '&send_image=0'; + + $this->assertResponseCode(204, $url); + } + + public function test_response_ShouldSend400ResponseCode_IfSiteIdIsInvalid() + { + $url = $this->tracker->getUrlTrackPageView('Test'); + $url .= '&idsite=100'; + + $this->assertResponseCode(400, $url); + } + + public function test_response_ShouldSend400ResponseCode_IfSiteIdIsZero() + { + $url = $this->tracker->getUrlTrackPageView('Test'); + $url .= '&idsite=0'; + + $this->assertResponseCode(400, $url); + } + + public function test_response_ShouldSend400ResponseCode_IfInvalidRequestParameterIsGiven() + { + $url = $this->tracker->getUrlTrackPageView('Test'); + $url .= '&cid=' . str_pad('1', 16, '1'); + + $this->assertResponseCode(200, $url); + $this->assertResponseCode(400, $url . '1'); // has to be 16 char, but is 17 now + } + + public function test_response_ShouldReturnPiwikMessage_InCaseOfEmptyRequest() + { + $url = Fixture::getTrackerUrl(); + $response = file_get_contents($url); + + $expected = "<a href='/'>Piwik</a> is a free/libre web <a href='http://piwik.org'>analytics</a> that lets you keep control of your data."; + $this->assertEquals($expected, $response); + } + +} |