Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SimpleTest.php « DataTable « Unit « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e95a1ee0e6bd315c661e6f9b34c44d87b4b72529 (plain)
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
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Tests\Unit\DataTable;


use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\DataTable\Simple;

class SimpleTest extends \PHPUnit\Framework\TestCase
{
    public function test_serialize_includesAllRequiredData()
    {
        $dataTable = new Simple();
        $dataTable->addRowFromSimpleArray([
            'column1' => 'value1',
            'column2' => 'value2',
        ]);
        $dataTable->addSummaryRow(new Row([
            Row::COLUMNS => ['column1' => 'total1', 'column2' => 'total2']
        ]));
        $dataTable->setAllTableMetadata([
            'metadataKey1' => 10,
            'metadataKey2' => ['a', 'b', 'c'],
        ]);

        $serialized = serialize($dataTable);

        /** @var Simple $unserialized */
        $unserialized = unserialize($serialized);

        $this->assertEquals(1, $unserialized->getRowsCountWithoutSummaryRow());
        $this->assertEquals([
            'column1' => 'value1',
            'column2' => 'value2',
        ], $unserialized->getRows()[0]->getColumns());

        $this->assertEquals(2, $unserialized->getRowsCount());
        $this->assertEquals(['column1' => 'total1', 'column2' => 'total2'], $unserialized->getRows()[DataTable::ID_SUMMARY_ROW]->getColumns());

        $this->assertEquals([
            'metadataKey1' => 10,
            'metadataKey2' => ['a', 'b', 'c'],
        ], $unserialized->getAllTableMetadata());
    }
}