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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
<?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\Tests\Integration;
use Piwik\Access;
use Piwik\Piwik;
use Piwik\Plugins\SitesManager\API;
use Piwik\Translate;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group Core
*/
class PiwikTest extends IntegrationTestCase
{
/**
* Dataprovider for testIsNumericValid
*/
public function getValidNumeric()
{
$valid = array(
-1, 0, 1, 1.5, -1.5, 21111, 89898, 99999999999, -4565656,
(float)-1, (float)0, (float)1, (float)1.5, (float)-1.5, (float)21111, (float)89898, (float)99999999999, (float)-4565656,
(int)-1, (int)0, (int)1, (int)1.5, (int)-1.5, (int)21111, (int)89898, (int)99999999999, (int)-4565656,
'-1', '0', '1', '1.5', '-1.5', '21111', '89898', '99999999999', '-4565656',
'1e3', '0x123', "-1e-2",
);
foreach ($valid as $key => $value) {
$valid[$key] = array($value);
}
return $valid;
}
/**
* @dataProvider getValidNumeric
*/
public function testIsNumericValid($toTest)
{
$this->assertTrue(is_numeric($toTest), $toTest . " not valid but should!");
}
/**
* Dataprovider for testIsNumericNotValid
*/
public function getInvalidNumeric()
{
$notValid = array(
'-1.0.0', '1,2', '--1', '-.', '- 1', '1-',
);
foreach ($notValid as $key => $value) {
$notValid[$key] = array($value);
}
return $notValid;
}
/**
* @dataProvider getInvalidNumeric
*/
public function testIsNumericNotValid($toTest)
{
$this->assertFalse(is_numeric($toTest), $toTest . " valid but shouldn't!");
}
public function testSecureDiv()
{
$this->assertSame(3, Piwik::secureDiv(9, 3));
$this->assertSame(0, Piwik::secureDiv(9, 0));
$this->assertSame(10, Piwik::secureDiv(10, 1));
$this->assertSame(10.0, Piwik::secureDiv(10.0, 1.0));
$this->assertSame(5.5, Piwik::secureDiv(11.0, 2));
$this->assertSame(0, Piwik::secureDiv(11.0, 'a'));
}
/**
* Dataprovider for testCheckValidLoginString
*/
public function getInvalidLoginStringData()
{
$notValid = array(
'',
' ',
'a',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'alpha/beta',
'alpha:beta',
'alpha;beta',
'alpha<beta',
'alpha=beta',
'alpha>beta',
'alpha?beta',
);
foreach ($notValid as $key => $value) {
$notValid[$key] = array($value);
}
return $notValid;
}
/**
* @dataProvider getInvalidLoginStringData
* @expectedException \Exception
*/
public function testCheckInvalidLoginString($toTest)
{
Piwik::checkValidLoginString($toTest);
}
/**
* Dataprovider for testCheckValidLoginString
*/
public function getValidLoginStringData()
{
$valid = array(
'aa',
'aaa',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'shoot_puck@the-goal.com',
);
foreach ($valid as $key => $value) {
$valid[$key] = array($value);
}
return $valid;
}
/**
* @dataProvider getValidLoginStringData
*/
public function testCheckValidLoginString($toTest)
{
$this->assertNull(Piwik::checkValidLoginString($toTest));
}
/**
* Data provider for testIsAssociativeArray.
*/
public function getIsAssociativeArrayTestCases()
{
return array(
array(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 4 => 'e', 5 => 'f'), false),
array(array(-1 => 'a', 0 => 'a', 1 => 'a', 2 => 'a', 3 => 'a'), true),
array(array(4 => 'a', 5 => 'a', 6 => 'a', 7 => 'a', 8 => 'a'), true),
array(array(0 => 'a', 2 => 'a', 3 => 'a', 4 => 'a', 5 => 'a'), true),
array(array('abc' => 'a', 0 => 'b', 'sdfds' => 'd'), true),
array(array('abc' => 'def'), true)
);
}
/**
* @dataProvider getIsAssociativeArrayTestCases
*/
public function testIsAssociativeArray($array, $expected)
{
$this->assertEquals($expected, Piwik::isAssociativeArray($array));
}
}
|