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.

72 lines
2.1 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__) . '/../../../classes/Env.class.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/GetViewHelper.php';
  16. class GetViewHelperTest extends PHPUnit_Framework_TestCase
  17. {
  18. public $helper;
  19. public function setUp()
  20. {
  21. $this->helper = new GetViewHelper(new PHPView('any'));
  22. }
  23. /**
  24. * @TODO: GetViewHelper: initialize GetViewHelper::$get with empty array()
  25. */
  26. public function testGetWithNull()
  27. {
  28. $this->setExpectedException('PHPUnit_Framework_Error');
  29. $this->helper->get(null);
  30. }
  31. /**
  32. * @TODO: GetViewHelper: check $_GET not null
  33. */
  34. public function testGetEmptyGET()
  35. {
  36. $this->setExpectedException('PHPUnit_Framework_Error');
  37. $result = $this->helper->get('param');
  38. }
  39. public function testGetWithSingleParam()
  40. {
  41. $_GET['a'] = 'b';
  42. $result = $this->helper->get(null);
  43. $this->assertEquals('?a=b', $result);
  44. $this->helper = new GetViewHelper(new PHPView('any'));
  45. $_GET['a'] = 'b';
  46. $_GET['b'] = 'a';
  47. $result = $this->helper->get(array('a' => 'c'));
  48. $this->assertEquals('?a=c&amp;b=a', $result);
  49. $_GET['a'] = 'b';
  50. $_GET['b'] = 'a';
  51. $result = $this->helper->get(array('a'));
  52. $this->assertEquals('?b=a', $result);
  53. }
  54. public function testGetWithArray()
  55. {
  56. $_GET['a'] = array('one' => 1, 'two' => 2);
  57. $_GET['b'] = 'a';
  58. $_GET['c'] = array('three' => 'four');
  59. $result = $this->helper->get(array('b' => 'c', 'c' => array('five' => 'six')));
  60. $this->assertEquals('?a[one]=1&amp;a[two]=2&amp;b=c&amp;c[five]=six', $result);
  61. }
  62. }