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

WidgetContainerConfigTest.php « Widget « Unit « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7a2d3fedaec1c4903e698f9f8912fd31ac9a9ce6 (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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?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;
use Piwik\Widget\WidgetContainerConfig;

/**
 * @group Widget
 * @group WidgetContainerConfig
 * @group WidgetContainerConfigTest
 */
class WidgetContainerConfigTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var WidgetContainerConfig
     */
    private $config;

    private $id = 'MyTestContainer';

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

    public function test_id_set_get()
    {
        $this->config->setId('testId');

        $this->assertSame('testId', $this->config->getId());
    }

    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_layout_set_get()
    {
        $this->config->setLayout('ByDimension');

        $this->assertSame('ByDimension', $this->config->getLayout());
    }

    public function test_getLayout_shouldBeEmptyStringByDefault()
    {
        $this->assertSame('', $this->config->getLayout());
    }

    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_shouldBeTheModuleToRenderItByDefault()
    {
        $this->assertSame('CoreHome', $this->config->getModule());
    }

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

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

    public function test_getAction_shouldBeTheActionToRenderItByDefault()
    {
        $this->assertSame('renderWidgetContainer', $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->assertSame(array(
            'module' => 'CoreHome',
            'action' => 'renderWidgetContainer',
            'containerId' => $this->id
        ), $this->config->getParameters());
    }

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

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

    public function test_addParameters_ShouldAddMoreParams()
    {
        $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' => 'renderWidgetContainer',
            'test' => '3',
            'forceView' => '1',
            'containerId' => $this->id
        ), $this->config->getParameters());
    }

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

        $this->assertSame(array(
            'module' => 'CoreHome',
            'action' => 'renderWidgetContainer',
            'forceView' => '1',
            'containerId' => $this->id
        ), $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_shouldNotBeWidgetizable_ByDefault()
    {
        $this->assertFalse($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_shouldIncludeContainerId()
    {
        $this->assertSame('widgetMyTestContainer', $this->config->getUniqueId());
    }

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

    public function test_getWidgetConfigs_shouldBeEmptyByDefault()
    {
        $this->assertSame(array(), $this->config->getWidgetConfigs());
    }

    public function test_widgetConfigs_shouldBeEmptyByDefault()
    {
        $this->config->addWidgetConfig($widget1 = $this->createWidgetConfig('widget1'));
        $this->config->addWidgetConfig($widget2 = $this->createWidgetConfig('widget2'));
        $this->config->addWidgetConfig($widget3 = $this->createWidgetConfig('widget3'));
        $this->config->addWidgetConfig($widget4 = new WidgetContainerConfig()); // should be possible to add container to a container
        $this->assertSame(array(
            $widget1,
            $widget2,
            $widget3,
            $widget4
        ), $this->config->getWidgetConfigs());
    }

    private function createWidgetConfig($widgetName)
    {
        $config = new WidgetConfig();
        $config->setName($widgetName);

        return $config;
    }
}