Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove $request->uri #6619

Merged
merged 10 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions tests/system/Helpers/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ public function testArrayDotIgnoresLastWildcard()
/**
* @dataProvider deepSearchProvider
*
* @param mixed $key
* @param mixed $expected
* @param int|string $key
* @param array|string|null $expected
*/
public function testArrayDeepSearch($key, $expected)
{
Expand Down Expand Up @@ -247,12 +247,8 @@ public function testArrayDeepSearchReturnNullEmptyArray()

/**
* @dataProvider sortByMultipleKeysProvider
*
* @param mixed $data
* @param mixed $sortColumns
* @param mixed $expected
*/
public function testArraySortByMultipleKeysWithArray($data, $sortColumns, $expected)
public function testArraySortByMultipleKeysWithArray(array $data, array $sortColumns, array $expected)
{
$success = array_sort_by_multiple_keys($data, $sortColumns);

Expand All @@ -262,12 +258,8 @@ public function testArraySortByMultipleKeysWithArray($data, $sortColumns, $expec

/**
* @dataProvider sortByMultipleKeysProvider
*
* @param mixed $data
* @param mixed $sortColumns
* @param mixed $expected
*/
public function testArraySortByMultipleKeysWithObjects($data, $sortColumns, $expected)
public function testArraySortByMultipleKeysWithObjects(array $data, array $sortColumns, array $expected)
{
// Morph to objects
foreach ($data as $index => $dataSet) {
Expand All @@ -282,12 +274,8 @@ public function testArraySortByMultipleKeysWithObjects($data, $sortColumns, $exp

/**
* @dataProvider sortByMultipleKeysProvider
*
* @param mixed $data
* @param mixed $sortColumns
* @param mixed $expected
*/
public function testArraySortByMultipleKeysFailsEmptyParameter($data, $sortColumns, $expected)
public function testArraySortByMultipleKeysFailsEmptyParameter(array $data, array $sortColumns, array $expected)
{
// Both filled
$success = array_sort_by_multiple_keys($data, $sortColumns);
Expand Down
55 changes: 18 additions & 37 deletions tests/system/Helpers/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,26 @@ protected function setUp(): void
parent::setUp();

helper('form');

$this->resetServices();
}

public function testFormOpenBasic()
private function setRequest(): void
{
$uri = new URI('http://example.com/');
Services::injectMock('uri', $uri);

$config = new App();
$config->baseURL = '';
$config->indexPage = 'index.php';
$request = Services::request($config);
$request->uri = new URI('http://example.com/');

$request = Services::request($config);
Services::injectMock('request', $request);
}

public function testFormOpenBasic()
{
$request = $this->setRequest();
Services::injectMock('request', $request);

$before = (new Filters())->globals['before'];
Expand Down Expand Up @@ -67,13 +77,8 @@ public function testFormOpenBasic()

public function testFormOpenHasLocale()
{
$config = new App();
$config->baseURL = '';
$config->indexPage = 'index.php';
$request = Services::request($config);
$request->uri = new URI('http://example.com/');
$this->setRequest();

Services::injectMock('request', $request);
$expected = <<<'EOH'
<form action="http://example.com/index.php/en/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">

Expand All @@ -89,13 +94,7 @@ public function testFormOpenHasLocale()

public function testFormOpenWithoutAction()
{
$config = new App();
$config->baseURL = '';
$config->indexPage = 'index.php';
$request = Services::request($config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);
$this->setRequest();

$before = (new Filters())->globals['before'];
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
Expand All @@ -122,13 +121,7 @@ public function testFormOpenWithoutAction()

public function testFormOpenWithoutMethod()
{
$config = new App();
$config->baseURL = '';
$config->indexPage = 'index.php';
$request = Services::request($config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);
$this->setRequest();

$before = (new Filters())->globals['before'];
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
Expand All @@ -155,13 +148,7 @@ public function testFormOpenWithoutMethod()

public function testFormOpenWithHidden()
{
$config = new App();
$config->baseURL = '';
$config->indexPage = 'index.php';
$request = Services::request($config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);
$this->setRequest();

$before = (new Filters())->globals['before'];
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
Expand Down Expand Up @@ -195,13 +182,7 @@ public function testFormOpenWithHidden()

public function testFormOpenMultipart()
{
$config = new App();
$config->baseURL = '';
$config->indexPage = 'index.php';
$request = Services::request($config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);
$this->setRequest();

$before = (new Filters())->globals['before'];
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
MGatner marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
80 changes: 38 additions & 42 deletions tests/system/Helpers/URLHelper/CurrentUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,28 @@ public function testUriStringAbsolute()
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_URI'] = '/assets/image.jpg';

$request = Services::request($this->config);
$request->uri = new URI('http://example.com/assets/image.jpg');
$uri = 'http://example.com/assets/image.jpg';
$this->setService($uri);

Services::injectMock('request', $request);
$this->assertSame('assets/image.jpg', uri_string());
}

private function setService(string $uri): void
{
$uri = new URI($uri);
Services::injectMock('uri', $uri);

$this->assertSame('/assets/image.jpg', uri_string());
$request = Services::request($this->config);
Services::injectMock('request', $request);
}

public function testUriStringRelative()
{
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_URI'] = '/assets/image.jpg';

$request = Services::request($this->config);
$request->uri = new URI('http://example.com/assets/image.jpg');

Services::injectMock('request', $request);
$uri = 'http://example.com/assets/image.jpg';
$this->setService($uri);

$this->assertSame('assets/image.jpg', uri_string(true));
}
Expand All @@ -167,12 +172,11 @@ public function testUriStringNoTrailingSlashAbsolute()
$_SERVER['REQUEST_URI'] = '/assets/image.jpg';

$this->config->baseURL = 'http://example.com';
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/assets/image.jpg');

Services::injectMock('request', $request);
$uri = 'http://example.com/assets/image.jpg';
$this->setService($uri);

$this->assertSame('/assets/image.jpg', uri_string());
$this->assertSame('assets/image.jpg', uri_string());
MGatner marked this conversation as resolved.
Show resolved Hide resolved
}

public function testUriStringNoTrailingSlashRelative()
Expand All @@ -181,30 +185,25 @@ public function testUriStringNoTrailingSlashRelative()
$_SERVER['REQUEST_URI'] = '/assets/image.jpg';

$this->config->baseURL = 'http://example.com';
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/assets/image.jpg');

Services::injectMock('request', $request);
$uri = 'http://example.com/assets/image.jpg';
$this->setService($uri);

$this->assertSame('assets/image.jpg', uri_string(true));
}

public function testUriStringEmptyAbsolute()
{
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);
$uri = 'http://example.com/';
$this->setService($uri);

$this->assertSame('/', uri_string());
}

public function testUriStringEmptyRelative()
{
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/');

Services::injectMock('request', $request);
$uri = 'http://example.com/';
$this->setService($uri);

$this->assertSame('', uri_string(true));
}
Expand All @@ -215,12 +214,11 @@ public function testUriStringSubfolderAbsolute()
$_SERVER['REQUEST_URI'] = '/subfolder/assets/image.jpg';

$this->config->baseURL = 'http://example.com/subfolder/';
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/subfolder/assets/image.jpg');

Services::injectMock('request', $request);
$uri = 'http://example.com/subfolder/assets/image.jpg';
$this->setService($uri);

$this->assertSame('/subfolder/assets/image.jpg', uri_string());
$this->assertSame('subfolder/assets/image.jpg', uri_string());
}

public function testUriStringSubfolderRelative()
Expand All @@ -230,10 +228,9 @@ public function testUriStringSubfolderRelative()
$_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';

$this->config->baseURL = 'http://example.com/subfolder/';
$request = Services::request($this->config);
$request->uri = new URI('http://example.com/subfolder/assets/image.jpg');

Services::injectMock('request', $request);
$uri = 'http://example.com/subfolder/assets/image.jpg';
$this->setService($uri);

$this->assertSame('assets/image.jpg', uri_string(true));
}
Expand Down Expand Up @@ -287,9 +284,8 @@ public function testUrlIs(string $currentPath, string $testPath, bool $expected)
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_URI'] = '/' . $currentPath;

$request = Services::request();
$request->uri = new URI('http://example.com/' . $currentPath);
Services::injectMock('request', $request);
$uri = 'http://example.com/' . $currentPath;
$this->setService($uri);

$this->assertSame($expected, url_is($testPath));
}
Expand All @@ -299,13 +295,13 @@ public function testUrlIs(string $currentPath, string $testPath, bool $expected)
*/
public function testUrlIsNoIndex(string $currentPath, string $testPath, bool $expected)
{
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_URI'] = '/' . $currentPath;
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_URI'] = '/' . $currentPath;

$this->config->indexPage = '';

$request = Services::request($this->config);
$request->uri = new URI('http://example.com/' . $currentPath);
Services::injectMock('request', $request);
$uri = 'http://example.com/' . $currentPath;
$this->setService($uri);

$this->assertSame($expected, url_is($testPath));
}
Expand All @@ -318,11 +314,11 @@ public function testUrlIsWithSubfolder(string $currentPath, string $testPath, bo
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_URI'] = '/' . $currentPath;
$_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';
$this->config->baseURL = 'http://example.com/subfolder/';

$request = Services::request($this->config);
$request->uri = new URI('http://example.com/subfolder/' . $currentPath);
Services::injectMock('request', $request);
$this->config->baseURL = 'http://example.com/subfolder/';

$uri = 'http://example.com/subfolder/' . $currentPath;
$this->setService($uri);

$this->assertSame($expected, url_is($testPath));
}
Expand Down
Loading