ソースを参照

Merge branch '4.next' into 5.x

ADmad 2 年 前
コミット
ee4f1e87d4

+ 1 - 0
composer.json

@@ -71,6 +71,7 @@
     "provide": {
         "psr/container-implementation": "^2.0",
         "psr/http-client-implementation": "^1.0",
+        "psr/http-factory-implementation": "^1.0",
         "psr/http-server-handler-implementation": "^1.0",
         "psr/http-server-middleware-implementation": "^1.0",
         "psr/log-implementation": "^3.0",

+ 6 - 1
src/Core/functions.php

@@ -270,7 +270,12 @@ function deprecationWarning(string $version, string $message, int $stackFrame =
         $frame = $trace[$stackFrame];
         $frame += ['file' => '[internal]', 'line' => '??'];
 
-        $relative = str_replace(DIRECTORY_SEPARATOR, '/', substr($frame['file'], strlen(ROOT) + 1));
+        // Assuming we're installed in vendor/cakephp/cakephp/src/Core/functions.php
+        $root = dirname(__DIR__, 5);
+        if (defined('ROOT')) {
+            $root = ROOT;
+        }
+        $relative = str_replace(DIRECTORY_SEPARATOR, '/', substr($frame['file'], strlen($root) + 1));
         $patterns = (array)Configure::read('Error.ignoredDeprecationPaths');
         foreach ($patterns as $pattern) {
             $pattern = str_replace(DIRECTORY_SEPARATOR, '/', $pattern);

+ 16 - 0
src/TestSuite/IntegrationTestTrait.php

@@ -1270,6 +1270,22 @@ trait IntegrationTestTrait
     }
 
     /**
+     * Asserts that a cookie is set.
+     *
+     * Useful when you're working with cookies that have obfuscated values
+     * but the cookie being set is important.
+     *
+     * @param string $name The cookie name.
+     * @param string $message The failure message that will be appended to the generated message.
+     * @return void
+     */
+    public function assertCookieIsSet(string $name, string $message = ''): void
+    {
+        $verboseMessage = $this->extractVerboseMessage($message);
+        $this->assertThat($name, new CookieSet($this->_response), $verboseMessage);
+    }
+
+    /**
      * Asserts a cookie has not been set in the response
      *
      * @param string $cookie The cookie name to check

+ 2 - 0
src/View/Helper/FormHelper.php

@@ -1131,6 +1131,7 @@ class FormHelper extends Helper
             'content' => $result,
             'error' => $error,
             'errorSuffix' => $errorSuffix,
+            'label' => $label,
             'options' => $options,
         ]);
 
@@ -1178,6 +1179,7 @@ class FormHelper extends Helper
         return $this->formatTemplate($inputContainerTemplate, [
             'content' => $options['content'],
             'error' => $options['error'],
+            'label' => $options['label'] ?? '',
             'required' => $options['options']['required'] ? ' ' . $this->templater()->get('requiredClass') : '',
             'type' => $options['options']['type'],
             'templateVars' => $options['options']['templateVars'] ?? [],

+ 31 - 0
tests/TestCase/TestSuite/IntegrationTestTraitTest.php

@@ -768,6 +768,37 @@ class IntegrationTestTraitTest extends TestCase
     }
 
     /**
+     * Tests assertCookieIsSet assertion
+     */
+    public function testAssertCookieIsSet(): void
+    {
+        $this->get('/posts/secretCookie');
+        $this->assertCookieIsSet('secrets');
+    }
+
+    /**
+     * Tests the failure message for assertCookieIsSet
+     */
+    public function testCookieIsSetFailure(): void
+    {
+        $this->expectException(AssertionFailedError::class);
+        $this->expectExceptionMessage('Failed asserting that \'not-secrets\' cookie is set');
+        $this->post('/posts/secretCookie');
+        $this->assertCookieIsSet('not-secrets');
+    }
+
+    /**
+     * Tests the failure message for assertCookieIsSet when no
+     * response whas generated
+     */
+    public function testCookieIsSetFailureNoResponse(): void
+    {
+        $this->expectException(AssertionFailedError::class);
+        $this->expectExceptionMessage('No response set, cannot assert content.');
+        $this->assertCookieIsSet('secrets');
+    }
+
+    /**
      * Test error handling and error page rendering.
      */
     public function testPostAndErrorHandling(): void

+ 21 - 0
tests/TestCase/View/Helper/FormHelperTest.php

@@ -2783,6 +2783,27 @@ class FormHelperTest extends TestCase
         ];
         $this->assertHtml($expected, $result);
 
+        $result = $this->Form->control('Contact.email', [
+            'templates' => [
+                'formGroup' => '{{input}}',
+                'inputContainer' => '<div><div>{{label}}</div>{{content}}</div>',
+            ],
+        ]);
+        $expected = [
+            '<div',
+            '<div',
+            'label' => ['for' => 'contact-email'],
+            'Email',
+            '/label',
+            '/div',
+            ['input' => [
+                'type' => 'email', 'name' => 'Contact[email]',
+                'id' => 'contact-email', 'maxlength' => 255,
+            ]],
+            '/div',
+        ];
+        $this->assertHtml($expected, $result);
+
         $result = $this->Form->control('Contact.email', ['type' => 'text']);
         $expected = [
             'div' => ['class' => 'input text'],