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
|
<?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\SegmentEditor\tests\Integration;
use Piwik\Plugins\SegmentEditor\SegmentFormatter;
use Piwik\Plugins\SegmentEditor\SegmentList;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Translate;
use Exception;
/**
* @group SegmentFormatterTest
* @group SegmentFormatter
* @group SegmentEditor
* @group Plugins
*/
class SegmentFormatterTest extends IntegrationTestCase
{
/**
* @var SegmentFormatter
*/
private $formatter;
private $idSite;
public function setUp()
{
parent::setUp();
$this->idSite = Fixture::createWebsite('2012-01-01 00:00:00');
$this->formatter = new SegmentFormatter(new SegmentList());
Translate::loadAllTranslations();
}
public function tearDown()
{
Translate::reset();
}
public function test_getHumanReadable_noSegmentGiven_ShouldReturnDefaultSegment()
{
$readable = $this->formatter->getHumanReadable($segment = '', $this->idSite);
$this->assertSame('All visits', $readable);
}
public function test_getHumanReadable_ShouldTranslateAMetric()
{
$readable = $this->formatter->getHumanReadable($segment = 'visitCount>5', $this->idSite);
$this->assertSame('Number of visits greater than "5"', $readable);
$readable = $this->formatter->getHumanReadable($segment = 'visitCount==5', $this->idSite);
$this->assertSame('Number of visits equals "5"', $readable);
}
public function test_getHumanReadable_ShouldTranslateADimension()
{
$readable = $this->formatter->getHumanReadable($segment = 'resolution=@1024', $this->idSite);
$this->assertSame('Resolution contains "1024"', $readable);
$readable = $this->formatter->getHumanReadable($segment = 'resolution==1024x768', $this->idSite);
$this->assertSame('Resolution is "1024x768"', $readable);
}
public function test_getHumanReadable_ShouldCombineMultipleSegmentDefinitionsWithBooleanOperator()
{
$readable = $this->formatter->getHumanReadable($segment = 'browserVersion!=1.0;browserEngine=$Trident', $this->idSite);
$this->assertSame('Browser version is not "1.0" and Browser engine ends with "Trident"', $readable);
$readable = $this->formatter->getHumanReadable($segment = 'browserVersion!=1.0,browserEngine=$Trident', $this->idSite);
$this->assertSame('Browser version is not "1.0" or Browser engine ends with "Trident"', $readable);
}
public function test_getHumanReadable_ShouldHandleAMissingValue()
{
$readable = $this->formatter->getHumanReadable($segment = 'browserVersion==', $this->idSite);
$this->assertSame('Browser version is null or empty', $readable);
$readable = $this->formatter->getHumanReadable($segment = 'browserVersion!=', $this->idSite);
$this->assertSame('Browser version is not null nor empty', $readable);
}
/**
* @expectedException \Exception
* @expectedExceptionMessage The segment 'noTexisTinG' does not exist
*/
public function test_getHumanReadable_ShouldThrowAnException_IfTheGivenSegmentNameDoesNotExist()
{
$this->formatter->getHumanReadable($segment = 'noTexisTinG==1.0', $this->idSite);
}
/**
* @expectedException \Exception
* @expectedExceptionMessage The segment 'pageUrl=!1.0' is not valid.
*/
public function test_getHumanReadable_ShouldThrowAnException_IfSegmentCannotBeParsedBecauseOfInvalidFormat()
{
$invalidOperator = '=!';
$this->formatter->getHumanReadable($segment = 'pageUrl' . $invalidOperator . '1.0', $this->idSite);
}
}
|