Skip to content

Commit 96d8a7e

Browse files
committed
tests: added tests
1 parent 8997102 commit 96d8a7e

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Http\RequestFactory query detection.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Nette\Http\RequestFactory;
10+
use Tester\Assert;
11+
12+
13+
require __DIR__ . '/../bootstrap.php';
14+
15+
16+
$factory = new RequestFactory;
17+
18+
test(function () use ($factory) {
19+
$_SERVER = [
20+
'HTTP_HOST' => 'nette.org',
21+
'REQUEST_URI' => '/',
22+
];
23+
24+
Assert::same('http://nette.org/', (string) $factory->createHttpRequest()->getUrl());
25+
});
26+
27+
28+
test(function () use ($factory) {
29+
$_SERVER = [
30+
'HTTP_HOST' => 'nette.org',
31+
'REQUEST_URI' => '/?a=b',
32+
];
33+
34+
Assert::same('http://nette.org/?a=b', (string) $factory->createHttpRequest()->getUrl());
35+
});

tests/Http/Url.query.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ Assert::same(['arg' => 'value', 'arg2' => null], $url->getQueryParameters());
6565
$url = new Url('http://hostname/path?arg=value');
6666
$url->setQuery([null]);
6767
Assert::same('http://hostname/path', $url->getAbsoluteUrl());
68+
69+
$url = new Url('http://hostname/path?arg=value');
70+
$url->setQuery('');
71+
Assert::same('http://hostname/path', $url->getAbsoluteUrl());
72+
73+
$url = new Url('http://hostname/path?arg=value');
74+
$url->setQuery('a=1');
75+
Assert::same('http://hostname/path?a=1', $url->getAbsoluteUrl());

tests/Http/UrlImmutable.manipulation.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,10 @@ test(function () {
7070

7171
$url = $url->withQuery([null]);
7272
Assert::same('http://hostname/path', $url->getAbsoluteUrl());
73+
74+
$url = $url->withQuery('');
75+
Assert::same('http://hostname/path', $url->getAbsoluteUrl());
76+
77+
$url = $url->withQuery('a=1');
78+
Assert::same('http://hostname/path?a=1', $url->getAbsoluteUrl());
7379
});

0 commit comments

Comments
 (0)