-
Notifications
You must be signed in to change notification settings - Fork 98
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::sendRedirect() transactionid= を画一的に追加せず、一定条件での継承のみとする #922 #960
Merged
+355
−9
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c8670ee
SC_Response::sendRedirect() transactionid= を画一的に追加せず、継承する #922
seasoftjapan b13a3e2
SC_Response::sendRedirect() transactionid= を画一的に追加せず、継承する #922
seasoftjapan 51a23f9
SC_Response::sendRedirect() transactionid= を画一的に追加せず、継承する #922
seasoftjapan 4d7ae7d
Merge remote-tracking branch 'ofc/master' into seasoft-922
seasoftjapan 960b4c8
iSC_Response::sendRedirect() transactionid= を画一的に追加せず、一定条件での継承のみとする #922
seasoftjapan a09269a
SC_Response::sendRedirect() transactionid= を画一的に追加せず、一定条件での継承のみとする #922
seasoftjapan 711ebc8
Merge branch 'master' into seasoft-922-2
nanasess 146e122
Merge branch 'master' into seasoft-922-2
seasoftjapan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
291 changes: 291 additions & 0 deletions
291
tests/class/SC_Response/SC_ResponseSendRedirectWithHeaderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,291 @@ | ||
<?php | ||
|
||
class SC_ResponseSendRedirectWithHeaderTest 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:8085', $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); | ||
} | ||
} | ||
|
||
/** | ||
* @param array $arrPostData | ||
* @param array $arrTestHeader エスケープせず HTTP ヘッダーに埋め込むので注意。 | ||
* @param array|null $arrPostData | ||
* @return void | ||
*/ | ||
private function request($arrQuery = [], $arrTestHeader = [], $arrPostData = null) | ||
{ | ||
$netUrl = new Net_URL('http://127.0.0.1:8085/sc_response_sendRedirect.php'); | ||
$netUrl->querystring = $arrQuery; | ||
$url = $netUrl->getUrl(); | ||
|
||
$arrOptions = [ | ||
'http' => [ | ||
'follow_location' => 0, | ||
'header' => [], | ||
], | ||
]; | ||
|
||
if (isset($arrPostData)) { | ||
$arrOptions['http']['method'] = 'POST'; | ||
$arrOptions['http']['header'][] = 'Content-Type: application/x-www-form-urlencoded'; | ||
$arrOptions['http']['content'] = http_build_query($arrPostData, '', '&'); | ||
} | ||
foreach ($arrTestHeader as $key => $value) { | ||
$arrOptions['http']['header'][] = "X-Test-{$key}: {$value}"; | ||
} | ||
|
||
$contents = file_get_contents($url, false, stream_context_create($arrOptions)); | ||
|
||
return $contents; | ||
} | ||
|
||
/** | ||
* @param array $arrQuerystring | ||
* @return string | ||
*/ | ||
private function getExpectedContents($arrQuerystring = []) | ||
{ | ||
$netUrl = new Net_URL('http://127.0.0.1:8085/redirect_url.php'); | ||
$netUrl->querystring = $arrQuerystring; | ||
$url = $netUrl->getUrl(); | ||
|
||
$contents = file_get_contents(__DIR__ . '/' . self::FIXTURES_DIR . '/sc_response_sendRedirect.expected'); | ||
$contents = str_replace('{url}', $url, $contents); | ||
|
||
return $contents; | ||
} | ||
|
||
/** | ||
* 以下は、sendRedirect で transactionid が付加されないパターン。 | ||
*/ | ||
public function testSendRedirect_Admin_GRG_transactionidなし_遷移先にmode() | ||
{ | ||
$arrQuery = [ | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'admin', | ||
'dst_mode' => 'hoge', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader); | ||
|
||
$expected = $this->getExpectedContents([ | ||
'mode' => 'hoge', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function testSendRedirect_Admin_PRG_リクエストにtransactionid_modeなし() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'admin', | ||
]; | ||
$arrPostData = [ | ||
'foo' => 'bar', | ||
TRANSACTION_ID_NAME => 'on_reqest_post', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader, $arrPostData); | ||
|
||
$expected = $this->getExpectedContents(); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function testSendRedirect_Front_GRG_リクエストにtransactionid_遷移先にmode() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'front', | ||
'dst_mode' => 'hoge', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader); | ||
|
||
$expected = $this->getExpectedContents([ | ||
'mode' => 'hoge', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function testSendRedirect_Front_PRG_リクエストにtransactionid_遷移先にmode() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'front', | ||
'dst_mode' => 'hoge', | ||
]; | ||
$arrPostData = [ | ||
'foo' => 'bar', | ||
TRANSACTION_ID_NAME => 'on_reqest_post', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader, $arrPostData); | ||
|
||
$expected = $this->getExpectedContents([ | ||
'mode' => 'hoge', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
/** | ||
* 以下は、sendRedirect で リクエストの transactionid がリダイレクト先に引き継がれるパターン。 | ||
*/ | ||
public function testSendRedirect_Admin_GRG_リクエストにtransactionid_遷移先にmode() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'admin', | ||
'dst_mode' => 'hoge', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader); | ||
|
||
$expected = $this->getExpectedContents([ | ||
'mode' => 'hoge', | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function testSendRedirect_Admin_PRG_リクエストにtransactionid_遷移先にmode() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'admin', | ||
'dst_mode' => 'hoge', | ||
]; | ||
$arrPostData = [ | ||
'foo' => 'bar', | ||
TRANSACTION_ID_NAME => 'on_reqest_post', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader, $arrPostData); | ||
|
||
$expected = $this->getExpectedContents([ | ||
'mode' => 'hoge', | ||
TRANSACTION_ID_NAME => 'on_reqest_post', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function testSendRedirect_Admin_GRG_リクエストにtransactionid_modeなし_クエリ継承() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'admin', | ||
'inherit_query_string' => '1', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader); | ||
|
||
$expected = $this->getExpectedContents([ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function testSendRedirect_Admin_PRG_リクエストにtransactionid_modeなし_クエリ継承() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'admin', | ||
'inherit_query_string' => '1', | ||
]; | ||
$arrPostData = [ | ||
'foo' => 'bar', | ||
TRANSACTION_ID_NAME => 'on_reqest_post', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader, $arrPostData); | ||
|
||
$expected = $this->getExpectedContents([ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
/** | ||
* 以下は、sendRedirect で ロジックの transactionid がリダイレクト先に渡るパターン。 | ||
* | ||
* 通常無さそうなケースだが、仕様として持っている動作。リダイレクトのタイミングで transactionid を更新する用途を想定。 | ||
*/ | ||
public function testSendRedirect_Admin_GRG_ロジック・リクエストにtransactionid_遷移先にmode() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'admin', | ||
'dst_mode' => 'hoge', | ||
'logic_transaction_id' => 'on_logic', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader); | ||
|
||
$expected = $this->getExpectedContents([ | ||
'mode' => 'hoge', | ||
TRANSACTION_ID_NAME => 'on_logic', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function testSendRedirect_Admin_PRG_ロジック・リクエストにtransactionid_遷移先にmode() | ||
{ | ||
$arrQuery = [ | ||
TRANSACTION_ID_NAME => 'on_reqest_query', | ||
]; | ||
$arrTestHeader = [ | ||
'function' => 'admin', | ||
'dst_mode' => 'hoge', | ||
'logic_transaction_id' => 'on_logic', | ||
]; | ||
$arrPostData = [ | ||
'foo' => 'bar', | ||
TRANSACTION_ID_NAME => 'on_reqest_post', | ||
]; | ||
$actual = $this->request($arrQuery, $arrTestHeader, $arrPostData); | ||
|
||
$expected = $this->getExpectedContents([ | ||
'mode' => 'hoge', | ||
TRANSACTION_ID_NAME => 'on_logic', | ||
]); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/class/fixtures/server/sc_response_sendRedirect.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {url} | ||
) | ||
shutdown |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nanasess デバッグ中に何かの都合(詳細失念)でポート番号を変更していたのですが、改めて試すと
:9999
とか、テキトーな番号でもローカルの phpunit は通るようでした。tests/class/fixtures/server/common.php で
putenv('HTTP_URL=http://127.0.0.1:8085/');
しているから、実際のポート番号は何でも良い感じでしょうか。そうなると、8085 は避けて、元の 8053 にしておくのが適切でしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここで使用するポート番号はビルトインウェブサーバーが LISTEN する番号ですので、他と被らなければ何でもいいと思います。
8085 でも OK です
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
承知いたしました。とりあえず、現状で大丈夫そうですね。
パラレル実行するときに問題となりそうなので、一応 Issue 登録しました。#964