Browse Source

Merge branch 'master' into 3.2

Mark Story 10 years ago
parent
commit
da890356ec

+ 1 - 1
src/Shell/ServerShell.php

@@ -153,7 +153,7 @@ class ServerShell extends Shell
 
         $parser->description([
             'PHP Built-in Server for CakePHP',
-            '<warning>[WARN] Don\'t use this at the production environment</warning>',
+            '<warning>[WARN] Don\'t use this in a production environment</warning>',
         ])->addOption('host', [
             'short' => 'H',
             'help' => 'ServerHost'

+ 3 - 4
src/Template/Error/missing_controller.ctp

@@ -14,7 +14,6 @@
  */
 use Cake\Core\Plugin;
 use Cake\Core\Configure;
-use Cake\Utility\Inflector;
 
 $pluginDot = empty($plugin) ? null : $plugin . '.';
 $namespace = Configure::read('App.namespace');
@@ -22,9 +21,9 @@ $prefixNs = '';
 $prefixPath = '';
 
 if (!empty($prefix)) {
-    $prefix = Inflector::camelize($prefix);
-    $prefixNs = '\\' . $prefix;
-    $prefixPath = $prefix . DS;
+    $prefix = array_map('\Cake\Utility\Inflector::camelize', explode('/', $prefix));
+    $prefixNs = '\\' . implode('\\', $prefix);
+    $prefixPath = implode(DS, $prefix) . DS;
 }
 
 if (!empty($plugin)) {

+ 27 - 0
src/TestSuite/IntegrationTestCase.php

@@ -838,4 +838,31 @@ abstract class IntegrationTestCase extends TestCase
         $result = $this->_response->cookie($name);
         $this->assertEquals($expected, $result['value'], 'Cookie data differs. ' . $message);
     }
+
+    /**
+     * Asserts cookie values which are encrypted by the
+     * CookieComponent.
+     *
+     * The difference from assertCookie() is this decrypts the cookie
+     * value like the CookieComponent for this assertion.
+     *
+     * @param string $expected The expected contents.
+     * @param string $name The cookie name.
+     * @param string|bool $encrypt Encryption mode to use.
+     * @param string|null $key Encryption key used. Defaults
+     *   to Security.salt.
+     * @param string $message The failure message that will be appended to the generated message.
+     * @return void
+     * @see CookieCryptTrait::_encrypt
+     */
+    public function assertCookieEncrypted($expected, $name, $encrypt = 'aes', $key = null, $message = '')
+    {
+        if (empty($this->_response)) {
+            $this->fail('Not response set, cannot assert cookies.');
+        }
+        $result = $this->_response->cookie($name);
+        $this->_cookieEncriptionKey = $key;
+        $result['value'] = $this->_decrypt($result['value'], $encrypt);
+        $this->assertEquals($expected, $result['value'], 'Cookie data differs. ' . $message);
+    }
 }

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

@@ -1711,6 +1711,7 @@ class FormHelper extends Helper
      * ### Options
      *
      * - `type` - Set to 'reset' for reset inputs. Defaults to 'submit'
+     * - `templateVars` - Additional template variables for the input element and its container.
      * - Other attributes will be assigned to the input element.
      *
      * @param string $caption The label appearing on the button OR if string contains :// or the
@@ -1726,7 +1727,11 @@ class FormHelper extends Helper
         if (!is_string($caption) && empty($caption)) {
             $caption = __d('cake', 'Submit');
         }
-        $options += ['type' => 'submit', 'secure' => false];
+        $options += [
+            'type' => 'submit',
+            'secure' => false,
+            'templateVars' => []
+        ];
 
         if (isset($options['name'])) {
             $this->_secure($options['secure'], $this->_secureFieldName($options['name']));
@@ -1770,10 +1775,12 @@ class FormHelper extends Helper
         $input = $this->formatTemplate('inputSubmit', [
             'type' => $type,
             'attrs' => $this->templater()->formatAttributes($options),
+            'templateVars' => $options['templateVars']
         ]);
 
         return $this->formatTemplate('submitContainer', [
-            'content' => $input
+            'content' => $input,
+            'templateVars' => $options['templateVars']
         ]);
     }
 

+ 11 - 3
src/View/View.php

@@ -40,9 +40,17 @@ use RuntimeException;
  * layout using `$this->set()`
  *
  * View class supports using plugins as themes. You can set
- * `$this->theme = 'SuperHot'` in your Controller to use plugin `SuperHot` as a
- * theme. Eg. If current action is Posts::index() then View class will look for
- * template file `plugins/SuperHot/Template/Posts/index.ctp`. If a theme template
+ *
+ * ```
+ * public function beforeRender(\Cake\Event\Event $event)
+ * {
+ *      $this->viewBuilder()->theme('SuperHot');
+ * }
+ * ```
+ *
+ * in your Controller to use plugin `SuperHot` as a theme. Eg. If current action
+ * is PostsController::index() then View class will look for template file
+ * `plugins/SuperHot/Template/Posts/index.ctp`. If a theme template
  * is not found for the current action the default app template file is used.
  *
  * @property \Cake\View\Helper\FlashHelper $Flash

+ 3 - 0
src/View/XmlView.php

@@ -141,6 +141,9 @@ class XmlView extends SerializedView
             $options['pretty'] = true;
         }
 
+        if (isset($options['return']) && strtolower($options['return']) === 'domdocument') {
+            return Xml::fromArray($data, $options)->saveXML();
+        }
         return Xml::fromArray($data, $options)->asXML();
     }
 }

+ 28 - 0
tests/TestCase/TestSuite/CookieEncryptedUsingControllerTest.php

@@ -109,4 +109,32 @@ class CookieEncryptedUsingControllerTest extends IntegrationTestCase
         $this->assertStringStartsWith('Q2FrZQ==.', $this->viewVariable('ValueFromRequest'), 'Encrypted');
         $this->assertEquals('Value of Cookie', $this->viewVariable('ValueFromCookieComponent'), 'Decrypted');
     }
+
+    /**
+     * Can AssertCookie even if the value is encrypted by
+     * the CookieComponent.
+     */
+    public function testCanAssertCookieEncrypted() {
+        $this->get('/cookie_component_test/set_cookie');
+        $this->assertCookieEncrypted('abc', 'NameOfCookie');
+    }
+
+    /**
+     * Can AssertCookie even if encrypted with the aes.
+     */
+    public function testCanAssertCookieEncryptedWithAes() {
+        $this->get('/cookie_component_test/set_cookie');
+        $this->assertCookieEncrypted('abc', 'NameOfCookie', 'aes');
+    }
+
+    /**
+     * Can AssertCookie even if encrypted with the another
+     * encrypted key.
+     */
+    public function testCanAssertCookieEncryptedWithAnotherEncryptionKey() {
+        $key = 'another salt xxxxxxxxxxxxxxxxxxx';
+        Security::salt($key);
+        $this->get('/cookie_component_test/set_cookie');
+        $this->assertCookieEncrypted('abc', 'NameOfCookie', 'aes', $key);
+    }
 }

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

@@ -581,6 +581,32 @@ class FormHelperTest extends TestCase
         ];
         $this->assertHtml($expected, $result);
     }
+    
+    /**
+     * Test using template vars in inputSubmit and submitContainer template.
+     *
+     * @return void
+     */
+    public function testSubmitTemplateVars()
+    {
+        $this->Form->templates([
+            'inputSubmit' => '<input custom="{{forinput}}" type="{{type}}"{{attrs}}/>',
+            'submitContainer' => '<div class="submit">{{content}}{{forcontainer}}</div>'
+        ]);
+        $result = $this->Form->submit('Submit', [
+            'templateVars' => [
+                'forinput' => 'in-input',
+                'forcontainer' => 'in-container'
+            ]
+        ]);
+        $expected = [
+            'div' => ['class'],
+            'input' => ['custom' => 'in-input', 'type' => 'submit', 'value' => 'Submit'],
+            'in-container',
+            '/div',
+        ];
+        $this->assertHtml($expected, $result);
+    }
 
     /**
      * test the create() method

+ 2 - 2
tests/TestCase/View/XmlViewTest.php

@@ -119,7 +119,7 @@ class XmlViewTest extends TestCase
         $Controller = new Controller($Request, $Response);
         $data = [
             '_serialize' => ['tags', 'nope'],
-            '_xmlOptions' => ['format' => 'attributes'],
+            '_xmlOptions' => ['format' => 'attributes', 'return' => 'domdocument'],
             'tags' => [
                     'tag' => [
                         [
@@ -138,7 +138,7 @@ class XmlViewTest extends TestCase
         $View = $Controller->createView();
         $result = $View->render();
 
-        $expected = Xml::build(['response' => ['tags' => $data['tags']]], $data['_xmlOptions'])->asXML();
+        $expected = Xml::build(['response' => ['tags' => $data['tags']]], $data['_xmlOptions'])->saveXML();
         $this->assertSame($expected, $result);
     }
 

+ 15 - 0
tests/test_app/TestApp/Controller/CookieComponentTestController.php

@@ -41,4 +41,19 @@ class CookieComponentTestController extends Controller
         $this->set('ValueFromRequest', $this->request->cookie('NameOfCookie'));
         $this->set('ValueFromCookieComponent', $this->Cookie->read('NameOfCookie'));
     }
+
+    /**
+     * action to set a cookie
+     *
+     * @param string|null $key Encryption key used. By defaults,
+     *   CookieComponent::_config['key'].
+     */
+    public function set_cookie($key = null)
+    {
+        $this->autoRender = false;
+        if (isset($key)) {
+            $this->Cookie->config('key', $key);
+        }
+        $this->Cookie->write('NameOfCookie', 'abc');
+    }
 }