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

FilterExcludeLowValueTest.php « Unit « tests « Insights « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 51c0192ef66f0d968c2b56e55940d3f7b4f62390 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\Insights\tests;

use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Plugins\Insights\DataTable\Filter\ExcludeLowValue;

/**
 * @group Insights
 * @group FilterExcludeLowValueTest
 * @group Unit
 * @group Core
 */
class FilterExcludeLowValueTest extends BaseUnitTest
{
    public function setUp()
    {
        $this->table = new DataTable();
        $this->table->addRowsFromArray(array(
            array(Row::COLUMNS => array('label' => 'val1', 'growth' => 22, 'isFooBar' => false)),
            array(Row::COLUMNS => array('label' => 'val2', 'growth' => 14, 'isFooBar' => true)),
            array(Row::COLUMNS => array('label' => 'val3', 'growth' => 18, 'isFooBar' => false)),
            array(Row::COLUMNS => array('label' => 'val4', 'growth' => 20, 'isFooBar' => true)),
            array(Row::COLUMNS => array('label' => 'val5', 'growth' => 22, 'isFooBar' => true)),
            array(Row::COLUMNS => array('label' => 'val6', 'growth' => 25, 'isFooBar' => true)),
            array(Row::COLUMNS => array('label' => 'val7', 'growth' => 17, 'isFooBar' => false)),
            array(Row::COLUMNS => array('label' => 'val8', 'growth' => 20, 'isFooBar' => false)),
            array(Row::COLUMNS => array('label' => 'val9', 'growth' => 0, 'isFooBar' => false)),
            array(Row::COLUMNS => array('label' => 'val10', 'growth' => 15, 'isFooBar' => false)),
            array(Row::COLUMNS => array('label' => 'val11', 'growth' => 16, 'isFooBar' => true))
        ));
    }

    public function testShouldNotRemoveAnyIfMinValueIsZero()
    {
        $rowsCountBefore = $this->table->getRowsCount();
        $this->assertGreaterThan(0, $rowsCountBefore);

        $this->excludeLowValues(0);

        $this->assertSame($rowsCountBefore, $this->table->getRowsCount());
    }

    public function testShouldKeepAllRowsHavingHigherGrowth()
    {
        $this->excludeLowValues(15);

        $this->assertOrder(array('val1', 'val3', 'val4', 'val5', 'val6', 'val7', 'val8', 'val10', 'val11'));
    }

    public function testShouldKeepRowsIfTheyHaveGivenMinGrowth()
    {
        $this->excludeLowValues(22);

        $this->assertOrder(array('val1', 'val5', 'val6'));
    }

    public function testShouldRemoveAllIfMinValueIsTooHigh()
    {
        $this->excludeLowValues(99);

        $this->assertOrder(array());
    }

    public function testShouldRemoveValuesOnlyIfColumnToCheckIsTrue()
    {
        $this->excludeLowValues(21, 'isFooBar');

        $this->assertOrder(array('val1', 'val3', 'val5', 'val6', 'val7', 'val8', 'val9', 'val10'));
    }

    private function excludeLowValues($minimumValue, $columnToCheck = null)
    {
        $filter = new ExcludeLowValue($this->table, 'growth', $minimumValue, $columnToCheck);
        $filter->filter($this->table);
    }

}