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.

78 lines
2.3 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/InitializationException.php';
  17. class MsgViewHelperTest extends PHPUnit_Framework_TestCase
  18. {
  19. public $helper;
  20. public function setUp()
  21. {
  22. Session::del('MsgViewHelper');
  23. $this->helper = new MsgViewHelper(new PHPView(array('path' => 'any')));
  24. }
  25. public function testMsg()
  26. {
  27. $this->helper->msg('new message from test', 'success');
  28. $this->assertSame(array('message' => 'new message from test', 'type' => 'success'), Session::get('MsgViewHelper'));
  29. $this->assertSame($this->helper, $this->helper->msg('error message', 'error'));
  30. $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
  31. }
  32. /**
  33. * @expectedException GeneralException
  34. * @expectedExceptionMessage Unknown message type
  35. */
  36. public function testWrongType()
  37. {
  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 testToString()
  52. {
  53. $this->helper->success('yeah');
  54. $result = $this->helper->__toString();
  55. $this->assertSame('<div class="success">yeah</div>', $result);
  56. }
  57. public function testToStringEmpty()
  58. {
  59. $result = $this->helper->__toString();
  60. $this->assertEmpty($result);
  61. }
  62. }