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

WidgetConfigTest.php « Widget « Unit « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de6917ef0e39e239daf98192bf6c1834306e0be4 (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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?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\Unit\Widget;

use Piwik\Widget\WidgetConfig;

/**
 * @group Widget
 * @group WidgetConfig
 * @group WidgetConfigTest
 */
class WidgetConfigTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var WidgetConfig
     */
    private $config;

    public function setUp()
    {
        parent::setUp();
        $this->config = new WidgetConfig();
    }

    public function test_name_set_get()
    {
        $this->config->setName('testName');

        $this->assertSame('testName', $this->config->getName());
    }

    public function test_getName_shouldBeEmptyStringByDefault()
    {
        $this->assertSame('', $this->config->getName());
    }

    public function test_categoryId_set_get()
    {
        $this->config->setCategoryId('testCat');

        $this->assertSame('testCat', $this->config->getCategoryId());
    }

    public function test_getCategoryId_shouldBeEmptyStringByDefault()
    {
        $this->assertSame('', $this->config->getCategoryId());
    }

    public function test_subcategoryId_set_get()
    {
        $this->config->setSubcategoryId('testsubcat');

        $this->assertSame('testsubcat', $this->config->getSubcategoryId());
    }

    public function test_getSubcategoryId_shouldBeEmptyStringByDefault()
    {
        $this->assertSame('', $this->config->getSubcategoryId());
    }

    public function test_module_set_get()
    {
        $this->config->setModule('CoreHome');

        $this->assertSame('CoreHome', $this->config->getModule());
    }

    public function test_getModule_shouldBeEmptyStringByDefault()
    {
        $this->assertSame('', $this->config->getModule());
    }

    public function test_action_set_get()
    {
        $this->config->setAction('get');

        $this->assertSame('get', $this->config->getAction());
    }

    public function test_getAction_shouldBeEmptyStringByDefault()
    {
        $this->assertSame('', $this->config->getAction());
    }

    public function test_order_set_get()
    {
        $this->config->setOrder(99);
        $this->assertSame(99, $this->config->getOrder());

        $this->config->setOrder('98');
        $this->assertSame(98, $this->config->getOrder());
    }

    public function test_getOrder_shouldReturnADefaultValue()
    {
        $this->assertSame(99, $this->config->getOrder());
    }

    public function test_setMiddlewareParameters_set_get()
    {
        $this->config->setMiddlewareParameters(array(
            'module' => 'Goals',
            'action' => 'hasConversions'
        ));

        $this->assertSame(array(
            'module' => 'Goals',
            'action' => 'hasConversions'
        ), $this->config->getMiddlewareParameters());
    }

    public function test_getMiddlewareParameters_shouldReturnADefaultValue()
    {
        $this->assertSame(array(), $this->config->getMiddlewareParameters());
    }

    public function test_getParameters_ShouldAddModuleAndAction()
    {
        $this->setModuleAndAction();
        $this->assertSame(array('module' => 'CoreHome', 'action' => 'renderMe'), $this->config->getParameters());
    }

    public function test_getParameters_ShouldNotBePossibleToOverwriteModuleAndAction()
    {
        $this->setModuleAndAction();
        $this->config->setParameters(array('module' => 'Actions', 'action' => 'index'));

        $this->assertSame(array('module' => 'CoreHome', 'action' => 'renderMe'), $this->config->getParameters());
    }

    public function test_addParameters_ShouldAddMoreParams()
    {
        $this->setModuleAndAction();
        $this->config->addParameters(array('test' => '1')); // should be removed by setParameters
        $this->config->addParameters(array('forceView' => '1'));
        $this->config->addParameters(array('test' => '3'));

        $this->assertSame(array('module' => 'CoreHome', 'action' => 'renderMe', 'test' => '3', 'forceView' => '1'), $this->config->getParameters());
    }

    public function test_setParameters_ShouldOverwriteAnyExistingParameters()
    {
        $this->setModuleAndAction();
        $this->config->addParameters(array('test' => '1')); // should be removed by setParameters
        $this->config->setParameters(array('forceView' => '1'));

        $this->assertSame(array('module' => 'CoreHome', 'action' => 'renderMe', 'forceView' => '1'), $this->config->getParameters());
    }

    public function test_shouldBeEnabledByDefault()
    {
        $this->assertTrue($this->config->isEnabled());
    }

    public function test_enable_disable()
    {
        $this->config->disable();
        $this->assertFalse($this->config->isEnabled());
        $this->config->enable();
        $this->assertTrue($this->config->isEnabled());
    }

    public function test_setIsEnabled()
    {
        $this->config->setIsEnabled(false);
        $this->assertFalse($this->config->isEnabled());
        $this->config->setIsEnabled(true);
        $this->assertTrue($this->config->isEnabled());
    }

    public function test_checkIsEnabled_shouldNotThrowException_IfEnabled()
    {
        $this->config->enable();
        $this->config->checkIsEnabled();
    }

    /**
     * @expectedException \Exception
     */
    public function test_checkIsEnabled_shouldThrowException_IfDisabled()
    {
        $this->config->disable();
        $this->config->checkIsEnabled();
    }

    public function test_shouldBeWidgetizable_ByDefault()
    {
        $this->assertTrue($this->config->isWidgetizeable());
    }

    public function test_widgetizeable()
    {
        $this->config->setIsNotWidgetizable();
        $this->assertFalse($this->config->isWidgetizeable());
        $this->config->setIsWidgetizable();
        $this->assertTrue($this->config->isWidgetizeable());
    }

    public function test_getUniqueId_withNoParameters()
    {
        $this->setModuleAndAction();
        $this->assertSame('widgetCoreHomerenderMe', $this->config->getUniqueId());
    }

    public function test_getUniqueId_withParameters()
    {
        $this->setModuleAndAction();
        $this->config->addParameters(array('viewDataTable' => 'table', 'forceView' => '1', 'mtest' => array('test')));
        $this->assertSame('widgetCoreHomerenderMeviewDataTabletableforceView1mtestArray', $this->config->getUniqueId());
    }

    private function setModuleAndAction()
    {
        $this->config->setModule('CoreHome');
        $this->config->setAction('renderMe');
    }

}