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

PMA_Message_test.php « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e247c5f7685a2cb9f09188e66dff970fe8944c65 (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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Test for PMA_Message class
 *
 * @author Michal Biniek <michal@bystrzyca.pl>
 * @version $Id$
 */

/**
 * Tests core.
 */
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Extensions/OutputTestCase.php';

/**
 * Include to test.
 */
require_once './libraries/Message.class.php';

/**
 * Test class PMA_Message.
 *
 * @package phpMyAdmin-test
 */
class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
{
    /**
     * @var    PMA_Message
     * @access protected
     */
    protected $object;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    protected function setUp()
    {
        $this->object = new PMA_Message;
    }

    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     */
    protected function tearDown()
    {
    }

    /**
     * to String casting test
     */
    public function test__toString()
    {
        $this->object->setMessage('test<&>', true);
        $this->assertEquals('test&lt;&amp;&gt;', (string)$this->object);
    }

    /**
     * test success method
     */
    public function testSuccess()
    {
        $this->object = new PMA_Message('test<&>', PMA_Message::SUCCESS);
        $this->assertEquals($this->object, PMA_Message::success('test<&>'));
        $this->assertEquals('strSuccess', PMA_Message::success()->getString());
    }

    /**
     * test error method
     */
    public function testError()
    {
        $this->object = new PMA_Message('test<&>', PMA_Message::ERROR);
        $this->assertEquals($this->object, PMA_Message::error('test<&>'));
        $this->assertEquals('strError', PMA_Message::error()->getString());
    }

    /**
     * test warning method
     */
    public function testWarning()
    {
        $this->object = new PMA_Message('test<&>', PMA_Message::WARNING);
        $this->assertEquals($this->object, PMA_Message::warning('test<&>'));
    }

    /**
     * test notice method
     */
    public function testNotice()
    {
        $this->object = new PMA_Message('test<&>', PMA_Message::NOTICE);
        $this->assertEquals($this->object, PMA_Message::notice('test<&>'));
    }

    /**
     * test rawError method
     */
    public function testRawError()
    {
        $this->object = new PMA_Message('', PMA_Message::ERROR);
        $this->object->setMessage('test<&>');

        $this->assertEquals($this->object, PMA_Message::rawError('test<&>'));
    }

    /**
     * test rawWarning method
     */
    public function testRawWarning() 
    {
        $this->object = new PMA_Message('', PMA_Message::WARNING);
        $this->object->setMessage('test<&>');

        $this->assertEquals($this->object, PMA_Message::rawWarning('test<&>'));
    }

    /**
     * test rawNotice method
     */
    public function testRawNotice() 
    {
        $this->object = new PMA_Message('', PMA_Message::NOTICE);
        $this->object->setMessage('test<&>');

        $this->assertEquals($this->object, PMA_Message::rawNotice('test<&>'));
    }

    /**
     * test rawSuccess method
     */
    public function testRawSuccess() 
    {
        $this->object = new PMA_Message('', PMA_Message::SUCCESS);
        $this->object->setMessage('test<&>');

        $this->assertEquals($this->object, PMA_Message::rawSuccess('test<&>'));
    }

    /**
     * testing isSuccess method
     */
    public function testIsSuccess() 
    {
        $this->assertFalse($this->object->isSuccess());
        $this->assertTrue($this->object->isSuccess(true));
    }

    /**
     * testing isNotice method
     */
    public function testIsNotice() 
    {
        $this->assertTrue($this->object->isNotice());
        $this->object->isWarning(true);
        $this->assertFalse($this->object->isNotice());
        $this->assertTrue($this->object->isNotice(true));
    }

    /**
     * testing isWarning method
     */
    public function testIsWarning() 
    {
        $this->assertFalse($this->object->isWarning());
        $this->assertTrue($this->object->isWarning(true));
    }

    /**
     * testing isError method
     */
    public function testIsError() 
    {
        $this->assertFalse($this->object->isError());
        $this->assertTrue($this->object->isError(true));
    }

    /**
     * testign setter of message
     */
    public function testSetMessage() 
    {
        $this->object->setMessage('test&<>', false);
        $this->assertEquals('test&<>', $this->object->getMessage());
        $this->object->setMessage('test&<>', true);
        $this->assertEquals('test&amp;&lt;&gt;', $this->object->getMessage());
    }

    /**
     * testing setter of string
     */
    public function testSetString() 
    {
        $this->object->setString('test&<>', false);
        $this->assertEquals('test&<>', $this->object->getString());
        $this->object->setString('test&<>', true);
        $this->assertEquals('test&amp;&lt;&gt;', $this->object->getString());
    }

    /**
     * testing add param method
     */
    public function testAddParam() 
    {
        $this->object->addParam(PMA_Message::notice('test'));
        $this->assertEquals(array(PMA_Message::notice('test')), $this->object->getParams());
        $this->object->addParam('test', true);
        $this->assertEquals(array(PMA_Message::notice('test'), 'test'), $this->object->getParams());
        $this->object->addParam('test', false);
        $this->assertEquals(array(PMA_Message::notice('test'), 'test', PMA_Message::notice('test')), $this->object->getParams());
    }

    /**
     * testing add string method
     */
    public function testAddString() 
    {
        $this->object->addString('test', '*');
        $this->assertEquals(array('*', PMA_Message::notice('test')), $this->object->getAddedMessages());
        $this->object->addString('test', '');
        $this->assertEquals(array('*', PMA_Message::notice('test'), '', PMA_Message::notice('test')), $this->object->getAddedMessages());
    }

    /**
     * testing add messages method
     */
    public function testAddMessages() 
    {
        $this->object->addMessages(array('test', PMA_Message::rawWarning('test')), '&');
        $this->assertEquals(array('&', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
    }

    /**
     * testing add message method
     */
    public function testAddMessage() 
    {
        $this->object->addMessage('test', '');
        $this->assertEquals(array(PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
        $this->object->addMessage('test');
        $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
        $this->object->addMessage(PMA_Message::rawWarning('test'), '&');
        $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
    }

    /**
     * testing setter of params
     */
    public function testSetParams() 
    {
        $this->object->setParams('test&<>');
        $this->assertEquals('test&<>', $this->object->getParams());
        $this->object->setParams('test&<>', true);
        $this->assertEquals('test&amp;&lt;&gt;', $this->object->getParams());
    }

    /**
     * testing sanitize method
     */
    public function testSanitize() 
    {
        $this->object->setString('test&string<>', false);
        $this->assertEquals('test&amp;string&lt;&gt;', PMA_Message::sanitize($this->object));
        $this->assertEquals(array('test&amp;string&lt;&gt;', 'test&amp;string&lt;&gt;'), PMA_Message::sanitize(array($this->object, $this->object)));
    }

    public function decodeBBDataProvider() 
    {
        return array(
            array('[i]test[/i][i]aa[i/][em]test[/em]', '<em>test</em><em>aa[i/]<em>test</em>'),
            array('[b]test[/b][strong]test[/strong]', '<strong>test</strong><strong>test</strong>'),
            array('[tt]test[/tt][code]test[/code]', '<code>test</code><code>test</code>'),
            array('[kbd]test[/kbd][br][sup]test[/sup]', '<kbd>test</kbd><br /><sup>test</sup>')
        );
    }

    /**
     * testing decodeBB method
     * @dataProvider decodeBBDataProvider
     */

    public function testDecodeBB($actual, $expected) 
    {
        $this->assertEquals($expected, PMA_Message::decodeBB($actual));   
    }

    /**
     * testing format method
     */
    public function testFormat() 
    {
        $this->assertEquals('test string', PMA_Message::format('test string'));
        $this->assertEquals('test string', PMA_Message::format('test string', 'a'));
        $this->assertEquals('test string', PMA_Message::format('test string', array()));
        $this->assertEquals('test string', PMA_Message::format('%s string', array('test')));
        
    }

    /**
     * testing getHash method
     */
    public function testGetHash() 
    {
        $this->object->setString('<&>test', false);
        $this->object->setMessage('<&>test', false);
        $this->assertEquals(md5(PMA_Message::NOTICE . '<&>test<&>test'), $this->object->getHash());
    }

    /**
     * getMessage test - with empty message and with non-empty string - not key in globals
     * additional params are defined
     */
    public function testGetMessageWithoutMessageWithStringWithParams() 
    {
        $this->object->setMessage('');
        $this->object->setString('test string %s %s');
        $this->object->addParam('test param 1');
        $this->object->addParam('test param 2');
        $this->assertEquals('test string test param 1 test param 2', $this->object->getMessage());
    }

    /**
     * getMessage test - with empty message and with empty string
     */
    public function testGetMessageWithoutMessageWithEmptyString() 
    {
        $this->object->setMessage('');
        $this->object->setString('');
        $this->assertEquals('', $this->object->getMessage());
    }

    /**
     * getMessage test - with empty message and with string, which is key to GLOBALS
     * additional messages are defined
     */
    public function testGetMessageWithoutMessageWithGlobalStringWithAddMessages() 
    {
        $GLOBALS['key'] = 'test message';
        $this->object->setMessage('');
        $this->object->setString('key');
        $this->object->addMessage('test message 2', ' - ');
        $this->object->addMessage('test message 3', '&');
        $this->assertEquals('test message - test message 2&test message 3', $this->object->getMessage());
        unset($GLOBALS['key']);
    }

    /**
     * getMessage test - message is defined
     * message with BBCode defined
     */
    public function testGetMessageWithMessageWithBBCode() 
    {
        $this->object->setMessage('[kbd]test[/kbd] [a@./Documentation.html#cfg_Example@_blank]test[/a]');
        $this->assertEquals('<kbd>test</kbd> <a href="./Documentation.html#cfg_Example" target="_blank">test</a>', $this->object->getMessage());
    }

    /**
     * getLevel test
     */
    public function testGetLevel() 
    {
        $this->assertEquals('notice', $this->object->getLevel());
        $this->object->setNumber(PMA_Message::SUCCESS);
        $this->assertEquals('success', $this->object->getLevel());
        $this->object->setNumber(PMA_Message::ERROR);
        $this->assertEquals('error', $this->object->getLevel());
        $this->object->setNumber(PMA_Message::WARNING);
        $this->assertEquals('warning', $this->object->getLevel());
    }

    /**
     * testing display method (output string and _is_displayed varible)
     */
    public function testDisplay() 
    {
        $this->assertFalse($this->object->isDisplayed());
        $this->object->setMessage('Test Message');

        $this->expectOutputString('<div class="notice">Test Message</div>');
        $this->object->display();

        $this->assertTrue($this->object->isDisplayed());
    }

    /**
     * getDisplay test
     */
    public function testGetDisplay() 
    {
        $this->object->setMessage('Test Message');
        $this->assertEquals('<div class="notice">Test Message</div>', $this->object->getDisplay());
    }

    /**
     * isDisplayed test
     */
    public function testIsDisplayed() 
    {
        $this->assertFalse($this->object->isDisplayed(false));
        $this->assertTrue($this->object->isDisplayed(true));
        $this->assertTrue($this->object->isDisplayed(false));
    }
}
?>