Browse Source

Merge branch 'master' into 3.2

Mark Story 10 years ago
parent
commit
d52ff1e466

+ 1 - 1
src/Cache/Cache.php

@@ -571,7 +571,7 @@ class Cache
      *
      * ```
      * Cache::add('cached_data', $data);
-     * ````
+     * ```
      *
      * Writing to a specific cache config:
      *

+ 4 - 4
src/Database/Expression/FunctionExpression.php

@@ -49,13 +49,13 @@ class FunctionExpression extends QueryExpression implements TypedResultInterface
      *
      * ### Examples:
      *
-     *  ``$f = new FunctionExpression('CONCAT', ['CakePHP', ' rules']);``
+     *  `$f = new FunctionExpression('CONCAT', ['CakePHP', ' rules']);`
      *
-     * Previous line will generate ``CONCAT('CakePHP', ' rules')``
+     * Previous line will generate `CONCAT('CakePHP', ' rules')`
      *
-     * ``$f = new FunctionExpression('CONCAT', ['name' => 'literal', ' rules']);``
+     * `$f = new FunctionExpression('CONCAT', ['name' => 'literal', ' rules']);`
      *
-     * Will produce ``CONCAT(name, ' rules')``
+     * Will produce `CONCAT(name, ' rules')`
      *
      * @param string $name the name of the function to be constructed
      * @param array $params list of arguments to be passed to the function

+ 20 - 21
src/Database/Query.php

@@ -442,10 +442,10 @@ class Query implements ExpressionInterface, IteratorAggregate
      * to be joined, unless the third argument is set to true.
      *
      * When no join type is specified an INNER JOIN is used by default:
-     * ``$query->join(['authors'])`` Will produce ``INNER JOIN authors ON 1 = 1``
+     * `$query->join(['authors'])` will produce `INNER JOIN authors ON 1 = 1`
      *
      * It is also possible to alias joins using the array key:
-     * ``$query->join(['a' => 'authors'])`` Will produce ``INNER JOIN authors a ON 1 = 1``
+     * `$query->join(['a' => 'authors'])`` will produce `INNER JOIN authors a ON 1 = 1`
      *
      * A join can be fully described and aliased using the array notation:
      *
@@ -709,7 +709,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * The previous example produces:
      *
-     * ``WHERE posted >= 2012-01-27 AND title LIKE 'Hello W%' AND author_id = 1``
+     * `WHERE posted >= 2012-01-27 AND title LIKE 'Hello W%' AND author_id = 1`
      *
      * Second parameter is used to specify what type is expected for each passed
      * key. Valid types can be used from the mapped with Database\Type class.
@@ -726,13 +726,13 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * The previous example produces:
      *
-     * ``WHERE author_id = 1 AND (published = 1 OR posted < '2012-02-01') AND NOT (title = 'Hello')``
+     * `WHERE author_id = 1 AND (published = 1 OR posted < '2012-02-01') AND NOT (title = 'Hello')`
      *
      * You can nest conditions using conjunctions as much as you like. Sometimes, you
      * may want to define 2 different options for the same key, in that case, you can
      * wrap each condition inside a new array:
      *
-     * ``$query->where(['OR' => [['published' => false], ['published' => true]])``
+     * `$query->where(['OR' => [['published' => false], ['published' => true]])`
      *
      * Keep in mind that every time you call where() with the third param set to false
      * (default), it will join the passed conditions to the previous stored list using
@@ -748,7 +748,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * The previous example produces:
      *
-     * ``WHERE (id != 100 OR author_id != 1) AND published = 1``
+     * `WHERE (id != 100 OR author_id != 1) AND published = 1`
      *
      * Other Query objects that be used as conditions for any field.
      *
@@ -771,7 +771,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * * The previous example produces:
      *
-     * ``WHERE title != 'Hello World' AND (id = 1 OR (id > 2 AND id < 10))``
+     * `WHERE title != 'Hello World' AND (id = 1 OR (id > 2 AND id < 10))`
      *
      * ### Conditions as strings:
      *
@@ -781,7 +781,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * The previous example produces:
      *
-     * ``WHERE articles.author_id = authors.id AND modified IS NULL``
+     * `WHERE articles.author_id = authors.id AND modified IS NULL`
      *
      * Please note that when using the array notation or the expression objects, all
      * values will be correctly quoted and transformed to the correspondent database
@@ -839,7 +839,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Produces:
      *
-     * ``WHERE (published = 0 OR published IS NULL) AND author_id = 1 AND comments_count > 10``
+     * `WHERE (published = 0 OR published IS NULL) AND author_id = 1 AND comments_count > 10`
      *
      * ```
      * $query
@@ -853,7 +853,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Generates the following conditions:
      *
-     * ``WHERE (title = 'Foo') AND (author_id = 1 OR author_id = 2)``
+     * `WHERE (title = 'Foo') AND (author_id = 1 OR author_id = 2)`
      *
      * @param string|array|ExpressionInterface|callback $conditions The conditions to add with AND.
      * @param array $types associative array of type names used to bind values to query
@@ -891,7 +891,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Will produce:
      *
-     * ``WHERE title = 'Hello World' OR title = 'Foo'``
+     * `WHERE title = 'Hello World' OR title = 'Foo'`
      *
      * ```
      * $query
@@ -901,7 +901,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Produces:
      *
-     * ``WHERE (published = 0 OR published IS NULL) OR (author_id = 1 AND comments_count > 10)``
+     * `WHERE (published = 0 OR published IS NULL) OR (author_id = 1 AND comments_count > 10)`
      *
      * ```
      * $query
@@ -915,7 +915,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Generates the following conditions:
      *
-     * ``WHERE (title = 'Foo') OR (author_id = 1 OR author_id = 2)``
+     * `WHERE (title = 'Foo') OR (author_id = 1 OR author_id = 2)`
      *
      * @param string|array|ExpressionInterface|callback $conditions The conditions to add with OR.
      * @param array $types associative array of type names used to bind values to query
@@ -950,7 +950,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Produces:
      *
-     * ``ORDER BY title DESC, author_id ASC``
+     * `ORDER BY title DESC, author_id ASC`
      *
      * ```
      * $query->order(['title' => 'DESC NULLS FIRST'])->order('author_id');
@@ -958,7 +958,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Will generate:
      *
-     * ``ORDER BY title DESC NULLS FIRST, author_id``
+     * `ORDER BY title DESC NULLS FIRST, author_id`
      *
      * ```
      * $expression = $query->newExpr()->add(['id % 2 = 0']);
@@ -967,7 +967,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Will become:
      *
-     * ``ORDER BY (id %2 = 0), title ASC``
+     * `ORDER BY (id %2 = 0), title ASC`
      *
      * If you need to set complex expressions as order conditions, you
      * should use `orderAsc()` or `orderDesc()`.
@@ -1106,7 +1106,7 @@ class Query implements ExpressionInterface, IteratorAggregate
     /**
      * Connects any previously defined set of conditions to the provided list
      * using the AND operator in the HAVING clause. This method operates in exactly
-     * the same way as the method ``andWhere()`` does. Please refer to its
+     * the same way as the method `andWhere()` does. Please refer to its
      * documentation for an insight on how to using each parameter.
      *
      * @param string|array|ExpressionInterface|callback $conditions The AND conditions for HAVING.
@@ -1123,7 +1123,7 @@ class Query implements ExpressionInterface, IteratorAggregate
     /**
      * Connects any previously defined set of conditions to the provided list
      * using the OR operator in the HAVING clause. This method operates in exactly
-     * the same way as the method ``orWhere()`` does. Please refer to its
+     * the same way as the method `orWhere()` does. Please refer to its
      * documentation for an insight on how to using each parameter.
      *
      * @param string|array|ExpressionInterface|callback $conditions The OR conditions for HAVING.
@@ -1241,7 +1241,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Will produce:
      *
-     * ``SELECT id, name FROM things d UNION SELECT id, title FROM articles a``
+     * `SELECT id, name FROM things d UNION SELECT id, title FROM articles a`
      *
      * @param string|Query $query full SQL query to be used in UNION operator
      * @param bool $overwrite whether to reset the list of queries to be operated or not
@@ -1275,7 +1275,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      *
      * Will produce:
      *
-     * ``SELECT id, name FROM things d UNION ALL SELECT id, title FROM articles a``
+     * `SELECT id, name FROM things d UNION ALL SELECT id, title FROM articles a`
      *
      * @param string|Query $query full SQL query to be used in UNION operator
      * @param bool $overwrite whether to reset the list of queries to be operated or not
@@ -1478,7 +1478,6 @@ class Query implements ExpressionInterface, IteratorAggregate
      * any format accepted by \Cake\Database\Expression\QueryExpression:
      *
      * ```
-     *
      * $expression = $query->newExpr(); // Returns an empty expression object
      * $expression = $query->newExpr('Table.column = Table2.column'); // Return a raw SQL expression
      * ```

+ 9 - 9
src/Datasource/QueryInterface.php

@@ -199,7 +199,7 @@ interface QueryInterface
      *
      * Produces:
      *
-     * ``ORDER BY title DESC, author_id ASC``
+     * `ORDER BY title DESC, author_id ASC`
      *
      * ```
      * $query->order(['title' => 'DESC NULLS FIRST'])->order('author_id');
@@ -207,7 +207,7 @@ interface QueryInterface
      *
      * Will generate:
      *
-     * ``ORDER BY title DESC NULLS FIRST, author_id``
+     * `ORDER BY title DESC NULLS FIRST, author_id`
      *
      * ```
      * $expression = $query->newExpr()->add(['id % 2 = 0']);
@@ -216,7 +216,7 @@ interface QueryInterface
      *
      * Will become:
      *
-     * ``ORDER BY (id %2 = 0), title ASC``
+     * `ORDER BY (id %2 = 0), title ASC`
      *
      * If you need to set complex expressions as order conditions, you
      * should use `orderAsc()` or `orderDesc()`.
@@ -286,7 +286,7 @@ interface QueryInterface
      *
      * The previous example produces:
      *
-     * ``WHERE posted >= 2012-01-27 AND title LIKE 'Hello W%' AND author_id = 1``
+     * `WHERE posted >= 2012-01-27 AND title LIKE 'Hello W%' AND author_id = 1`
      *
      * Second parameter is used to specify what type is expected for each passed
      * key. Valid types can be used from the mapped with Database\Type class.
@@ -303,13 +303,13 @@ interface QueryInterface
      *
      * The previous example produces:
      *
-     * ``WHERE author_id = 1 AND (published = 1 OR posted < '2012-02-01') AND NOT (title = 'Hello')``
+     * `WHERE author_id = 1 AND (published = 1 OR posted < '2012-02-01') AND NOT (title = 'Hello')`
      *
      * You can nest conditions using conjunctions as much as you like. Sometimes, you
      * may want to define 2 different options for the same key, in that case, you can
      * wrap each condition inside a new array:
      *
-     * ``$query->where(['OR' => [['published' => false], ['published' => true]])``
+     * `$query->where(['OR' => [['published' => false], ['published' => true]])`
      *
      * Keep in mind that every time you call where() with the third param set to false
      * (default), it will join the passed conditions to the previous stored list using
@@ -325,7 +325,7 @@ interface QueryInterface
      *
      * The previous example produces:
      *
-     * ``WHERE (id != 100 OR author_id != 1) AND published = 1``
+     * `WHERE (id != 100 OR author_id != 1) AND published = 1`
      *
      * Other Query objects that be used as conditions for any field.
      *
@@ -348,7 +348,7 @@ interface QueryInterface
      *
      * * The previous example produces:
      *
-     * ``WHERE title != 'Hello World' AND (id = 1 OR (id > 2 AND id < 10))``
+     * `WHERE title != 'Hello World' AND (id = 1 OR (id > 2 AND id < 10))`
      *
      * ### Conditions as strings:
      *
@@ -358,7 +358,7 @@ interface QueryInterface
      *
      * The previous example produces:
      *
-     * ``WHERE articles.author_id = authors.id AND modified IS NULL``
+     * `WHERE articles.author_id = authors.id AND modified IS NULL`
      *
      * Please note that when using the array notation or the expression objects, all
      * values will be correctly quoted and transformed to the correspondent database

+ 16 - 6
src/TestSuite/TestCase.php

@@ -437,7 +437,11 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
         foreach ($regex as $i => $assertion) {
             $matches = false;
             if (isset($assertion['attrs'])) {
-                $string = $this->_assertAttributes($assertion, $string);
+                $string = $this->_assertAttributes($assertion, $string, $fullDebug, $regex);
+                if ($fullDebug === true && $string === false) {
+                    debug($string, true);
+                    debug($regex, true);
+                }
                 continue;
             }
 
@@ -451,11 +455,11 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
                 }
             }
             if (!$matches) {
-                $this->assertRegExp($expression, $string, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description));
-                if ($fullDebug) {
-                    debug($string, true);
-                    debug($regex, true);
+                if ($fullDebug === true) {
+                    debug($string);
+                    debug($regex);
                 }
+                $this->assertRegExp($expression, $string, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description));
                 return false;
             }
         }
@@ -469,9 +473,11 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
      *
      * @param array $assertions Assertions to run.
      * @param string $string The HTML string to check.
+     * @param bool $fullDebug Whether or not more verbose output should be used.
+     * @param array $regex Full regexp from `assertHtml`
      * @return string
      */
-    protected function _assertAttributes($assertions, $string)
+    protected function _assertAttributes($assertions, $string, $fullDebug = false, $regex = '')
     {
         $asserts = $assertions['attrs'];
         $explains = $assertions['explains'];
@@ -488,6 +494,10 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
                 }
             }
             if ($matches === false) {
+                if ($fullDebug === true) {
+                    debug($string);
+                    debug($regex);
+                }
                 $this->assertTrue(false, 'Attribute did not match. Was expecting ' . $explains[$j]);
             }
             $len = count($asserts);

+ 1 - 1
src/View/Helper/TextHelper.php

@@ -127,7 +127,7 @@ class TextHelper extends Helper
             $text
         );
         $text = preg_replace_callback(
-            '#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://)www\.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
+            '#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://)www\.[^\s\n\%\ <]+[^\s<\n\%\,\.\ <](?<!\))#i',
             [&$this, '_insertPlaceHolder'],
             $text
         );

+ 1 - 1
src/View/ViewVarsTrait.php

@@ -123,7 +123,7 @@ trait ViewVarsTrait
      * Saves a variable or an associative array of variables for use inside a template.
      *
      * @param string|array $name A string or an array of data.
-     * @param string|array|null $value Value in case $name is a string (which then works as the key).
+     * @param string|array|null|bool $value Value in case $name is a string (which then works as the key).
      *   Unused if $name is an associative array, otherwise serves as the values to $name's keys.
      * @return $this
      */

+ 27 - 1
tests/TestCase/View/Helper/FormHelperTest.php

@@ -581,7 +581,33 @@ class FormHelperTest extends TestCase
         ];
         $this->assertHtml($expected, $result);
     }
-    
+
+    /**
+     * Test ensuring template variables work in template files loaded
+     * during input().
+     *
+     * @return void
+     */
+    public function testInputTemplatesFromFile()
+    {
+        $result = $this->Form->input('title', [
+            'templates' => 'test_templates',
+            'templateVars' => [
+                'forcontainer' => 'container-data'
+            ]
+        ]);
+        $expected = [
+            'div' => ['class'],
+            'label' => ['for'],
+            'Title',
+            '/label',
+            'input' => ['name', 'type' => 'text', 'id'],
+            'container-data',
+            '/div',
+        ];
+        $this->assertHtml($expected, $result);
+    }
+
     /**
      * Test using template vars in inputSubmit and submitContainer template.
      *

+ 4 - 0
tests/TestCase/View/Helper/TextHelperTest.php

@@ -338,6 +338,10 @@ class TextHelperTest extends TestCase
                 'Text with a partial http://www.küchenschöhn-not-working.de URL',
                 'Text with a partial <a href="http://www.küchenschöhn-not-working.de">http://www.küchenschöhn-not-working.de</a> URL'
             ],
+            [
+                "Text with partial www.cakephp.org\r\nwww.cakephp.org urls and CRLF",
+                "Text with partial <a href=\"http://www.cakephp.org\">www.cakephp.org</a>\r\n<a href=\"http://www.cakephp.org\">www.cakephp.org</a> urls and CRLF"
+            ]
         ];
     }
 

+ 1 - 0
tests/test_app/config/test_templates.php

@@ -4,4 +4,5 @@
  */
 return [
     'link' => '<a href="{{url}}">{{text}}</a>',
+    'inputContainer' => '<div class="input {{type}}{{required}}">{{content}}{{forcontainer}}</div>'
 ];