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.

83 lines
2.4 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. /**
  19. * @var GetViewHelper
  20. */
  21. public $helper;
  22. public function setUp()
  23. {
  24. $this->helper = new GetViewHelper(new PHPView('any'));
  25. }
  26. /**
  27. * @TODO: GetViewHelper: initialize GetViewHelper::$get with empty array()
  28. */
  29. public function testGetWithNull()
  30. {
  31. $this->setExpectedException('PHPUnit_Framework_Error');
  32. $this->helper->get(null);
  33. }
  34. /**
  35. * @TODO: GetViewHelper: check $_GET not null
  36. */
  37. public function testGetEmptyGET()
  38. {
  39. $this->setExpectedException('PHPUnit_Framework_Error');
  40. $result = $this->helper->get('param');
  41. }
  42. public function testGetWithSingleParam()
  43. {
  44. $_GET['a'] = 'b';
  45. $result = $this->helper->get(null);
  46. $this->assertSame('?a=b', $result);
  47. $this->helper = new GetViewHelper(new PHPView('any'));
  48. $_GET['a'] = 'b';
  49. $_GET['b'] = 'a';
  50. $result = $this->helper->get(array('a' => 'c'));
  51. $this->assertSame('?a=c&amp;b=a', $result);
  52. $_GET['a'] = 'b';
  53. $_GET['b'] = 'a';
  54. $result = $this->helper->get(array('a'));
  55. $this->assertSame('?b=a', $result);
  56. }
  57. public function testGetWithArray()
  58. {
  59. $_GET['a'] = array('one' => 1, 'two' => 2);
  60. $_GET['b'] = 'a';
  61. $_GET['c'] = array('three' => 'four');
  62. $result = $this->helper->get(array('b' => 'c', 'c' => array('five' => 'six')));
  63. $this->assertSame('?a[one]=1&amp;a[two]=2&amp;b=c&amp;c[five]=six', $result);
  64. }
  65. public function testGetUrlencode()
  66. {
  67. $_GET['a'] = array('one' => 1, 'two' => 2);
  68. $_GET['b'] = 'a';
  69. $_GET['c'] = array('three' => 'four');
  70. $result = $this->helper->get(array('b' => 'c d e', 'c' => array('five' => 'six seven')));
  71. $this->assertSame('?a[one]=1&amp;a[two]=2&amp;b=c+d+e&amp;c[five]=six+seven', $result);
  72. }
  73. }