remove todo, after upgrade PHPExcel
[phpmyadmin/arisferyanto.git] / test / PMA_Message_test.php
blobe247c5f7685a2cb9f09188e66dff970fe8944c65
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for PMA_Message class
6 * @author Michal Biniek <michal@bystrzyca.pl>
7 * @version $Id$
8 */
10 /**
11 * Tests core.
13 require_once 'PHPUnit/Framework.php';
14 require_once 'PHPUnit/Extensions/OutputTestCase.php';
16 /**
17 * Include to test.
19 require_once './libraries/Message.class.php';
21 /**
22 * Test class PMA_Message.
24 * @package phpMyAdmin-test
26 class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
28 /**
29 * @var PMA_Message
30 * @access protected
32 protected $object;
34 /**
35 * Sets up the fixture, for example, opens a network connection.
36 * This method is called before a test is executed.
38 * @access protected
40 protected function setUp()
42 $this->object = new PMA_Message;
45 /**
46 * Tears down the fixture, for example, closes a network connection.
47 * This method is called after a test is executed.
49 * @access protected
51 protected function tearDown()
55 /**
56 * to String casting test
58 public function test__toString()
60 $this->object->setMessage('test<&>', true);
61 $this->assertEquals('test&lt;&amp;&gt;', (string)$this->object);
64 /**
65 * test success method
67 public function testSuccess()
69 $this->object = new PMA_Message('test<&>', PMA_Message::SUCCESS);
70 $this->assertEquals($this->object, PMA_Message::success('test<&>'));
71 $this->assertEquals('strSuccess', PMA_Message::success()->getString());
74 /**
75 * test error method
77 public function testError()
79 $this->object = new PMA_Message('test<&>', PMA_Message::ERROR);
80 $this->assertEquals($this->object, PMA_Message::error('test<&>'));
81 $this->assertEquals('strError', PMA_Message::error()->getString());
84 /**
85 * test warning method
87 public function testWarning()
89 $this->object = new PMA_Message('test<&>', PMA_Message::WARNING);
90 $this->assertEquals($this->object, PMA_Message::warning('test<&>'));
93 /**
94 * test notice method
96 public function testNotice()
98 $this->object = new PMA_Message('test<&>', PMA_Message::NOTICE);
99 $this->assertEquals($this->object, PMA_Message::notice('test<&>'));
103 * test rawError method
105 public function testRawError()
107 $this->object = new PMA_Message('', PMA_Message::ERROR);
108 $this->object->setMessage('test<&>');
110 $this->assertEquals($this->object, PMA_Message::rawError('test<&>'));
114 * test rawWarning method
116 public function testRawWarning()
118 $this->object = new PMA_Message('', PMA_Message::WARNING);
119 $this->object->setMessage('test<&>');
121 $this->assertEquals($this->object, PMA_Message::rawWarning('test<&>'));
125 * test rawNotice method
127 public function testRawNotice()
129 $this->object = new PMA_Message('', PMA_Message::NOTICE);
130 $this->object->setMessage('test<&>');
132 $this->assertEquals($this->object, PMA_Message::rawNotice('test<&>'));
136 * test rawSuccess method
138 public function testRawSuccess()
140 $this->object = new PMA_Message('', PMA_Message::SUCCESS);
141 $this->object->setMessage('test<&>');
143 $this->assertEquals($this->object, PMA_Message::rawSuccess('test<&>'));
147 * testing isSuccess method
149 public function testIsSuccess()
151 $this->assertFalse($this->object->isSuccess());
152 $this->assertTrue($this->object->isSuccess(true));
156 * testing isNotice method
158 public function testIsNotice()
160 $this->assertTrue($this->object->isNotice());
161 $this->object->isWarning(true);
162 $this->assertFalse($this->object->isNotice());
163 $this->assertTrue($this->object->isNotice(true));
167 * testing isWarning method
169 public function testIsWarning()
171 $this->assertFalse($this->object->isWarning());
172 $this->assertTrue($this->object->isWarning(true));
176 * testing isError method
178 public function testIsError()
180 $this->assertFalse($this->object->isError());
181 $this->assertTrue($this->object->isError(true));
185 * testign setter of message
187 public function testSetMessage()
189 $this->object->setMessage('test&<>', false);
190 $this->assertEquals('test&<>', $this->object->getMessage());
191 $this->object->setMessage('test&<>', true);
192 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getMessage());
196 * testing setter of string
198 public function testSetString()
200 $this->object->setString('test&<>', false);
201 $this->assertEquals('test&<>', $this->object->getString());
202 $this->object->setString('test&<>', true);
203 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getString());
207 * testing add param method
209 public function testAddParam()
211 $this->object->addParam(PMA_Message::notice('test'));
212 $this->assertEquals(array(PMA_Message::notice('test')), $this->object->getParams());
213 $this->object->addParam('test', true);
214 $this->assertEquals(array(PMA_Message::notice('test'), 'test'), $this->object->getParams());
215 $this->object->addParam('test', false);
216 $this->assertEquals(array(PMA_Message::notice('test'), 'test', PMA_Message::notice('test')), $this->object->getParams());
220 * testing add string method
222 public function testAddString()
224 $this->object->addString('test', '*');
225 $this->assertEquals(array('*', PMA_Message::notice('test')), $this->object->getAddedMessages());
226 $this->object->addString('test', '');
227 $this->assertEquals(array('*', PMA_Message::notice('test'), '', PMA_Message::notice('test')), $this->object->getAddedMessages());
231 * testing add messages method
233 public function testAddMessages()
235 $this->object->addMessages(array('test', PMA_Message::rawWarning('test')), '&');
236 $this->assertEquals(array('&', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
240 * testing add message method
242 public function testAddMessage()
244 $this->object->addMessage('test', '');
245 $this->assertEquals(array(PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
246 $this->object->addMessage('test');
247 $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
248 $this->object->addMessage(PMA_Message::rawWarning('test'), '&');
249 $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
253 * testing setter of params
255 public function testSetParams()
257 $this->object->setParams('test&<>');
258 $this->assertEquals('test&<>', $this->object->getParams());
259 $this->object->setParams('test&<>', true);
260 $this->assertEquals('test&amp;&lt;&gt;', $this->object->getParams());
264 * testing sanitize method
266 public function testSanitize()
268 $this->object->setString('test&string<>', false);
269 $this->assertEquals('test&amp;string&lt;&gt;', PMA_Message::sanitize($this->object));
270 $this->assertEquals(array('test&amp;string&lt;&gt;', 'test&amp;string&lt;&gt;'), PMA_Message::sanitize(array($this->object, $this->object)));
273 public function decodeBBDataProvider()
275 return array(
276 array('[i]test[/i][i]aa[i/][em]test[/em]', '<em>test</em><em>aa[i/]<em>test</em>'),
277 array('[b]test[/b][strong]test[/strong]', '<strong>test</strong><strong>test</strong>'),
278 array('[tt]test[/tt][code]test[/code]', '<code>test</code><code>test</code>'),
279 array('[kbd]test[/kbd][br][sup]test[/sup]', '<kbd>test</kbd><br /><sup>test</sup>')
284 * testing decodeBB method
285 * @dataProvider decodeBBDataProvider
288 public function testDecodeBB($actual, $expected)
290 $this->assertEquals($expected, PMA_Message::decodeBB($actual));
294 * testing format method
296 public function testFormat()
298 $this->assertEquals('test string', PMA_Message::format('test string'));
299 $this->assertEquals('test string', PMA_Message::format('test string', 'a'));
300 $this->assertEquals('test string', PMA_Message::format('test string', array()));
301 $this->assertEquals('test string', PMA_Message::format('%s string', array('test')));
306 * testing getHash method
308 public function testGetHash()
310 $this->object->setString('<&>test', false);
311 $this->object->setMessage('<&>test', false);
312 $this->assertEquals(md5(PMA_Message::NOTICE . '<&>test<&>test'), $this->object->getHash());
316 * getMessage test - with empty message and with non-empty string - not key in globals
317 * additional params are defined
319 public function testGetMessageWithoutMessageWithStringWithParams()
321 $this->object->setMessage('');
322 $this->object->setString('test string %s %s');
323 $this->object->addParam('test param 1');
324 $this->object->addParam('test param 2');
325 $this->assertEquals('test string test param 1 test param 2', $this->object->getMessage());
329 * getMessage test - with empty message and with empty string
331 public function testGetMessageWithoutMessageWithEmptyString()
333 $this->object->setMessage('');
334 $this->object->setString('');
335 $this->assertEquals('', $this->object->getMessage());
339 * getMessage test - with empty message and with string, which is key to GLOBALS
340 * additional messages are defined
342 public function testGetMessageWithoutMessageWithGlobalStringWithAddMessages()
344 $GLOBALS['key'] = 'test message';
345 $this->object->setMessage('');
346 $this->object->setString('key');
347 $this->object->addMessage('test message 2', ' - ');
348 $this->object->addMessage('test message 3', '&');
349 $this->assertEquals('test message - test message 2&test message 3', $this->object->getMessage());
350 unset($GLOBALS['key']);
354 * getMessage test - message is defined
355 * message with BBCode defined
357 public function testGetMessageWithMessageWithBBCode()
359 $this->object->setMessage('[kbd]test[/kbd] [a@./Documentation.html#cfg_Example@_blank]test[/a]');
360 $this->assertEquals('<kbd>test</kbd> <a href="./Documentation.html#cfg_Example" target="_blank">test</a>', $this->object->getMessage());
364 * getLevel test
366 public function testGetLevel()
368 $this->assertEquals('notice', $this->object->getLevel());
369 $this->object->setNumber(PMA_Message::SUCCESS);
370 $this->assertEquals('success', $this->object->getLevel());
371 $this->object->setNumber(PMA_Message::ERROR);
372 $this->assertEquals('error', $this->object->getLevel());
373 $this->object->setNumber(PMA_Message::WARNING);
374 $this->assertEquals('warning', $this->object->getLevel());
378 * testing display method (output string and _is_displayed varible)
380 public function testDisplay()
382 $this->assertFalse($this->object->isDisplayed());
383 $this->object->setMessage('Test Message');
385 $this->expectOutputString('<div class="notice">Test Message</div>');
386 $this->object->display();
388 $this->assertTrue($this->object->isDisplayed());
392 * getDisplay test
394 public function testGetDisplay()
396 $this->object->setMessage('Test Message');
397 $this->assertEquals('<div class="notice">Test Message</div>', $this->object->getDisplay());
401 * isDisplayed test
403 public function testIsDisplayed()
405 $this->assertFalse($this->object->isDisplayed(false));
406 $this->assertTrue($this->object->isDisplayed(true));
407 $this->assertTrue($this->object->isDisplayed(false));