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.

101 lines
3.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. require_once dirname(__FILE__) . '/../../../exception/GeneralException.php';
  17. class MsgViewHelperTest extends PHPUnit_Framework_TestCase
  18. {
  19. /**
  20. * @var MsgViewHelper
  21. */
  22. public $helper;
  23. public function setUp()
  24. {
  25. Session::del('MsgViewHelper');
  26. $this->helper = new MsgViewHelper(new PHPView(array('path' => 'any')));
  27. }
  28. public function testMsg()
  29. {
  30. $this->helper->msg('new message from test', 'success');
  31. $this->assertSame(array('message' => 'new message from test', 'type' => 'success'), Session::get('MsgViewHelper'));
  32. $this->assertSame($this->helper, $this->helper->msg('error message', 'error'));
  33. $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
  34. }
  35. public function testWrongType()
  36. {
  37. $this->setExpectedException('GeneralException', 'Unknown message type');
  38. $this->helper->msg('some message', 'wrong');
  39. }
  40. public function testSuccess()
  41. {
  42. $this->helper->success('success message');
  43. $this->assertSame(array('message' => 'success message', 'type' => 'success'), Session::get('MsgViewHelper'));
  44. }
  45. public function testError()
  46. {
  47. $this->helper->error('error message');
  48. $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
  49. $this->assertNull(Session::get('test'));
  50. }
  51. public function testInfo()
  52. {
  53. $this->helper->info('info message');
  54. $this->assertSame(array('message' => 'info message', 'type' => 'info'), Session::get('MsgViewHelper'));
  55. $this->assertNull(Session::get('test'));
  56. }
  57. public function testWarning()
  58. {
  59. $this->helper->warning('warning message');
  60. $this->assertSame(array('message' => 'warning message', 'type' => 'warning'), Session::get('MsgViewHelper'));
  61. $this->assertNull(Session::get('test'));
  62. }
  63. public function testToString()
  64. {
  65. $this->helper->success('yeah');
  66. $result = $this->helper->__toString();
  67. $this->assertSame('<div class="success">yeah</div>', $result);
  68. }
  69. public function testToStringEmpty()
  70. {
  71. $result = $this->helper->__toString();
  72. $this->assertEmpty($result);
  73. }
  74. public function testToStringWithPrefix()
  75. {
  76. $this->helper->success('yeah');
  77. $result = $this->helper->withPrefix('prefix')->__toString();
  78. $this->assertSame('<div class="prefixsuccess">yeah</div>', $result);
  79. }
  80. public function testToStringEmptyWithPrefix()
  81. {
  82. $result = $this->helper->withPrefix('prefix')->__toString();
  83. $this->assertEmpty($result);
  84. }
  85. }