From 7df7fefca47715dde12b8f0ed8e3072d41c1a7c3 Mon Sep 17 00:00:00 2001 From: Koji Tanaka Date: Thu, 9 Feb 2023 23:59:44 +0900 Subject: [PATCH] test: Separate FormHelperTest::testSecuredFileInput() by PHP Version. Added 'full_path' key https://www.php.net/manual/en/migration81.new-features.php#migration81.new-features.core.upload-full-path-key --- .../Test/Case/View/Helper/FormHelperTest.php | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 046919ebc..6024e39fe 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -1699,11 +1699,13 @@ class FormHelperTest extends CakeTestCase { } /** - * Tests that the correct keys are added to the field hash index + * Tests that the correct keys are added to the field hash index (For PHP < 8.1) * * @return void */ public function testSecuredFileInput() { + $this->skipIf(version_compare(PHP_VERSION, '8.1.0', '>=')); + $this->Form->request['_Token'] = array('key' => 'testKey'); $this->assertEquals(array(), $this->Form->fields); @@ -1715,6 +1717,28 @@ class FormHelperTest extends CakeTestCase { $this->assertEquals($expected, $this->Form->fields); } +/** + * Tests that the correct keys are added to the field hash index (For PHP >= 8.1) + * + * Added full_path key + * + * @see https://www.php.net/manual/en/migration81.new-features.php#migration81.new-features.core.upload-full-path-key + * @return void + */ + public function testSecuredFileInputForPhp81Plus() { + $this->skipIf(version_compare(PHP_VERSION, '8.1.0', '<')); + + $this->Form->request['_Token'] = array('key' => 'testKey'); + $this->assertEquals(array(), $this->Form->fields); + + $this->Form->file('Attachment.file'); + $expected = array( + 'Attachment.file.name', 'Attachment.file.type', 'Attachment.file.tmp_name', + 'Attachment.file.error', 'Attachment.file.size', 'Attachment.file.full_path' + ); + $this->assertEquals($expected, $this->Form->fields); + } + /** * test that multiple selects keys are added to field hash *