Skip to content

Commit 50c1cdb

Browse files
committed
test: add tests for uri_string() and current_url()
1 parent a0b2401 commit 50c1cdb

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/system/Test/ControllerTestTraitTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Config\App;
2020
use Config\Services;
2121
use Exception;
22+
use Tests\Support\Controllers\Newautorouting;
2223
use Tests\Support\Controllers\Popcorn;
2324

2425
/**
@@ -259,4 +260,15 @@ public function throwsBody(): void
259260

260261
$this->withBody('banana')->execute('throwsBody');
261262
}
263+
264+
public function testWithUriUpdatesUriStringAndCurrentUrlValues()
265+
{
266+
$result = $this->withURI('http://example.com/foo/bar/1/2/3')
267+
->controller(Newautorouting::class)
268+
->execute('postSave', '1', '2', '3');
269+
270+
$this->assertSame('Saved', $result->response()->getBody());
271+
$this->assertSame('foo/bar/1/2/3', uri_string());
272+
$this->assertSame('http://example.com/index.php/foo/bar/1/2/3', current_url());
273+
}
262274
}

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ public function testCallGet(): void
6161
$response->assertDontSee('Again');
6262
}
6363

64+
public function testCallGetAndUriString(): void
65+
{
66+
$this->withRoutes([
67+
[
68+
'get',
69+
'foo/bar/1/2/3',
70+
static fn () => 'Hello World',
71+
],
72+
]);
73+
$response = $this->get('foo/bar/1/2/3');
74+
75+
$this->assertSame('Hello World', $response->response()->getBody());
76+
$this->assertSame('foo/bar/1/2/3', uri_string());
77+
$this->assertSame('http://example.com/index.php/foo/bar/1/2/3', current_url());
78+
}
79+
6480
public function testClosureWithEcho()
6581
{
6682
$this->withRoutes([

0 commit comments

Comments
 (0)