Remove misleading comment on the "Rename database" interface
[phpmyadmin/ammaryasirr.git] / test / PMA_Message_test.php
blobed7694e3d948785342aad154509dc6c640e557b6
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 notice method
85 public function testNotice()
87 $this->object = new PMA_Message('test<&>', PMA_Message::NOTICE);
88 $this->assertEquals($this->object, PMA_Message::notice('test<&>'));
91 /**
92 * test rawError method
94 public function testRawError()
96 $this->object = new PMA_Message('', PMA_Message::ERROR);
97 $this->object->setMessage('test<&>');
99 $this->assertEquals($this->object, PMA_Message::rawError('test<&>'));
103 * test rawWarning method
105 public function testRawWarning()
107 $this->object = new PMA_Message('', PMA_Message::WARNING);
108 $this->object->setMessage('test<&>');
110 $this->assertEquals($this->object, PMA_Message::rawWarning('test<&>'));
114 * test rawNotice method
116 public function testRawNotice()
118 $this->object = new PMA_Message('', PMA_Message::NOTICE);
119 $this->object->setMessage('test<&>');
121 $this->assertEquals($this->object, PMA_Message::rawNotice('test<&>'));
125 * test rawSuccess method
127 public function testRawSuccess()
129 $this->object = new PMA_Message('', PMA_Message::SUCCESS);
130 $this->object->setMessage('test<&>');
132 $this->assertEquals($this->object, PMA_Message::rawSuccess('test<&>'));
136 * testing isSuccess method
138 public function testIsSuccess()
140 $this->assertFalse($this->object->isSuccess());
141 $this->assertTrue($this->object->isSuccess(true));
145 * testing isNotice method
147 public function testIsNotice()
149 $this->assertTrue($this->object->isNotice());
150 $this->object->isError(true);
151 $this->assertFalse($this->object->isNotice());
152 $this->assertTrue($this->object->isNotice(true));
156 * testing isError method
158 public function testIsError()
160 $this->assertFalse($this->object->isError());
161 $this->assertTrue($this->object->isError(true));
165 * testign setter of message
167 public function testSetMessage()
169 $this->object->setMessage('test&<>', false);
170 $this->assertEquals('test&<>', $this->object->getMessage());
171 $this->object->setMessage('test&<>', true);
172 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getMessage());
176 * testing setter of string
178 public function testSetString()
180 $this->object->setString('test&<>', false);
181 $this->assertEquals('test&<>', $this->object->getString());
182 $this->object->setString('test&<>', true);
183 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getString());
187 * testing add param method
189 public function testAddParam()
191 $this->object->addParam(PMA_Message::notice('test'));
192 $this->assertEquals(array(PMA_Message::notice('test')), $this->object->getParams());
193 $this->object->addParam('test', true);
194 $this->assertEquals(array(PMA_Message::notice('test'), 'test'), $this->object->getParams());
195 $this->object->addParam('test', false);
196 $this->assertEquals(array(PMA_Message::notice('test'), 'test', PMA_Message::notice('test')), $this->object->getParams());
200 * testing add string method
202 public function testAddString()
204 $this->object->addString('test', '*');
205 $this->assertEquals(array('*', PMA_Message::notice('test')), $this->object->getAddedMessages());
206 $this->object->addString('test', '');
207 $this->assertEquals(array('*', PMA_Message::notice('test'), '', PMA_Message::notice('test')), $this->object->getAddedMessages());
211 * testing add messages method
213 public function testAddMessages()
215 $this->object->addMessages(array('test', PMA_Message::rawWarning('test')), '&');
216 $this->assertEquals(array('&', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
220 * testing add message method
222 public function testAddMessage()
224 $this->object->addMessage('test', '');
225 $this->assertEquals(array(PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
226 $this->object->addMessage('test');
227 $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
228 $this->object->addMessage(PMA_Message::rawWarning('test'), '&');
229 $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
233 * testing setter of params
235 public function testSetParams()
237 $this->object->setParams('test&<>');
238 $this->assertEquals('test&<>', $this->object->getParams());
239 $this->object->setParams('test&<>', true);
240 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getParams());
244 * testing sanitize method
246 public function testSanitize()
248 $this->object->setString('test&string<>', false);
249 $this->assertEquals('test&amp;string&lt;&gt;', PMA_Message::sanitize($this->object));
250 $this->assertEquals(array('test&amp;string&lt;&gt;', 'test&amp;string&lt;&gt;'), PMA_Message::sanitize(array($this->object, $this->object)));
253 public function decodeBBDataProvider()
255 return array(
256 array('[i]test[/i][i]aa[i/][em]test[/em]', '<em>test</em><em>aa[i/]<em>test</em>'),
257 array('[b]test[/b][strong]test[/strong]', '<strong>test</strong><strong>test</strong>'),
258 array('[tt]test[/tt][code]test[/code]', '<code>test</code><code>test</code>'),
259 array('[kbd]test[/kbd][br][sup]test[/sup]', '<kbd>test</kbd><br /><sup>test</sup>')
264 * testing decodeBB method
265 * @dataProvider decodeBBDataProvider
268 public function testDecodeBB($actual, $expected)
270 $this->assertEquals($expected, PMA_Message::decodeBB($actual));
274 * testing format method
276 public function testFormat()
278 $this->assertEquals('test string', PMA_Message::format('test string'));
279 $this->assertEquals('test string', PMA_Message::format('test string', 'a'));
280 $this->assertEquals('test string', PMA_Message::format('test string', array()));
281 $this->assertEquals('test string', PMA_Message::format('%s string', array('test')));
286 * testing getHash method
288 public function testGetHash()
290 $this->object->setString('<&>test', false);
291 $this->object->setMessage('<&>test', false);
292 $this->assertEquals(md5(PMA_Message::NOTICE . '<&>test<&>test'), $this->object->getHash());
296 * getMessage test - with empty message and with non-empty string - not key in globals
297 * additional params are defined
299 public function testGetMessageWithoutMessageWithStringWithParams()
301 $this->object->setMessage('');
302 $this->object->setString('test string %s %s');
303 $this->object->addParam('test param 1');
304 $this->object->addParam('test param 2');
305 $this->assertEquals('test string test param 1 test param 2', $this->object->getMessage());
309 * getMessage test - with empty message and with empty string
311 public function testGetMessageWithoutMessageWithEmptyString()
313 $this->object->setMessage('');
314 $this->object->setString('');
315 $this->assertEquals('', $this->object->getMessage());
319 * getMessage test - with empty message and with string, which is key to GLOBALS
320 * additional messages are defined
322 public function testGetMessageWithoutMessageWithGlobalStringWithAddMessages()
324 $GLOBALS['key'] = 'test message';
325 $this->object->setMessage('');
326 $this->object->setString('key');
327 $this->object->addMessage('test message 2', ' - ');
328 $this->object->addMessage('test message 3', '&');
329 $this->assertEquals('test message - test message 2&test message 3', $this->object->getMessage());
330 unset($GLOBALS['key']);
334 * getMessage test - message is defined
335 * message with BBCode defined
337 public function testGetMessageWithMessageWithBBCode()
339 $this->object->setMessage('[kbd]test[/kbd] [a@./Documentation.html#cfg_Example@_blank]test[/a]');
340 $this->assertEquals('<kbd>test</kbd> <a href="./Documentation.html#cfg_Example" target="_blank">test</a>', $this->object->getMessage());
344 * getLevel test
346 public function testGetLevel()
348 $this->assertEquals('notice', $this->object->getLevel());
349 $this->object->setNumber(PMA_Message::SUCCESS);
350 $this->assertEquals('success', $this->object->getLevel());
351 $this->object->setNumber(PMA_Message::ERROR);
352 $this->assertEquals('error', $this->object->getLevel());
356 * testing display method (output string and _is_displayed varible)
358 public function testDisplay()
360 $this->assertFalse($this->object->isDisplayed());
361 $this->object->setMessage('Test Message');
363 $this->expectOutputString('<div class="notice">Test Message</div>');
364 $this->object->display();
366 $this->assertTrue($this->object->isDisplayed());
370 * getDisplay test
372 public function testGetDisplay()
374 $this->object->setMessage('Test Message');
375 $this->assertEquals('<div class="notice">Test Message</div>', $this->object->getDisplay());
379 * isDisplayed test
381 public function testIsDisplayed()
383 $this->assertFalse($this->object->isDisplayed(false));
384 $this->assertTrue($this->object->isDisplayed(true));
385 $this->assertTrue($this->object->isDisplayed(false));