You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-11
  8. *
  9. * Unit tests for PHPView class
  10. */
  11. require_once dirname(__FILE__) . '/../../../session/Session.php';
  12. require_once dirname(__FILE__) . '/../../../view/iView.php';
  13. require_once dirname(__FILE__) . '/../../../view/PHPView.php';
  14. require_once dirname(__FILE__) . '/../../../view/helpers/ViewHelper.php';
  15. require_once dirname(__FILE__) . '/../../../view/helpers/MsgViewHelper.php';
  16. class MsgViewHelperTest extends PHPUnit_Framework_TestCase
  17. {
  18. public $helper;
  19. public function setUp()
  20. {
  21. Session::del('MsgViewHelper');
  22. $this->helper = new MsgViewHelper(new PHPView(array('path' => 'any')));
  23. }
  24. public function testMsg()
  25. {
  26. $this->helper->msg('new message from test', 'success');
  27. $this->assertSame(array('message' => 'new message from test', 'type' => 'success'), Session::get('MsgViewHelper'));
  28. $this->assertSame($this->helper, $this->helper->msg('error message', 'error'));
  29. $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
  30. }
  31. /**
  32. * @expectedException Exception
  33. * @expectedExceptionMessage Unknown message type
  34. */
  35. public function testWrongType()
  36. {
  37. $this->helper->msg('some message', 'wrong');
  38. }
  39. public function testSuccess()
  40. {
  41. $this->helper->success('success message');
  42. $this->assertSame(array('message' => 'success message', 'type' => 'success'), Session::get('MsgViewHelper'));
  43. }
  44. public function testError()
  45. {
  46. $this->helper->error('error message');
  47. $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
  48. $this->assertNull(Session::get('test'));
  49. }
  50. public function testToString()
  51. {
  52. $this->helper->success('yeah');
  53. $result = $this->helper->__toString();
  54. $this->assertSame('<div class="success">yeah</div>', $result);
  55. }
  56. public function testToStringEmpty()
  57. {
  58. $result = $this->helper->__toString();
  59. $this->assertEmpty($result);
  60. }
  61. }