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.

75 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. 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. public function testWrongType()
  33. {
  34. $this->setExpectedException('GeneralException', 'Unknown message type');
  35. $this->helper->msg('some message', 'wrong');
  36. }
  37. public function testSuccess()
  38. {
  39. $this->helper->success('success message');
  40. $this->assertSame(array('message' => 'success message', 'type' => 'success'), Session::get('MsgViewHelper'));
  41. }
  42. public function testError()
  43. {
  44. $this->helper->error('error message');
  45. $this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
  46. $this->assertNull(Session::get('test'));
  47. }
  48. public function testToString()
  49. {
  50. $this->helper->success('yeah');
  51. $result = $this->helper->__toString();
  52. $this->assertSame('<div class="success">yeah</div>', $result);
  53. }
  54. public function testToStringEmpty()
  55. {
  56. $result = $this->helper->__toString();
  57. $this->assertEmpty($result);
  58. }
  59. }