From dbbed7c8ead5309ff68cd507201683986f86e93d Mon Sep 17 00:00:00 2001 From: NISHIMURA Daisuke Date: Fri, 1 Apr 2022 13:11:36 +0900 Subject: [PATCH 1/3] PHP_SELF in tests/bootstrap is no longer necessary. The problem is resolved at CakePHP 3.6.3. Remove a test added at ec4b498c16eb32c6283a14fdd610305d067674ae. Refs #893 --- tests/TestCase/Controller/PagesControllerTest.php | 13 ------------- tests/bootstrap.php | 2 -- 2 files changed, 15 deletions(-) diff --git a/tests/TestCase/Controller/PagesControllerTest.php b/tests/TestCase/Controller/PagesControllerTest.php index bf018e1157..039517624a 100644 --- a/tests/TestCase/Controller/PagesControllerTest.php +++ b/tests/TestCase/Controller/PagesControllerTest.php @@ -29,19 +29,6 @@ class PagesControllerTest extends TestCase { use IntegrationTestTrait; - /** - * testMultipleGet method - * - * @return void - */ - public function testMultipleGet() - { - $this->get('/'); - $this->assertResponseOk(); - $this->get('/'); - $this->assertResponseOk(); - } - /** * testDisplay method * diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 18a8696d85..35a98023f8 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -29,8 +29,6 @@ require dirname(__DIR__) . '/config/bootstrap.php'; -$_SERVER['PHP_SELF'] = '/'; - if (empty($_SERVER['HTTP_HOST'])) { Configure::write('App.fullBaseUrl', 'http://localhost'); } From aa06c04c62e5378c8851bf180740ccd1c2339054 Mon Sep 17 00:00:00 2001 From: NISHIMURA Daisuke Date: Fri, 1 Apr 2022 13:36:45 +0900 Subject: [PATCH 2/3] Make PagesControllerTest stable against debug mode. Run testDisplay in debug mode. Pages in this repo can only be displayed in debug mode. Do not assert normal responses at testCsrfAppliedOk. Responses may change by debug mode, but that is not a concern of this test. Assert the opposite of testCsrfAppliedError. Refs #893 --- tests/TestCase/Controller/PagesControllerTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/TestCase/Controller/PagesControllerTest.php b/tests/TestCase/Controller/PagesControllerTest.php index 039517624a..407d6d8f22 100644 --- a/tests/TestCase/Controller/PagesControllerTest.php +++ b/tests/TestCase/Controller/PagesControllerTest.php @@ -17,6 +17,7 @@ namespace App\Test\TestCase\Controller; use Cake\Core\Configure; +use Cake\TestSuite\Constraint\Response\StatusCode; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; @@ -36,6 +37,7 @@ class PagesControllerTest extends TestCase */ public function testDisplay() { + Configure::write('debug', true); $this->get('/pages/home'); $this->assertResponseOk(); $this->assertResponseContains('CakePHP'); @@ -107,7 +109,7 @@ public function testCsrfAppliedOk() $this->enableCsrfToken(); $this->post('/pages/home', ['hello' => 'world']); - $this->assertResponseCode(200); - $this->assertResponseContains('CakePHP'); + $this->assertThat(403, $this->logicalNot(new StatusCode($this->_response))); + $this->assertResponseNotContains('CSRF'); } } From 44658f3a929e512fe0bbe7c3f00ef4d9be54127d Mon Sep 17 00:00:00 2001 From: NISHIMURA Daisuke Date: Fri, 1 Apr 2022 15:48:26 +0900 Subject: [PATCH 3/3] Make ApplicationTest stable against debug mode. Make testBootstrap run in production mode, and add a case to test bootstrap in debug mode. DebugKit should not be added in production, but should be added in debug mode. Refs #893 --- tests/TestCase/ApplicationTest.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/TestCase/ApplicationTest.php b/tests/TestCase/ApplicationTest.php index 7bd3aa0591..7c42d856dc 100644 --- a/tests/TestCase/ApplicationTest.php +++ b/tests/TestCase/ApplicationTest.php @@ -17,6 +17,7 @@ namespace App\Test\TestCase; use App\Application; +use Cake\Core\Configure; use Cake\Error\Middleware\ErrorHandlerMiddleware; use Cake\Http\MiddlewareQueue; use Cake\Routing\Middleware\AssetMiddleware; @@ -33,19 +34,35 @@ class ApplicationTest extends TestCase use IntegrationTestTrait; /** - * testBootstrap + * Test bootstrap in production. * * @return void */ public function testBootstrap() { + Configure::write('debug', false); $app = new Application(dirname(dirname(__DIR__)) . '/config'); $app->bootstrap(); $plugins = $app->getPlugins(); - $this->assertTrue($plugins->has('Bake'), 'plugins has Bake'); - $this->assertTrue($plugins->has('DebugKit'), 'plugins has DebugKit'); - $this->assertTrue($plugins->has('Migrations'), 'plugins has Migrations'); + $this->assertTrue($plugins->has('Bake'), 'plugins has Bake?'); + $this->assertFalse($plugins->has('DebugKit'), 'plugins has DebugKit?'); + $this->assertTrue($plugins->has('Migrations'), 'plugins has Migrations?'); + } + + /** + * Test bootstrap add DebugKit plugin in debug mode. + * + * @return void + */ + public function testBootstrapInDebug() + { + Configure::write('debug', true); + $app = new Application(dirname(dirname(__DIR__)) . '/config'); + $app->bootstrap(); + $plugins = $app->getPlugins(); + + $this->assertTrue($plugins->has('DebugKit'), 'plugins has DebugKit?'); } /**