1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\SegmentEditor\tests\System;
use Piwik\Config;
use Piwik\Http;
use Piwik\Plugins\SegmentEditor\API as SegmentEditorApi;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
class ApiTest extends SystemTestCase
{
public function test_segmentHashWorkflow_whenSegmentIsCrazyEncoded()
{
$segment = 'pageUrl=@%252F1';
Fixture::createWebsite('2020-03-03 00:00:00');
Config::getInstance()->General['enable_browser_archiving_triggering'] = 0;
self::$fixture->getTestEnvironment()->overrideConfig('General', 'enable_browser_archiving_triggering', 0);
self::$fixture->getTestEnvironment()->save();
$url = Fixture::getTestRootUrl() . '?' . http_build_query([
'module' => 'API',
'method' => 'SegmentEditor.add',
'name' => 'test segment',
'definition' => $segment,
'idSite' => 1,
'autoArchive' => 1,
'enabledAllUsers' => 1,
'format' => 'json',
'token_auth' => Fixture::getTokenAuth(),
]);
self::assertStringContainsString(urlencode($segment), $url);
Http::sendHttpRequest($url, 10);
$segments = SegmentEditorApi::getInstance()->getAll();
$segmentDefinitionHash = end($segments);
$segmentDefinitionHash = $segmentDefinitionHash['hash'];
$url = Fixture::getTestRootUrl() . '?' . http_build_query([
'module' => 'API',
'method' => 'ExamplePlugin.getSegmentHash',
'segment' => $segment,
'idSite' => 1,
'format' => 'json',
'token_auth' => Fixture::getTokenAuth(),
]);
$segmentApiHash = Http::sendHttpRequest($url, 10);
$segmentApiHash = json_decode($segmentApiHash, true);
$segmentApiHash = $segmentApiHash['value'];
$this->assertEquals($segmentApiHash, $segmentDefinitionHash);
}
}
|