Skip to content

Commit ebb5566

Browse files
committed
Add Pager testing for current_url
1 parent 39def32 commit ebb5566

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

system/Pager/PagerRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class PagerRenderer
8181
*/
8282
protected $pageCount;
8383
/**
84-
* URI? unused?
84+
* URI base for pagination links
8585
*
8686
* @var integer
8787
*/

tests/system/Helpers/URLHelperTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,12 +1096,13 @@ public function testBasedNoIndex()
10961096
$config->baseURL = 'http://example.com/ci/v4/';
10971097
$config->indexPage = 'index.php';
10981098
$request = Services::request($config);
1099-
$request->uri = new URI('http://example.com/somewhere');
1099+
$request->uri = new URI('http://example.com/ci/v4/x/y');
11001100

11011101
Services::injectMock('request', $request);
11021102

11031103
$this->assertEquals('http://example.com/ci/v4/index.php/controller/method', site_url('controller/method', null, $config));
11041104
$this->assertEquals('http://example.com/ci/v4/controller/method', base_url('controller/method', null, $config));
1105+
$this->assertEquals(base_url(uri_string()), current_url());
11051106
}
11061107

11071108
public function testBasedWithIndex()
@@ -1113,12 +1114,13 @@ public function testBasedWithIndex()
11131114
$config->baseURL = 'http://example.com/ci/v4/';
11141115
$config->indexPage = 'index.php';
11151116
$request = Services::request($config);
1116-
$request->uri = new URI('http://example.com/somewhere');
1117+
$request->uri = new URI('http://example.com/ci/v4/index.php/x/y');
11171118

11181119
Services::injectMock('request', $request);
11191120

11201121
$this->assertEquals('http://example.com/ci/v4/index.php/controller/method', site_url('controller/method', null, $config));
11211122
$this->assertEquals('http://example.com/ci/v4/controller/method', base_url('controller/method', null, $config));
1123+
$this->assertEquals(base_url(uri_string()), current_url());
11221124
}
11231125

11241126
public function testBasedWithoutIndex()
@@ -1130,12 +1132,13 @@ public function testBasedWithoutIndex()
11301132
$config->baseURL = 'http://example.com/ci/v4/';
11311133
$config->indexPage = '';
11321134
$request = Services::request($config);
1133-
$request->uri = new URI('http://example.com/somewhere');
1135+
$request->uri = new URI('http://example.com/ci/v4/x/y');
11341136

11351137
Services::injectMock('request', $request);
11361138

11371139
$this->assertEquals('http://example.com/ci/v4/controller/method', site_url('controller/method', null, $config));
11381140
$this->assertEquals('http://example.com/ci/v4/controller/method', base_url('controller/method', null, $config));
1141+
$this->assertEquals(base_url(uri_string()), current_url());
11391142
}
11401143

11411144
public function testBasedWithOtherIndex()
@@ -1147,12 +1150,13 @@ public function testBasedWithOtherIndex()
11471150
$config->baseURL = 'http://example.com/ci/v4/';
11481151
$config->indexPage = 'fc.php';
11491152
$request = Services::request($config);
1150-
$request->uri = new URI('http://example.com/somewhere');
1153+
$request->uri = new URI('http://example.com/ci/v4/x/y');
11511154

11521155
Services::injectMock('request', $request);
11531156

11541157
$this->assertEquals('http://example.com/ci/v4/fc.php/controller/method', site_url('controller/method', null, $config));
11551158
$this->assertEquals('http://example.com/ci/v4/controller/method', base_url('controller/method', null, $config));
1159+
$this->assertEquals(base_url(uri_string()), current_url());
11561160
}
11571161

11581162
}

tests/system/Pager/PagerTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php namespace CodeIgniter\Pager;
22

3+
use CodeIgniter\HTTP\URI;
34
use CodeIgniter\Pager\Exceptions\PagerException;
5+
use Config\App;
46
use Config\Pager;
57
use Config\Services;
68

@@ -19,7 +21,6 @@ class PagerTest extends \CIUnitTestCase
1921
protected function setUp()
2022
{
2123
parent::setUp();
22-
2324
helper('url');
2425

2526
$_SERVER['HTTP_HOST'] = 'example.com';
@@ -354,4 +355,32 @@ public function testHeadLinks()
354355
$this->assertContains('<link rel="canonical"', $last_page);
355356
$this->assertNotContains('<link rel="next"', $last_page);
356357
}
358+
359+
public function testBasedURI()
360+
{
361+
$_SERVER['HTTP_HOST'] = 'example.com';
362+
$_SERVER['REQUEST_URI'] = '/ci/v4/x/y';
363+
$_GET = [];
364+
365+
$config = new App();
366+
$config->baseURL = 'http://example.com/ci/v4/';
367+
$config->indexPage = 'fc.php';
368+
$request = Services::request($config);
369+
$request->uri = new URI('http://example.com/ci/v4/x/y');
370+
371+
Services::injectMock('request', $request);
372+
373+
$this->config = new Pager();
374+
$this->pager = new \CodeIgniter\Pager\Pager($this->config, Services::renderer());
375+
376+
$_GET['page'] = 2;
377+
378+
$this->pager->store('foo', 2, 12, 70);
379+
380+
$expected = current_url(true);
381+
$expected = (string)$expected->setQuery('page=1');
382+
383+
$this->assertEquals((string)$expected, $this->pager->getPreviousPageURI('foo'));
384+
}
385+
357386
}

0 commit comments

Comments
 (0)