Translation update done using Pootle.
[phpmyadmin-themes.git] / test / PMA_Message_test.php
blobe3a44928c0ab3f79bb9235aa1014eea9fbc5d147
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for PMA_Message class
6 */
8 /**
9 * Tests core.
11 require_once 'PHPUnit/Framework.php';
12 require_once 'PHPUnit/Extensions/OutputTestCase.php';
14 /**
15 * Include to test.
17 require_once './libraries/Message.class.php';
19 /**
20 * Test class PMA_Message.
22 * @package phpMyAdmin-test
24 class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
26 /**
27 * @var PMA_Message
28 * @access protected
30 protected $object;
32 /**
33 * Sets up the fixture, for example, opens a network connection.
34 * This method is called before a test is executed.
36 * @access protected
38 protected function setUp()
40 $this->object = new PMA_Message;
43 /**
44 * Tears down the fixture, for example, closes a network connection.
45 * This method is called after a test is executed.
47 * @access protected
49 protected function tearDown()
53 /**
54 * to String casting test
56 public function test__toString()
58 $this->object->setMessage('test<&>', true);
59 $this->assertEquals('test&lt;&amp;&gt;', (string)$this->object);
62 /**
63 * test success method
65 public function testSuccess()
67 $this->object = new PMA_Message('test<&>', PMA_Message::SUCCESS);
68 $this->assertEquals($this->object, PMA_Message::success('test<&>'));
69 $this->assertEquals('Your SQL query has been executed successfully', PMA_Message::success()->getString());
72 /**
73 * test error method
75 public function testError()
77 $this->object = new PMA_Message('test<&>', PMA_Message::ERROR);
78 $this->assertEquals($this->object, PMA_Message::error('test<&>'));
79 $this->assertEquals('Error', PMA_Message::error()->getString());
82 /**
83 * test warning method
85 public function testWarning()
87 $this->object = new PMA_Message('test<&>', PMA_Message::WARNING);
88 $this->assertEquals($this->object, PMA_Message::warning('test<&>'));
91 /**
92 * test notice method
94 public function testNotice()
96 $this->object = new PMA_Message('test<&>', PMA_Message::NOTICE);
97 $this->assertEquals($this->object, PMA_Message::notice('test<&>'));
101 * test rawError method
103 public function testRawError()
105 $this->object = new PMA_Message('', PMA_Message::ERROR);
106 $this->object->setMessage('test<&>');
108 $this->assertEquals($this->object, PMA_Message::rawError('test<&>'));
112 * test rawWarning method
114 public function testRawWarning()
116 $this->object = new PMA_Message('', PMA_Message::WARNING);
117 $this->object->setMessage('test<&>');
119 $this->assertEquals($this->object, PMA_Message::rawWarning('test<&>'));
123 * test rawNotice method
125 public function testRawNotice()
127 $this->object = new PMA_Message('', PMA_Message::NOTICE);
128 $this->object->setMessage('test<&>');
130 $this->assertEquals($this->object, PMA_Message::rawNotice('test<&>'));
134 * test rawSuccess method
136 public function testRawSuccess()
138 $this->object = new PMA_Message('', PMA_Message::SUCCESS);
139 $this->object->setMessage('test<&>');
141 $this->assertEquals($this->object, PMA_Message::rawSuccess('test<&>'));
145 * testing isSuccess method
147 public function testIsSuccess()
149 $this->assertFalse($this->object->isSuccess());
150 $this->assertTrue($this->object->isSuccess(true));
154 * testing isNotice method
156 public function testIsNotice()
158 $this->assertTrue($this->object->isNotice());
159 $this->object->isWarning(true);
160 $this->assertFalse($this->object->isNotice());
161 $this->assertTrue($this->object->isNotice(true));
165 * testing isWarning method
167 public function testIsWarning()
169 $this->assertFalse($this->object->isWarning());
170 $this->assertTrue($this->object->isWarning(true));
174 * testing isError method
176 public function testIsError()
178 $this->assertFalse($this->object->isError());
179 $this->assertTrue($this->object->isError(true));
183 * testign setter of message
185 public function testSetMessage()
187 $this->object->setMessage('test&<>', false);
188 $this->assertEquals('test&<>', $this->object->getMessage());
189 $this->object->setMessage('test&<>', true);
190 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getMessage());
194 * testing setter of string
196 public function testSetString()
198 $this->object->setString('test&<>', false);
199 $this->assertEquals('test&<>', $this->object->getString());
200 $this->object->setString('test&<>', true);
201 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getString());
205 * testing add param method
207 public function testAddParam()
209 $this->object->addParam(PMA_Message::notice('test'));
210 $this->assertEquals(array(PMA_Message::notice('test')), $this->object->getParams());
211 $this->object->addParam('test', true);
212 $this->assertEquals(array(PMA_Message::notice('test'), 'test'), $this->object->getParams());
213 $this->object->addParam('test', false);
214 $this->assertEquals(array(PMA_Message::notice('test'), 'test', PMA_Message::notice('test')), $this->object->getParams());
218 * testing add string method
220 public function testAddString()
222 $this->object->addString('test', '*');
223 $this->assertEquals(array('*', PMA_Message::notice('test')), $this->object->getAddedMessages());
224 $this->object->addString('test', '');
225 $this->assertEquals(array('*', PMA_Message::notice('test'), '', PMA_Message::notice('test')), $this->object->getAddedMessages());
229 * testing add messages method
231 public function testAddMessages()
233 $this->object->addMessages(array('test', PMA_Message::rawWarning('test')), '&');
234 $this->assertEquals(array('&', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
238 * testing add message method
240 public function testAddMessage()
242 $this->object->addMessage('test', '');
243 $this->assertEquals(array(PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
244 $this->object->addMessage('test');
245 $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
246 $this->object->addMessage(PMA_Message::rawWarning('test'), '&');
247 $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
251 * testing setter of params
253 public function testSetParams()
255 $this->object->setParams('test&<>');
256 $this->assertEquals('test&<>', $this->object->getParams());
257 $this->object->setParams('test&<>', true);
258 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getParams());
262 * testing sanitize method
264 public function testSanitize()
266 $this->object->setString('test&string<>', false);
267 $this->assertEquals('test&amp;string&lt;&gt;', PMA_Message::sanitize($this->object));
268 $this->assertEquals(array('test&amp;string&lt;&gt;', 'test&amp;string&lt;&gt;'), PMA_Message::sanitize(array($this->object, $this->object)));
271 public function decodeBBDataProvider()
273 return array(
274 array('[i]test[/i][i]aa[i/][em]test[/em]', '<em>test</em><em>aa[i/]<em>test</em>'),
275 array('[b]test[/b][strong]test[/strong]', '<strong>test</strong><strong>test</strong>'),
276 array('[tt]test[/tt][code]test[/code]', '<code>test</code><code>test</code>'),
277 array('[kbd]test[/kbd][br][sup]test[/sup]', '<kbd>test</kbd><br /><sup>test</sup>')
282 * testing decodeBB method
283 * @dataProvider decodeBBDataProvider
286 public function testDecodeBB($actual, $expected)
288 $this->assertEquals($expected, PMA_Message::decodeBB($actual));
292 * testing format method
294 public function testFormat()
296 $this->assertEquals('test string', PMA_Message::format('test string'));
297 $this->assertEquals('test string', PMA_Message::format('test string', 'a'));
298 $this->assertEquals('test string', PMA_Message::format('test string', array()));
299 $this->assertEquals('test string', PMA_Message::format('%s string', array('test')));
304 * testing getHash method
306 public function testGetHash()
308 $this->object->setString('<&>test', false);
309 $this->object->setMessage('<&>test', false);
310 $this->assertEquals(md5(PMA_Message::NOTICE . '<&>test<&>test'), $this->object->getHash());
314 * getMessage test - with empty message and with non-empty string - not key in globals
315 * additional params are defined
317 public function testGetMessageWithoutMessageWithStringWithParams()
319 $this->object->setMessage('');
320 $this->object->setString('test string %s %s');
321 $this->object->addParam('test param 1');
322 $this->object->addParam('test param 2');
323 $this->assertEquals('test string test param 1 test param 2', $this->object->getMessage());
327 * getMessage test - with empty message and with empty string
329 public function testGetMessageWithoutMessageWithEmptyString()
331 $this->object->setMessage('');
332 $this->object->setString('');
333 $this->assertEquals('', $this->object->getMessage());
337 * getMessage test - with empty message and with string, which is key to GLOBALS
338 * additional messages are defined
340 public function testGetMessageWithoutMessageWithGlobalStringWithAddMessages()
342 $GLOBALS['key'] = 'test message';
343 $this->object->setMessage('');
344 $this->object->setString('key');
345 $this->object->addMessage('test message 2', ' - ');
346 $this->object->addMessage('test message 3', '&');
347 $this->assertEquals('test message - test message 2&test message 3', $this->object->getMessage());
348 unset($GLOBALS['key']);
352 * getMessage test - message is defined
353 * message with BBCode defined
355 public function testGetMessageWithMessageWithBBCode()
357 $this->object->setMessage('[kbd]test[/kbd] [a@./Documentation.html#cfg_Example@_blank]test[/a]');
358 $this->assertEquals('<kbd>test</kbd> <a href="./Documentation.html#cfg_Example" target="_blank">test</a>', $this->object->getMessage());
362 * getLevel test
364 public function testGetLevel()
366 $this->assertEquals('notice', $this->object->getLevel());
367 $this->object->setNumber(PMA_Message::SUCCESS);
368 $this->assertEquals('success', $this->object->getLevel());
369 $this->object->setNumber(PMA_Message::ERROR);
370 $this->assertEquals('error', $this->object->getLevel());
371 $this->object->setNumber(PMA_Message::WARNING);
372 $this->assertEquals('warning', $this->object->getLevel());
376 * testing display method (output string and _is_displayed varible)
378 public function testDisplay()
380 $this->assertFalse($this->object->isDisplayed());
381 $this->object->setMessage('Test Message');
383 $this->expectOutputString('<div class="notice">Test Message</div>');
384 $this->object->display();
386 $this->assertTrue($this->object->isDisplayed());
390 * getDisplay test
392 public function testGetDisplay()
394 $this->object->setMessage('Test Message');
395 $this->assertEquals('<div class="notice">Test Message</div>', $this->object->getDisplay());
399 * isDisplayed test
401 public function testIsDisplayed()
403 $this->assertFalse($this->object->isDisplayed(false));
404 $this->assertTrue($this->object->isDisplayed(true));
405 $this->assertTrue($this->object->isDisplayed(false));