قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 23:17:46 +00:00

* [Coding Style] Enable rule PSR12.Files.FileHeader * Apply CS * Replace Piwik with Matomo in file headers * Unify file headers (position, no. of lines, https links) * Rebuild dist files * Apply CS * Fix system test that relies on line numbers in a file that had the file header updated --------- Co-authored-by: Stefan Giehl <stefan@matomo.org>
142 خطوط
4.0 KiB
PHP
142 خطوط
4.0 KiB
PHP
<?php
|
|
|
|
namespace Piwik\Plugins\ExampleLogTables\tests\System;
|
|
|
|
use Piwik\Plugins\ExampleLogTables\tests\Fixtures\VisitsWithUserIdAndCustomData;
|
|
use Piwik\Tests\Framework\TestCase\SystemTestCase;
|
|
use Piwik\Tests\Framework\TestRequest\ApiTestConfig;
|
|
use Piwik\Tests\Framework\TestRequest\Response;
|
|
|
|
/**
|
|
* Testing Custom Log Tables
|
|
*
|
|
* @group ExampleLogTables
|
|
* @group Plugins
|
|
*/
|
|
class CustomLogTablesTest extends SystemTestCase
|
|
{
|
|
/**
|
|
* @var VisitsWithUserIdAndCustomData
|
|
*/
|
|
public static $fixture = null; // initialized below class definition
|
|
|
|
/**
|
|
* @dataProvider getApiForTesting
|
|
*/
|
|
public function testApi($api, $params)
|
|
{
|
|
$this->runApiTests($api, $params);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getSegmentsToTest
|
|
*/
|
|
public function testNoApiReturnsError($segment)
|
|
{
|
|
self::expectNotToPerformAssertions();
|
|
|
|
$dateTime = self::$fixture->dateTime;
|
|
$idSite1 = self::$fixture->idSite;
|
|
|
|
$params = [
|
|
'idSite' => $idSite1,
|
|
'date' => $dateTime,
|
|
'periods' => 'month',
|
|
'setDateLastN' => false,
|
|
'format' => 'JSON',
|
|
'segment' => $segment,
|
|
'testSuffix' => ''
|
|
];
|
|
|
|
$testConfig = new ApiTestConfig($params);
|
|
$testRequests = $this->getTestRequestsCollection('all', $testConfig, 'all');
|
|
|
|
foreach ($testRequests->getRequestUrls() as $apiId => $requestUrl) {
|
|
$response = Response::loadFromApi($params, $requestUrl, false);
|
|
$decoded = json_decode($response->getResponseText(), true);
|
|
|
|
if (is_array($decoded) && isset($decoded['result']) && $decoded['result'] == 'error') {
|
|
$this->fail('API returned an error when requesting ' . http_build_query($requestUrl) . "\nMessage: " . $decoded['message']);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getSegmentsToTest()
|
|
{
|
|
return [
|
|
['attrgender==men'],
|
|
['isadmin==1'],
|
|
];
|
|
}
|
|
|
|
public function getApiForTesting()
|
|
{
|
|
$dateTime = self::$fixture->dateTime;
|
|
$idSite1 = self::$fixture->idSite;
|
|
|
|
$result = [
|
|
[[
|
|
'Actions.get',
|
|
'UserId.getUsers',
|
|
'VisitsSummary.get'
|
|
], [
|
|
'idSite' => $idSite1,
|
|
'date' => $dateTime,
|
|
'periods' => 'month',
|
|
'setDateLastN' => false,
|
|
'segment' => 'attrgender==men',
|
|
'testSuffix' => '_men']
|
|
],
|
|
[[
|
|
'Actions.get',
|
|
'UserId.getUsers',
|
|
'VisitsSummary.get'
|
|
], [
|
|
'idSite' => $idSite1,
|
|
'date' => $dateTime,
|
|
'periods' => 'month',
|
|
'setDateLastN' => false,
|
|
'segment' => 'attrgender==women',
|
|
'testSuffix' => '_women']
|
|
],
|
|
[[
|
|
'Actions.get',
|
|
'UserId.getUsers',
|
|
'VisitsSummary.get'
|
|
], [
|
|
'idSite' => $idSite1,
|
|
'date' => $dateTime,
|
|
'periods' => 'month',
|
|
'setDateLastN' => false,
|
|
'segment' => 'isadmin==1',
|
|
'testSuffix' => '_admin']
|
|
],
|
|
[[
|
|
'Actions.get',
|
|
'UserId.getUsers',
|
|
'VisitsSummary.get'
|
|
], [
|
|
'idSite' => $idSite1,
|
|
'date' => $dateTime,
|
|
'periods' => 'month',
|
|
'setDateLastN' => false,
|
|
'testSuffix' => '_all']
|
|
],
|
|
];
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function getOutputPrefix()
|
|
{
|
|
return 'ExampleLogTables';
|
|
}
|
|
|
|
public static function getPathToTestDirectory()
|
|
{
|
|
return dirname(__FILE__);
|
|
}
|
|
}
|
|
|
|
CustomLogTablesTest::$fixture = new VisitsWithUserIdAndCustomData();
|