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

RemoveUserIfNeededTest.php « Filter « DataTable « Integration « tests « CustomDimensions « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1aacb27ad1a6b04ef8c1de7bfff808e9ee9312de (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
53
54
55
56
57
58
59
60
61
62
<?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\CustomDimensions\tests\Integration\DataTable\Filter;

use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;

/**
 * @group CustomDimensions
 * @group DimensionTest
 * @group Dimension
 * @group Dao
 * @group Plugins
 */
class RemoveUserIfNeededTest extends IntegrationTestCase
{
    private $filter = 'Piwik\Plugins\CustomDimensions\DataTable\Filter\RemoveUserIfNeeded';

    public function setUp(): void
    {
        parent::setUp();

        Fixture::createWebsite('2010-01-01 00:00:00');
    }

    public function test_filter_shouldNotRemoveColumn_IfThereIsAValueInTableForNbUsers()
    {
        $columns = $this->filterTable($withUser = 5);

        $this->assertSame(array(0, false, 5), $columns);
    }

    public function test_filter_withoutUsers_shouldRemoveColumn()
    {
        $columns = $this->filterTable($withUser = 0);
        $this->assertSame(array(false, false, false), $columns);
    }

    private function filterTable($withUser = 5)
    {
        $dataTable = new DataTable();
        $dataTable->addRowsFromArray(array(
            array(Row::COLUMNS => array('label' => 'val1', Metrics::INDEX_NB_USERS => 0)),
            array(Row::COLUMNS => array('label' => 'val2')),
            array(Row::COLUMNS => array('label' => 'val2 5w ö?', Metrics::INDEX_NB_USERS => $withUser))
        ));

        $dataTable->filter($this->filter, array($idSite = 1, $period = 'day', $date = 'today'));

        return $dataTable->getColumn(Metrics::INDEX_NB_USERS);
    }

}