Skip to content
This repository
Browse code

Update PaginatorHelper::beforeRender to merge request->query with url…

… options
  • Loading branch information...
commit 1475e87b3823f7ea6f0d7a0f0116ac5d45b161fd 1 parent 4f2d7b5
Takayuki Miwa authored March 03, 2012
84  lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
@@ -661,11 +661,12 @@ public function testPassedArgsMergingWithUrlOptions() {
661 661
 
662 662
 		$this->Paginator->request->params['pass'] = array(2);
663 663
 		$this->Paginator->request->params['named'] = array('foo' => 'bar');
  664
+		$this->Paginator->request->query = array('x' => 'y');
664 665
 		$this->Paginator->beforeRender('posts/index');
665 666
 
666 667
 		$result = $this->Paginator->sort('title');
667 668
 		$expected = array(
668  
-			'a' => array('href' => '/articles/index/2/page:1/foo:bar/sort:title/direction:asc'),
  669
+			'a' => array('href' => '/articles/index/2/page:1/foo:bar/sort:title/direction:asc?x=y'),
669 670
 			'Title',
670 671
 			'/a'
671 672
 		);
@@ -675,24 +676,91 @@ public function testPassedArgsMergingWithUrlOptions() {
675 676
 		$expected = array(
676 677
 			array('span' => array('class' => 'current')), '1', '/span',
677 678
 			' | ',
678  
-			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:2/foo:bar')), '2', '/a', '/span',
  679
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:2/foo:bar?x=y')), '2', '/a', '/span',
679 680
 			' | ',
680  
-			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:3/foo:bar')), '3', '/a', '/span',
  681
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:3/foo:bar?x=y')), '3', '/a', '/span',
681 682
 			' | ',
682  
-			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:4/foo:bar')), '4', '/a', '/span',
  683
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:4/foo:bar?x=y')), '4', '/a', '/span',
683 684
 			' | ',
684  
-			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:5/foo:bar')), '5', '/a', '/span',
  685
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:5/foo:bar?x=y')), '5', '/a', '/span',
685 686
 			' | ',
686  
-			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:6/foo:bar')), '6', '/a', '/span',
  687
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:6/foo:bar?x=y')), '6', '/a', '/span',
687 688
 			' | ',
688  
-			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:7/foo:bar')), '7', '/a', '/span',
  689
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:7/foo:bar?x=y')), '7', '/a', '/span',
689 690
 		);
690 691
 		$this->assertTags($result, $expected);
691 692
 
692 693
 		$result = $this->Paginator->next('Next');
693 694
 		$expected = array(
694 695
 			'span' => array('class' => 'next'),
695  
-			'a' => array('href' => '/articles/index/2/page:2/foo:bar', 'rel' => 'next'),
  696
+			'a' => array('href' => '/articles/index/2/page:2/foo:bar?x=y', 'rel' => 'next'),
  697
+			'Next',
  698
+			'/a',
  699
+			'/span'
  700
+		);
  701
+		$this->assertTags($result, $expected);
  702
+	}
  703
+
  704
+/**
  705
+ * testPassedArgsMergingWithUrlOptionsParamTypeQuerystring method
  706
+ *
  707
+ * @return void
  708
+ */
  709
+	public function testPassedArgsMergingWithUrlOptionsParamTypeQuerystring() {
  710
+		Router::reload();
  711
+		Router::parse('/');
  712
+		Router::setRequestInfo(array(
  713
+			array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'url' => array('url' => 'articles/index/2/foo:bar')),
  714
+			array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
  715
+		));
  716
+		$this->Paginator->request->params['paging'] = array(
  717
+			'Article' => array(
  718
+				'page' => 1, 'current' => 3, 'count' => 13,
  719
+				'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
  720
+				'options' => array(
  721
+					'page' => 1,
  722
+					'order' => array(),
  723
+					'conditions' => array()
  724
+				),
  725
+				'paramType' => 'querystring'
  726
+			)
  727
+		);
  728
+
  729
+		$this->Paginator->request->params['pass'] = array(2);
  730
+		$this->Paginator->request->params['named'] = array('foo' => 'bar');
  731
+		$this->Paginator->request->query = array('x' => 'y');
  732
+		$this->Paginator->beforeRender('posts/index');
  733
+
  734
+		$result = $this->Paginator->sort('title');
  735
+		$expected = array(
  736
+			'a' => array('href' => '/articles/index/2/foo:bar?x=y&page=1&sort=title&direction=asc'),
  737
+			'Title',
  738
+			'/a'
  739
+		);
  740
+		$this->assertTags($result, $expected);
  741
+
  742
+		$result = $this->Paginator->numbers();
  743
+		$expected = array(
  744
+			array('span' => array('class' => 'current')), '1', '/span',
  745
+			' | ',
  746
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&page=2')), '2', '/a', '/span',
  747
+			' | ',
  748
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&page=3')), '3', '/a', '/span',
  749
+			' | ',
  750
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&page=4')), '4', '/a', '/span',
  751
+			' | ',
  752
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&page=5')), '5', '/a', '/span',
  753
+			' | ',
  754
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&page=6')), '6', '/a', '/span',
  755
+			' | ',
  756
+			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&page=7')), '7', '/a', '/span',
  757
+		);
  758
+		$this->assertTags($result, $expected);
  759
+
  760
+		$result = $this->Paginator->next('Next');
  761
+		$expected = array(
  762
+			'span' => array('class' => 'next'),
  763
+			'a' => array('href' => '/articles/index/2/foo:bar?x=y&page=2', 'rel' => 'next'),
696 764
 			'Next',
697 765
 			'/a',
698 766
 			'/span'
3  lib/Cake/View/Helper/PaginatorHelper.php
@@ -109,6 +109,9 @@ public function __construct(View $View, $settings = array()) {
109 109
  */
110 110
 	public function beforeRender($viewFile) {
111 111
 		$this->options['url'] = array_merge($this->request->params['pass'], $this->request->params['named']);
  112
+		if (!empty($this->request->query)) {
  113
+			$this->options['url']['?'] = $this->request->query;
  114
+		}
112 115
 		parent::beforeRender($viewFile);
113 116
 	}
114 117
 

0 notes on commit 1475e87

Please sign in to comment.
Something went wrong with that request. Please try again.