From 534d9362e48fce962b4671a5ec2304bd76f32326 Mon Sep 17 00:00:00 2001 From: bancer Date: Mon, 18 Mar 2019 11:50:13 +0100 Subject: [PATCH 1/6] Add extra unit tests --- .../Controller/ApplicationControllerTest.php | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 lib/Cake/Test/Case/Controller/ApplicationControllerTest.php diff --git a/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php b/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php new file mode 100644 index 000000000..8bca18274 --- /dev/null +++ b/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php @@ -0,0 +1,104 @@ +Session->id(); + return $this->redirect(array( + 'controller' => 'trans_session_id', + 'action' => 'next_step', + '?' => array( + htmlspecialchars($sessionName) => htmlspecialchars($sessionId), + ), + )); + } + +} + +/** + * ApplicationControllerTest class for testing controllers by using ControllerTestCase. + * + * ApplicationControllerTest extends ControllerTestCase in contrast + * with ControllerTest that extends CakeTestCase. + * + * @package Cake.Test.Case.Controller + */ +class ApplicationControllerTest extends ControllerTestCase { + +/** + * setupDown method + * + * @return void + */ + public function setUp() { + CakeSession::destroy(); + parent::setUp(); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + CakeSession::destroy(); + parent::tearDown(); + } + +/** + * Tests the redirect and session config with use_trans_sid=1. + */ + public function testRedirect() { + $sessionId = 'o7k64tlhil9pakp89j6d8ovlqk'; + CakeSession::id($sessionId); + $this->testAction('/trans_session_id/next'); + $this->assertContains('/trans_session_id/next_step?CAKEPHP=' . $sessionId, $this->headers['Location']); + $expectedConfig = array( + 'cookie' => 'CAKEPHP', + 'timeout' => 240, + 'ini' => array( + 'session.use_trans_sid' => 1, + 'session.cookie_path' => '/', + 'session.cookie_lifetime' => 14400, + 'session.name' => 'CAKEPHP', + 'session.gc_maxlifetime' => 14400, + 'session.cookie_httponly' => 1, + 'session.use_cookies' => 0, + 'session.use_only_cookies' => 0, + ), + 'defaults' => 'php', + 'cookieTimeout' => 240, + 'cacheLimiter' => 'must-revalidate', + ); + $actualConfig = Configure::read('Session'); + $this->assertEquals($expectedConfig, $actualConfig); + $this->assertTrue(false, __METHOD__ . ' test has been run'); + } + +} From 2fe0af9fa968502cee71fc300c63f491b320d3a9 Mon Sep 17 00:00:00 2001 From: bancer Date: Mon, 18 Mar 2019 11:52:35 +0100 Subject: [PATCH 2/6] Improve docs --- lib/Cake/Test/Case/Controller/ApplicationControllerTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php b/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php index 8bca18274..d72c7e881 100644 --- a/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php @@ -73,6 +73,8 @@ class ApplicationControllerTest extends ControllerTestCase { /** * Tests the redirect and session config with use_trans_sid=1. + * + * @return void */ public function testRedirect() { $sessionId = 'o7k64tlhil9pakp89j6d8ovlqk'; From ec3abd9089f3888605d6c07d700085d7e2323563 Mon Sep 17 00:00:00 2001 From: bancer Date: Mon, 18 Mar 2019 11:58:42 +0100 Subject: [PATCH 3/6] Add extra test to AllControllerTest --- lib/Cake/Test/Case/AllControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Test/Case/AllControllerTest.php b/lib/Cake/Test/Case/AllControllerTest.php index 8af92e8a5..e6f5644d7 100644 --- a/lib/Cake/Test/Case/AllControllerTest.php +++ b/lib/Cake/Test/Case/AllControllerTest.php @@ -38,6 +38,7 @@ class AllControllersTest extends PHPUnit_Framework_TestSuite { $suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'PagesControllerTest.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ComponentTest.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ControllerMergeVarsTest.php'); + $suite->addTestFile(CORE_TEST_CASES . DS . 'Controller' . DS . 'ApplicationControllerTest.php'); return $suite; } } From 4db38f26ca17adf3c2275e919e9c69a62ef7505d Mon Sep 17 00:00:00 2001 From: bancer Date: Mon, 18 Mar 2019 12:43:26 +0100 Subject: [PATCH 4/6] Improve unit test --- lib/Cake/Test/Case/Controller/ApplicationControllerTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php b/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php index d72c7e881..2487aa4db 100644 --- a/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ApplicationControllerTest.php @@ -34,7 +34,7 @@ class TransSessionIdController extends AppController { 'controller' => 'trans_session_id', 'action' => 'next_step', '?' => array( - htmlspecialchars($sessionName) => htmlspecialchars($sessionId), + $sessionName => $sessionId, ), )); } @@ -78,8 +78,7 @@ class ApplicationControllerTest extends ControllerTestCase { */ public function testRedirect() { $sessionId = 'o7k64tlhil9pakp89j6d8ovlqk'; - CakeSession::id($sessionId); - $this->testAction('/trans_session_id/next'); + $this->testAction('/trans_session_id/next?CAKEPHP=' . $sessionId); $this->assertContains('/trans_session_id/next_step?CAKEPHP=' . $sessionId, $this->headers['Location']); $expectedConfig = array( 'cookie' => 'CAKEPHP', @@ -100,7 +99,6 @@ class ApplicationControllerTest extends ControllerTestCase { ); $actualConfig = Configure::read('Session'); $this->assertEquals($expectedConfig, $actualConfig); - $this->assertTrue(false, __METHOD__ . ' test has been run'); } } From e6ea25cbd24ca0d3b3264faa6192e75a2dbc6ed8 Mon Sep 17 00:00:00 2001 From: bancer Date: Mon, 18 Mar 2019 13:04:09 +0100 Subject: [PATCH 5/6] Add `--verbose` to the test command --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 51342b2bc..5680314f4 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,6 @@ "@test" ], "cs-check": "./vendors/bin/phpcs -p --extensions=php --standard=CakePHP ./lib/Cake", - "test": "./lib/Cake/Console/cake test core AllTests --stderr" + "test": "./lib/Cake/Console/cake test core AllTests --stderr --verbose" } } From 81c7c6700ff8ddd2df7913f48fa4f6438e428570 Mon Sep 17 00:00:00 2001 From: bancer Date: Mon, 18 Mar 2019 13:29:02 +0100 Subject: [PATCH 6/6] Add `--verbose` to the test command in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0b7934400..87158546c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -158,7 +158,7 @@ before_script: }" > app/Config/database.php script: - - sh -c "if [ '$PHPCS' != '1' ]; then ./lib/Cake/Console/cake test core AllTests --stderr; fi" + - sh -c "if [ '$PHPCS' != '1' ]; then ./lib/Cake/Console/cake test core AllTests --stderr --verbose; fi" - sh -c "if [ '$PHPCS' = '1' ]; then vendors/bin/phpcs -p --extensions=php --standard=CakePHP ./lib/Cake; fi;" notifications: