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.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/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 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. }