mirror of
https://github.com/DanielSiepmann/tracking.git
synced 2024-11-22 05:56:08 +01:00
Add functional tests regarding actual frontend request tracking
Ensures pageview and recordview are tracked as expected. Relates: #46
This commit is contained in:
parent
721b6e5a31
commit
73e2ec0214
10 changed files with 237 additions and 4 deletions
|
@ -244,7 +244,7 @@ class PageviewsPerPageTest extends TestCase
|
||||||
$result = $subject->getChartData();
|
$result = $subject->getChartData();
|
||||||
static::assertSame([
|
static::assertSame([
|
||||||
'Page 2',
|
'Page 2',
|
||||||
'Seite 1',
|
'Page 1',
|
||||||
], $result['labels']);
|
], $result['labels']);
|
||||||
static::assertCount(2, $result['datasets'][0]['data']);
|
static::assertCount(2, $result['datasets'][0]['data']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'
|
|
@ -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' => 'coding@daniel-siepmann.de',
|
||||||
|
'author_company' => '',
|
||||||
|
'version' => '1.1.2',
|
||||||
|
'constraints' => [
|
||||||
|
'depends' => [
|
||||||
|
'core' => '',
|
||||||
|
'tracking' => '',
|
||||||
|
],
|
||||||
|
'conflicts' => [],
|
||||||
|
'suggests' => [],
|
||||||
|
],
|
||||||
|
];
|
|
@ -1,9 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<dataset>
|
<dataset>
|
||||||
<pages>
|
<pages>
|
||||||
<pid>1</pid>
|
<pid>0</pid>
|
||||||
<uid>1</uid>
|
<uid>1</uid>
|
||||||
<title>Page 1</title>
|
<title>Page 1</title>
|
||||||
|
<slug>/</slug>
|
||||||
</pages>
|
</pages>
|
||||||
<pages>
|
<pages>
|
||||||
<pid>1</pid>
|
<pid>1</pid>
|
||||||
|
|
5
Tests/Functional/Fixtures/Rendering.typoscript
Normal file
5
Tests/Functional/Fixtures/Rendering.typoscript
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
page = PAGE
|
||||||
|
page {
|
||||||
|
10 = TEXT
|
||||||
|
10.value = Output
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
base: 'https://example.com'
|
base: '/'
|
||||||
languages:
|
languages:
|
||||||
-
|
-
|
||||||
title: English
|
title: English
|
||||||
|
|
91
Tests/Functional/PageviewTest.php
Normal file
91
Tests/Functional/PageviewTest.php
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DanielSiepmann\Tracking\Tests\Functional;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
91
Tests/Functional/RecordviewTest.php
Normal file
91
Tests/Functional/RecordviewTest.php
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DanielSiepmann\Tracking\Tests\Functional;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,8 @@
|
||||||
"phpspec/prophecy-phpunit": "^2.0",
|
"phpspec/prophecy-phpunit": "^2.0",
|
||||||
"typo3/testing-framework": "^6.8.2",
|
"typo3/testing-framework": "^6.8.2",
|
||||||
"saschaegerer/phpstan-typo3": "^0.13.1",
|
"saschaegerer/phpstan-typo3": "^0.13.1",
|
||||||
"symplify/easy-coding-standard": "^9.3"
|
"symplify/easy-coding-standard": "^9.3",
|
||||||
|
"cweagans/composer-patches": "^1.7"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
|
@ -62,6 +63,12 @@
|
||||||
"extension-key": "tracking",
|
"extension-key": "tracking",
|
||||||
"web-dir": ".Build/web"
|
"web-dir": ".Build/web"
|
||||||
},
|
},
|
||||||
|
"composer-exit-on-patch-failure": true,
|
||||||
|
"patches": {
|
||||||
|
"typo3/testing-framework": {
|
||||||
|
"[FEATURE] Support custom user agent in functional tests #257": "https://patch-diff.githubusercontent.com/raw/TYPO3/testing-framework/pull/257.patch"
|
||||||
|
}
|
||||||
|
},
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-main": "1.0.x-dev"
|
"dev-main": "1.0.x-dev"
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,3 +13,4 @@ parameters:
|
||||||
- '#Cannot call method fetchAll\(\) on Doctrine\\DBAL\\Driver\\ResultStatement\|int\.#'
|
- '#Cannot call method fetchAll\(\) on Doctrine\\DBAL\\Driver\\ResultStatement\|int\.#'
|
||||||
- '#Cannot call method fetchColumn\(\) on Doctrine\\DBAL\\Driver\\Statement\|int\.#'
|
- '#Cannot call method fetchColumn\(\) on Doctrine\\DBAL\\Driver\\Statement\|int\.#'
|
||||||
- '#Cannot call method fetchColumn\(\) on Doctrine\\DBAL\\Driver\\ResultStatement\|int\.#'
|
- '#Cannot call method fetchColumn\(\) on Doctrine\\DBAL\\Driver\\ResultStatement\|int\.#'
|
||||||
|
- '#^Variable \$_EXTKEY might not be defined\.$#'
|
||||||
|
|
Loading…
Reference in a new issue