1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-25 00:17:37 +00:00
Files
matomo/tests/PHPUnit/Unit/DataAccess/ArchiveTableCreatorTest.php
Michal Kleiner 06d1f19978 Update core:convert-to-utf8mb4 to write db collaction to config (#22678)
* Use metadata provider instead of direct queries

* Add method to get latest installed archive table for a given type

* Update utf8mb4 conversion script to also factor in db collation

* Ensure to print errors as such in console

* Simplify sorting of archive tables

Co-authored-by: Stefan Giehl <stefan@matomo.org>

* Prevent undefined array key error if the table doesn't exist

* Simplify update script by using a newly available method to get the latest archive table

* Return early if there's no archive table found

No need to safeguard the check for collation then as the table should exist.

---------

Co-authored-by: sgiehl <stefan@matomo.org>
2024-10-14 16:19:02 +02:00

125 خطوط
3.2 KiB
PHP

<?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\Unit\DataAccess;
use Piwik\DataAccess\ArchiveTableCreator;
/**
* @group Core
*/
class ArchiveTableCreatorTest extends \PHPUnit\Framework\TestCase
{
private $tables;
public function setUp(): void
{
parent::setUp();
$this->tables = array(
'archive_numeric_2015_02',
'archive_blob_2015_05',
'archive_numeric_2014_03',
'archive_blob_2015_01',
'archive_blob_2015_02',
);
}
public function tearDown(): void
{
ArchiveTableCreator::clear();
parent::tearDown();
}
/**
* @dataProvider getTestDataForGetTablesArchivesInstalled
*/
public function testGetTablesArchivesInstalledCorrectlyFiltersTableNames($type, $expectedTables)
{
ArchiveTableCreator::$tablesAlreadyInstalled = $this->tables;
$tables = ArchiveTableCreator::getTablesArchivesInstalled($type);
$this->assertEquals($expectedTables, $tables);
}
public function getTestDataForGetTablesArchivesInstalled(): array
{
return [
[
ArchiveTableCreator::BLOB_TABLE,
[
'archive_blob_2015_05',
'archive_blob_2015_01',
'archive_blob_2015_02',
],
],
[
ArchiveTableCreator::NUMERIC_TABLE,
[
'archive_numeric_2015_02',
'archive_numeric_2014_03',
],
],
[
'qewroufsjdlf',
[],
],
[
'',
[
'archive_numeric_2015_02',
'archive_blob_2015_05',
'archive_numeric_2014_03',
'archive_blob_2015_01',
'archive_blob_2015_02',
],
],
[
null,
[
'archive_numeric_2015_02',
'archive_blob_2015_05',
'archive_numeric_2014_03',
'archive_blob_2015_01',
'archive_blob_2015_02',
],
],
];
}
/**
* @dataProvider getTestDataForGetLatestArchiveTableInstalled
*/
public function testGetLatestArchiveTableInstalled($type, $expectedLatestTable)
{
ArchiveTableCreator::$tablesAlreadyInstalled = $this->tables;
$latestTable = ArchiveTableCreator::getLatestArchiveTableInstalled($type);
$this->assertEquals($expectedLatestTable, $latestTable);
}
public function getTestDataForGetLatestArchiveTableInstalled(): array
{
return [
[ArchiveTableCreator::BLOB_TABLE, 'archive_blob_2015_05'],
[ArchiveTableCreator::NUMERIC_TABLE, 'archive_numeric_2015_02'],
['qewroufsjdlf', ''],
['', 'archive_blob_2015_05'],
[null, 'archive_blob_2015_05'],
];
}
}