-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functional tests regarding actual frontend request tracking
Ensures pageview and recordview are tracked as expected. Relates: #46
- Loading branch information
1 parent
721b6e5
commit 73e2ec0
Showing
10 changed files
with
237 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Tests/Functional/Fixtures/Extensions/recordview/Configuration/Services.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
DanielSiepmann\Tracking\Middleware\Recordview: | ||
public: true | ||
arguments: | ||
$rules: | ||
topics: | ||
matches: 'request.getQueryParams()["topic_id"] > 0' | ||
recordUid: 'request.getQueryParams()["topic_id"]' | ||
tableName: 'sys_category' |
23 changes: 23 additions & 0 deletions
23
Tests/Functional/Fixtures/Extensions/recordview/ext_emconf.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
$EM_CONF[$_EXTKEY] = [ | ||
'title' => 'TESTING: Tracking recordview', | ||
'description' => 'Used by functional tests', | ||
'category' => 'fe', | ||
'state' => 'stable', | ||
'uploadfolder' => 0, | ||
'createDirs' => '', | ||
'clearCacheOnLoad' => 0, | ||
'author' => 'Daniel Siepmann', | ||
'author_email' => '[email protected]', | ||
'author_company' => '', | ||
'version' => '1.1.2', | ||
'constraints' => [ | ||
'depends' => [ | ||
'core' => '', | ||
'tracking' => '', | ||
], | ||
'conflicts' => [], | ||
'suggests' => [], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
page = PAGE | ||
page { | ||
10 = TEXT | ||
10.value = Output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
base: 'https://example.com' | ||
base: '/' | ||
languages: | ||
- | ||
title: English | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace DanielSiepmann\Tracking\Tests\Functional; | ||
|
||
/* | ||
* Copyright (C) 2021 Daniel Siepmann <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; | ||
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase as TestCase; | ||
|
||
/** | ||
* @testdox Pageviews are | ||
*/ | ||
class PageviewTest extends TestCase | ||
{ | ||
protected $testExtensionsToLoad = [ | ||
'typo3conf/ext/tracking', | ||
]; | ||
|
||
protected $pathsToLinkInTestInstance = [ | ||
'typo3conf/ext/tracking/Tests/Functional/Fixtures/sites' => 'typo3conf/sites', | ||
]; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml'); | ||
$this->setUpFrontendRootPage(1, [ | ||
'EXT:tracking/Tests/Functional/Fixtures/Rendering.typoscript', | ||
]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function trackedWhenAllowed(): void | ||
{ | ||
$request = new InternalRequest(); | ||
$request = $request->withPageId(1); | ||
$request = $request->withHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0'); | ||
$response = $this->executeFrontendRequest($request); | ||
|
||
self::assertSame(200, $response->getStatusCode()); | ||
|
||
$records = $this->getAllRecords('tx_tracking_pageview'); | ||
self::assertCount(1, $records); | ||
self::assertSame('1', (string)$records[0]['pid']); | ||
self::assertSame('1', (string)$records[0]['uid']); | ||
self::assertSame('http://localhost/?id=1', $records[0]['url']); | ||
self::assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', $records[0]['user_agent']); | ||
self::assertSame('Macintosh', $records[0]['operating_system']); | ||
self::assertSame('0', (string)$records[0]['type']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function notTrackedWhenDisallowed(): void | ||
{ | ||
$this->setUpBackendUserFromFixture(1); | ||
|
||
$request = new InternalRequest(); | ||
$request = $request->withPageId(1); | ||
$context = new InternalRequestContext(); | ||
$context = $context->withBackendUserId(1); | ||
$response = $this->executeFrontendRequest($request, $context); | ||
|
||
self::assertSame(200, $response->getStatusCode()); | ||
|
||
$records = $this->getAllRecords('tx_tracking_pageview'); | ||
self::assertCount(0, $records); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace DanielSiepmann\Tracking\Tests\Functional; | ||
|
||
/* | ||
* Copyright (C) 2021 Daniel Siepmann <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; | ||
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase as TestCase; | ||
|
||
/** | ||
* @testdox Recordviews are | ||
*/ | ||
class RecordviewTest extends TestCase | ||
{ | ||
protected $testExtensionsToLoad = [ | ||
'typo3conf/ext/tracking', | ||
'typo3conf/ext/tracking/Tests/Functional/Fixtures/Extensions/recordview', | ||
]; | ||
|
||
protected $pathsToLinkInTestInstance = [ | ||
'typo3conf/ext/tracking/Tests/Functional/Fixtures/sites' => 'typo3conf/sites', | ||
]; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml'); | ||
$this->setUpFrontendRootPage(1, [ | ||
'EXT:tracking/Tests/Functional/Fixtures/Rendering.typoscript', | ||
]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function trackedWhenAllowed(): void | ||
{ | ||
$request = new InternalRequest(); | ||
$request = $request->withPageId(1); | ||
$request = $request->withQueryParameter('topic_id', 1); | ||
$request = $request->withHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0'); | ||
$response = $this->executeFrontendRequest($request); | ||
|
||
self::assertSame(200, $response->getStatusCode()); | ||
|
||
$records = $this->getAllRecords('tx_tracking_recordview'); | ||
self::assertCount(1, $records); | ||
self::assertSame('1', (string)$records[0]['pid']); | ||
self::assertSame('1', (string)$records[0]['uid']); | ||
self::assertSame('http://localhost/?id=1&topic_id=1', $records[0]['url']); | ||
self::assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', $records[0]['user_agent']); | ||
self::assertSame('Macintosh', $records[0]['operating_system']); | ||
self::assertSame('sys_category_1', $records[0]['record']); | ||
self::assertSame('1', (string)$records[0]['record_uid']); | ||
self::assertSame('sys_category', $records[0]['record_table_name']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function notTrackedWhenNotDetected(): void | ||
{ | ||
$request = new InternalRequest(); | ||
$request = $request->withPageId(1); | ||
$response = $this->executeFrontendRequest($request); | ||
|
||
self::assertSame(200, $response->getStatusCode()); | ||
|
||
$records = $this->getAllRecords('tx_tracking_recordview'); | ||
self::assertCount(0, $records); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters