File size: 4,000 Bytes
bf8c0ce | 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | <?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration;
use Piwik\CacheId;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group Cache
* @group CacheId
*/
class CacheIdTest extends IntegrationTestCase
{
public function setUp(): void
{
Fixture::loadAllTranslations();
}
public function tearDown(): void
{
Fixture::resetTranslations();
}
public function testLanguageAwareShouldAppendTheLoadedLanguage()
{
$result = CacheId::languageAware('myrandomkey');
$this->assertEquals('myrandomkey-en', $result);
}
public function testPluginAwareShouldAppendLoadedPluginsAndLanguage()
{
$result = CacheId::pluginAware('myrandomkey');
$parts = explode('-', $result);
$this->assertCount(3, $parts);
$this->assertEquals('myrandomkey', $parts[0]);
$this->assertEquals(32, strlen($parts[1]), $parts[1] . ' is not a MD5 hash');
$this->assertEquals('en', $parts[2]);
}
public function testSiteAwareShouldAppendIdSitesPassed()
{
$result = CacheId::siteAware('key', [1,2,3]);
$this->assertEquals('key-1_2_3', $result);
$result = CacheId::siteAware('key', [1,2,3,4,5,6,7,9]);
$this->assertEquals('key-f791852e88bb2a1f130f37b4a9e2c351', $result);
}
/**
* @dataProvider getTestDataForSiteAware
*/
public function testSiteAwareShouldAppendIdSiteQueryParamsIfArgumentIsNull($getParams, $postParams, $expected)
{
$_GET = $getParams;
$_POST = $postParams;
$result = CacheId::siteAware('key');
$this->assertEquals($expected, $result);
}
public function getTestDataForSiteAware()
{
return [
[
['idSite' => '1'],
[],
'key-1',
],
[
['idSite' => '0,1,2'],
[],
'key-0_1_2',
],
[
['idSites' => '0,4,3,2'],
[],
'key-0_2_3_4',
],
[
['idSite' => 'all'],
[],
'key-0',
],
[
['idSite' => '3,4', 'idSites' => '4,5,6'],
[],
'key-3_4-4_5_6',
],
[
['idSite' => '3,4,5,6,7,8', 'idSites' => '9,10,11,12,19,14,15'],
[],
'key-09c89807ba10937c5ced44af9d9d49e8-8bec4c3209c94166186190a26a2920cb',
],
[
[],
[],
'key',
],
[
['idSite' => '3,4,5', 'idsite' => '9,13,15'],
[],
'key-3_4_5-9_13_15',
],
[
['idSite' => '3,4,5', 'idSites' => '1', 'idsite' => '9,13,15'],
[],
'key-3_4_5-1-9_13_15',
],
[
['idSite' => '1,2'],
['idSite' => '4,5'],
'key-1_2_4_5',
],
[
['idSites' => '1,2'],
['idSite' => '4,5'],
'key-4_5-1_2',
],
[
['idSite' => '1,2', 'idSites' => '9,9', 'idsite' => '12,13'],
['idSite' => '4,5', 'idSites' => '9,8', 'idsite' => '14,15'],
'key-1_2_4_5-8_9-12_13_14_15',
],
// must support $_GET/$_POST values being arrays and not strings
[
['idSite' => ['1', '2'], 'idSites' => ['9', '9'], 'idsite' => ['12', '13']],
['idSite' => ['4', '5'], 'idSites' => ['9', '8'], 'idsite' => ['14', '15']],
'key-1_2_4_5-8_9-12_13_14_15',
],
];
}
}
|