Skip to content

Commit 0eebc5e

Browse files
committed
test: add tests for SiteURIFactory
1 parent 3a76189 commit 0eebc5e

1 file changed

Lines changed: 82 additions & 7 deletions

File tree

tests/system/HTTP/SiteURIFactoryTest.php

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,91 @@ public function testCreateFromGlobalsAllowedHost()
8585
$this->assertSame('woot', $uri->getRoutePath());
8686
}
8787

88-
public function testCreateFromString()
89-
{
88+
/**
89+
* @dataProvider provideCreateFromStringWithIndexPage
90+
*/
91+
public function testCreateFromStringWithIndexPage(
92+
string $uriString,
93+
string $expectUriString,
94+
string $expectedPath,
95+
string $expectedRoutePath
96+
) {
9097
$factory = $this->createSiteURIFactory();
9198

92-
$uriString = 'http://invalid.example.jp/foo/bar?page=3';
93-
$uri = $factory->createFromString($uriString);
99+
$uri = $factory->createFromString($uriString);
94100

95101
$this->assertInstanceOf(SiteURI::class, $uri);
96-
$this->assertSame('http://localhost:8080/index.php/foo/bar?page=3', (string) $uri);
97-
$this->assertSame('/index.php/foo/bar', $uri->getPath());
98-
$this->assertSame('foo/bar', $uri->getRoutePath());
102+
$this->assertSame($expectUriString, (string) $uri);
103+
$this->assertSame($expectedPath, $uri->getPath());
104+
$this->assertSame($expectedRoutePath, $uri->getRoutePath());
105+
}
106+
107+
public static function provideCreateFromStringWithIndexPage(): iterable
108+
{
109+
return [
110+
'indexPage path query' => [
111+
'http://invalid.example.jp/foo/bar?page=3', // $uriString
112+
'http://localhost:8080/index.php/foo/bar?page=3', // $expectUriString
113+
'/index.php/foo/bar', // $expectedPath
114+
'foo/bar', // $expectedRoutePath
115+
],
116+
'indexPage noPath' => [
117+
'http://localhost:8080', // $uriString
118+
'http://localhost:8080/index.php', // $expectUriString
119+
'/index.php', // $expectedPath
120+
'', // $expectedRoutePath
121+
],
122+
'indexPage slash' => [
123+
'http://localhost:8080/', // $uriString
124+
'http://localhost:8080/index.php/', // $expectUriString
125+
'/index.php/', // $expectedPath
126+
'', // $expectedRoutePath
127+
],
128+
];
129+
}
130+
131+
/**
132+
* @dataProvider provideCreateFromStringWithoutIndexPage
133+
*/
134+
public function testCreateFromStringWithoutIndexPage(
135+
string $uriString,
136+
string $expectUriString,
137+
string $expectedPath,
138+
string $expectedRoutePath
139+
) {
140+
$config = new App();
141+
$config->indexPage = '';
142+
$factory = $this->createSiteURIFactory($config);
143+
144+
$uri = $factory->createFromString($uriString);
145+
146+
$this->assertInstanceOf(SiteURI::class, $uri);
147+
$this->assertSame($expectUriString, (string) $uri);
148+
$this->assertSame($expectedPath, $uri->getPath());
149+
$this->assertSame($expectedRoutePath, $uri->getRoutePath());
150+
}
151+
152+
public static function provideCreateFromStringWithoutIndexPage(): iterable
153+
{
154+
return [
155+
'path query' => [
156+
'http://invalid.example.jp/foo/bar?page=3', // $uriString
157+
'http://localhost:8080/foo/bar?page=3', // $expectUriString
158+
'/foo/bar', // $expectedPath
159+
'foo/bar', // $expectedRoutePath
160+
],
161+
'noPath' => [
162+
'http://localhost:8080', // $uriString
163+
'http://localhost:8080/', // $expectUriString
164+
'/', // $expectedPath
165+
'', // $expectedRoutePath
166+
],
167+
'slash' => [
168+
'http://localhost:8080/', // $uriString
169+
'http://localhost:8080/', // $expectUriString
170+
'/', // $expectedPath
171+
'', // $expectedRoutePath
172+
],
173+
];
99174
}
100175
}

0 commit comments

Comments
 (0)