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

SC_Response::reload() のテストケース追加 #576

Merged
merged 2 commits into from
Sep 7, 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
5 changes: 2 additions & 3 deletions data/class/SC_Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ public static function reload($arrQueryString = array(), $removeQueryString = fa
// 現在の URL を取得
$netUrl = new Net_URL($_SERVER['REQUEST_URI']);

if (!$removeQueryString) {
$arrQueryString = array_merge($netUrl->querystring, $arrQueryString);
if ($removeQueryString) {
$netUrl->querystring = array();
}
$netUrl->querystring = array();

SC_Response_Ex::sendRedirect($netUrl->getURL(), $arrQueryString);
}
Expand Down
42 changes: 42 additions & 0 deletions tests/class/SC_Response/SC_ResponseWithHeaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

class SC_ResponseWithHeaderTest extends Common_TestCase
{
/** @var resource|bool */
private static $server;
const FIXTURES_DIR = '../fixtures/server';

public static function setUpBeforeClass()
{
$spec = [
1 => ['file', '/dev/null', 'w'],
2 => ['file', '/dev/null', 'w']
];

if (!self::$server = @proc_open('exec php -S 127.0.0.1:8053', $spec, $pipes, __DIR__.'/'.self::FIXTURES_DIR)) {
self::markTestSkipped('PHP server unable to start.');
}
sleep(1);
}

public static function tearDownAfterClass()
{
if (is_resource(self::$server)) {
proc_terminate(self::$server);
proc_close(self::$server);
}
}

public function testReload()
{
$context = stream_context_create(
[
'http' => [
'follow_location' => false
]
]
);
$actual = file_get_contents('http://127.0.0.1:8053/sc_response_reload.php', false, $context);
self::assertStringEqualsFile(__DIR__.'/'.self::FIXTURES_DIR.'/sc_response_reload.expected', $actual);
}
}
19 changes: 19 additions & 0 deletions tests/class/fixtures/server/common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

putenv('HTTP_URL=http://127.0.0.1:8085/');

require __DIR__.'/../../../require.php';

error_reporting(-1);
ini_set('display_errors', '1');

header_remove('X-Powered-By');
header('Content-Type: text/plain; charset=utf-8');

register_shutdown_function(function () {
echo "\n";
session_write_close();
print_r(headers_list());
echo "shutdown\n";
});
ob_start();
7 changes: 7 additions & 0 deletions tests/class/fixtures/server/sc_response_reload.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Location: http://127.0.0.1:8085/index.php?debug=%E3%83%86%E3%82%B9%E3%83%88&redirect=1&transactionid=aaaa
)
shutdown
8 changes: 8 additions & 0 deletions tests/class/fixtures/server/sc_response_reload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

require __DIR__.'/common.php';

$_SERVER['REQUEST_URI'] = HTTPS_URL.'index.php?debug='.urlencode('テスト');
$_SESSION[TRANSACTION_ID_NAME] = 'aaaa';

SC_Response_Ex::reload(['redirect' => 1]);