ソースを参照

Merge branch 'master' into 3.next

Mark Story 9 年 前
コミット
6c7a460ceb

+ 3 - 3
.github/ISSUE_TEMPLATE.md

@@ -9,12 +9,12 @@ This is a (multiple allowed):
 ### What you did
 EXPLAIN WHAT YOU DID, PREFERABLY WITH CODE EXAMPLES, HERE.
 
+### What happened
+EXPLAIN WHAT IS ACTUALLY HAPPENING, HERE.
+
 ### Expected Behavior
 EXPLAIN WHAT IS TO BE EXPECTED, HERE.
 
-### Actual Behavior
-EXPLAIN WHAT IS ACTUALLY HAPPENING, HERE.
-
 P.S. Remember, an issue is not the place to ask questions. You can use [Stack Overflow](http://stackoverflow.com/questions/tagged/cakephp)
 for that or join the #cakephp channel on irc.freenode.net, where we will be more
 than happy to help answer your questions.

+ 1 - 1
src/Controller/Component/FlashComponent.php

@@ -108,7 +108,7 @@ class FlashComponent extends Component
 
         $messages = [];
         if ($options['clear'] === false) {
-            $messages = $this->_session->read('Flash.' . $options['key']);
+            $messages = (array)$this->_session->read('Flash.' . $options['key']);
         }
 
         $messages[] = [

+ 1 - 1
src/Database/Schema/SqlserverSchema.php

@@ -186,7 +186,7 @@ class SqlserverSchema extends BaseSchema
         }
 
         // Remove quotes
-        if (preg_match("/^'(.*)'$/", $default, $matches)) {
+        if (preg_match("/^N?'(.*)'/", $default, $matches)) {
             return str_replace("''", "'", $matches[1]);
         }
 

+ 11 - 2
src/Routing/Middleware/RoutingMiddleware.php

@@ -39,8 +39,17 @@ class RoutingMiddleware
             Router::setRequestContext($request);
             $params = (array)$request->getAttribute('params', []);
             if (empty($params['controller'])) {
-                $path = $request->getUri()->getPath();
-                $request = $request->withAttribute('params', Router::parse($path, $request->getMethod()));
+                $parsedBody = $request->getParsedBody();
+                if (is_array($parsedBody) && isset($parsedBody['_method'])) {
+                    $request = $request->withMethod($parsedBody['_method']);
+                }
+                $request = $request->withAttribute(
+                    'params',
+                    Router::parse(
+                        $request->getUri()->getPath(),
+                        $request->getMethod()
+                    )
+                );
             }
         } catch (RedirectException $e) {
             return new RedirectResponse(

+ 1 - 0
src/Routing/RouteBuilder.php

@@ -302,6 +302,7 @@ class RouteBuilder
      *   make sure that your mapped methods are also in the 'only' list.
      * - 'prefix' - Define a routing prefix for the resource controller. If the current scope
      *   defines a prefix, this prefix will be appended to it.
+     * - 'connectOptions' – Custom options for connecting the routes.
      *
      * @param string $name A controller name to connect resource routes for.
      * @param array|callable $options Options to use when generating REST routes, or a callback.

+ 5 - 0
src/View/Helper/HtmlHelper.php

@@ -238,6 +238,11 @@ class HtmlHelper extends Helper
                 'description' => ['name' => 'description', 'content' => $content],
                 'robots' => ['name' => 'robots', 'content' => $content],
                 'viewport' => ['name' => 'viewport', 'content' => $content],
+                'canonical' => ['rel' => 'canonical', 'link' => $content],
+                'next' => ['rel' => 'next', 'link' => $content],
+                'prev' => ['rel' => 'prev', 'link' => $content],
+                'first' => ['rel' => 'first', 'link' => $content],
+                'last' => ['rel' => 'last', 'link' => $content]
             ];
 
             if ($type === 'icon' && $content === null) {

+ 6 - 6
tests/TestCase/Database/Schema/SqlserverSchemaTest.php

@@ -63,8 +63,8 @@ SQL;
         $table = <<<SQL
 CREATE TABLE schema_articles (
 id BIGINT PRIMARY KEY,
-title VARCHAR(20) COLLATE Japanese_Unicode_CI_AI,
-body VARCHAR(1000),
+title NVARCHAR(20) COLLATE Japanese_Unicode_CI_AI DEFAULT N'無題' COLLATE Japanese_Unicode_CI_AI,
+body NVARCHAR(1000) DEFAULT N'本文なし',
 author_id INTEGER NOT NULL,
 published BIT DEFAULT 0,
 views SMALLINT DEFAULT 0,
@@ -302,8 +302,8 @@ SQL;
             'title' => [
                 'type' => 'string',
                 'null' => true,
-                'default' => null,
-                'length' => 20,
+                'default' => '無題',
+                'length' => 40,
                 'precision' => null,
                 'comment' => null,
                 'fixed' => null,
@@ -312,8 +312,8 @@ SQL;
             'body' => [
                 'type' => 'string',
                 'null' => true,
-                'default' => null,
-                'length' => 1000,
+                'default' => '本文なし',
+                'length' => 2000,
                 'precision' => null,
                 'fixed' => null,
                 'comment' => null,

+ 18 - 0
tests/TestCase/I18n/I18nTest.php

@@ -117,6 +117,24 @@ class I18nTest extends TestCase
     }
 
     /**
+     * Test plural rules are used for non-english languages
+     *
+     * @return void
+     */
+    public function testPluralSelectionRussian()
+    {
+        $translator = I18n::translator('default', 'ru');
+        $result = $translator->translate('{0} months', ['_count' => 1, 1]);
+        $this->assertEquals('1 months ends in 1, not 11', $result);
+
+        $result = $translator->translate('{0} months', ['_count' => 2, 2]);
+        $this->assertEquals('2 months ends in 2-4, not 12-14', $result);
+
+        $result = $translator->translate('{0} months', ['_count' => 7, 7]);
+        $this->assertEquals('7 months everything else', $result);
+    }
+
+    /**
      * Tests that custom translation packages can be created on the fly and used later on
      *
      * @return void

+ 4 - 0
tests/TestCase/I18n/PluralRulesTest.php

@@ -53,6 +53,10 @@ class PluralRulesTest extends TestCase
             ['ru', 0, 2],
             ['ru', 1, 0],
             ['ru', 2, 1],
+            ['ru', 21, 0],
+            ['ru', 22, 1],
+            ['ru', 5, 2],
+            ['ru', 7, 2],
             ['sk', 0, 2],
             ['sk', 1, 0],
             ['sk', 2, 1],

+ 37 - 0
tests/TestCase/Routing/Middleware/RoutingMiddlewareTest.php

@@ -133,4 +133,41 @@ class RoutingMiddlewareTest extends TestCase
         $middleware = new RoutingMiddleware();
         $middleware($request, $response, $next);
     }
+
+    /**
+     * Test route with _method being parsed correctly.
+     *
+     * @return void
+     */
+    public function testFakedRequestMethodParsed()
+    {
+        Router::connect('/articles-patch', [
+            'controller' => 'Articles',
+            'action' => 'index',
+            '_method' => 'PATCH'
+        ]);
+        $request = ServerRequestFactory::fromGlobals(
+            [
+                'REQUEST_METHOD' => 'POST',
+                'REQUEST_URI' => '/articles-patch'
+            ],
+            null,
+            ['_method' => 'PATCH']
+        );
+        $response = new Response();
+        $next = function ($req, $res) {
+            $expected = [
+                'controller' => 'Articles',
+                'action' => 'index',
+                '_method' => 'PATCH',
+                'plugin' => null,
+                'pass' => [],
+                '_matchedRoute' => '/articles-patch'
+            ];
+            $this->assertEquals($expected, $req->getAttribute('params'));
+            $this->assertEquals('PATCH', $req->getMethod());
+        };
+        $middleware = new RoutingMiddleware();
+        $middleware($request, $response, $next);
+    }
 }

+ 10 - 10
tests/TestCase/Utility/InflectorTest.php

@@ -347,13 +347,13 @@ class InflectorTest extends TestCase
             'rules' => [],
         ]);
 
-        $this->assertEquals(Inflector::singularize('wisdom teeth'), 'wisdom tooth');
-        $this->assertEquals(Inflector::singularize('wisdom-teeth'), 'wisdom-tooth');
-        $this->assertEquals(Inflector::singularize('wisdom_teeth'), 'wisdom_tooth');
+        $this->assertEquals('wisdom tooth', Inflector::singularize('wisdom teeth'));
+        $this->assertEquals('wisdom-tooth', Inflector::singularize('wisdom-teeth'));
+        $this->assertEquals('wisdom_tooth', Inflector::singularize('wisdom_teeth'));
 
-        $this->assertEquals(Inflector::pluralize('sweet potato'), 'sweet potatoes');
-        $this->assertEquals(Inflector::pluralize('sweet-potato'), 'sweet-potatoes');
-        $this->assertEquals(Inflector::pluralize('sweet_potato'), 'sweet_potatoes');
+        $this->assertEquals('sweet potatoes', Inflector::pluralize('sweet potato'));
+        $this->assertEquals('sweet-potatoes', Inflector::pluralize('sweet-potato'));
+        $this->assertEquals('sweet_potatoes', Inflector::pluralize('sweet_potato'));
     }
 
     /**
@@ -484,14 +484,14 @@ class InflectorTest extends TestCase
         $this->assertSame('test_thing_extra', Inflector::underscore('TestThingExtra'));
         $this->assertSame('test_thing_extra', Inflector::underscore('testThingExtra'));
         $this->assertSame('test_this_thing', Inflector::underscore('test-this-thing'));
-        $this->assertSame(Inflector::underscore('testThingExtrå'), 'test_thing_extrå');
+        $this->assertSame('test_thing_extrå', Inflector::underscore('testThingExtrå'));
 
         // Identical checks test the cache code path.
         $this->assertSame('test_thing', Inflector::underscore('TestThing'));
         $this->assertSame('test_thing', Inflector::underscore('testThing'));
         $this->assertSame('test_thing_extra', Inflector::underscore('TestThingExtra'));
         $this->assertSame('test_thing_extra', Inflector::underscore('testThingExtra'));
-        $this->assertSame(Inflector::underscore('testThingExtrå'), 'test_thing_extrå');
+        $this->assertSame('test_thing_extrå', Inflector::underscore('testThingExtrå'));
 
         // Test stupid values
         $this->assertSame('', Inflector::underscore(''));
@@ -592,8 +592,8 @@ class InflectorTest extends TestCase
         $this->assertEquals('File Systems', Inflector::humanize('file_systems'));
         $this->assertSame('', Inflector::humanize(null));
         $this->assertSame('', Inflector::humanize(false));
-        $this->assertSame(Inflector::humanize('hello_wörld'), 'Hello Wörld');
-        $this->assertSame(Inflector::humanize('福岡_city'), '福岡 City');
+        $this->assertSame('Hello Wörld', Inflector::humanize('hello_wörld'));
+        $this->assertSame('福岡 City', Inflector::humanize('福岡_city'));
     }
 
     /**

+ 41 - 9
tests/TestCase/View/Helper/HtmlHelperTest.php

@@ -43,11 +43,18 @@ class HtmlHelperTest extends TestCase
     public $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/';
 
     /**
-     * html property
+     * Helper to be tested
      *
-     * @var object
+     * @var \Cake\View\Helper\HtmlHelper
      */
-    public $Html = null;
+    public $Html;
+
+    /**
+     * Mocked view
+     *
+     * @var \Cake\View\View|\PHPUnit_Framework_MockObject_MockObject
+     */
+    public $View;
 
     /**
      * setUp method
@@ -490,7 +497,6 @@ class HtmlHelperTest extends TestCase
      */
     public function testThemeAssetsInMainWebrootPath()
     {
-        $webRoot = Configure::read('App.wwwRoot');
         Configure::write('App.wwwRoot', TEST_APP . 'webroot/');
 
         $this->Html->Url->theme = 'TestTheme';
@@ -516,13 +522,10 @@ class HtmlHelperTest extends TestCase
     public function testStyle()
     {
         $result = $this->Html->style(['display' => 'none', 'margin' => '10px']);
-        $expected = 'display:none; margin:10px;';
-        $this->assertRegExp('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected);
+        $this->assertEquals('display:none; margin:10px;', $result);
 
         $result = $this->Html->style(['display' => 'none', 'margin' => '10px'], false);
-        $lines = explode("\n", $result);
-        $this->assertRegExp('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]);
-        $this->assertRegExp('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]);
+        $this->assertEquals("display:none;\nmargin:10px;", $result);
     }
 
     /**
@@ -1638,6 +1641,35 @@ class HtmlHelperTest extends TestCase
     }
 
     /**
+     * @return array
+     */
+    public function dataMetaLinksProvider()
+    {
+        return [
+            ['canonical', ['controller' => 'posts', 'action' => 'show'], '/posts/show'],
+            ['first', ['controller' => 'posts', 'action' => 'index'], '/posts'],
+            ['last', ['controller' => 'posts', 'action' => 'index', '?' => ['page' => 10]], '/posts?page=10'],
+            ['prev', ['controller' => 'posts', 'action' => 'index', '?' => ['page' => 4]], '/posts?page=4'],
+            ['next', ['controller' => 'posts', 'action' => 'index', '?' => ['page' => 6]], '/posts?page=6']
+        ];
+    }
+
+    /**
+     * test canonical and pagination meta links
+     *
+     * @param string $type
+     * @param array $url
+     * @param string $expectedUrl
+     * @dataProvider dataMetaLinksProvider
+     */
+    public function testMetaLinks($type, array $url, $expectedUrl)
+    {
+        $result = $this->Html->meta($type, $url);
+        $expected = ['link' => ['href' => $expectedUrl, 'rel' => $type]];
+        $this->assertHtml($expected, $result);
+    }
+
+    /**
      * Test generating favicon's with meta()
      *
      * @return void

+ 25 - 0
tests/test_app/TestApp/Locale/ru/default.po

@@ -0,0 +1,25 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: CakePHP Testsuite\n"
+"POT-Creation-Date: 2008-05-15 02:51-0700\n"
+"PO-Revision-Date: \n"
+"Last-Translator: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
+"Language-Team: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
+"X-Poedit-Language: RU (Three Forms of Plurals)\n"
+"X-Poedit-SourceCharset: utf-8\n"
+
+msgid "Plural Rule 1"
+msgstr "Plural Rule 7 (translated)"
+
+msgid "{0} month"
+msgid_plural "{0} months"
+msgstr[0] "{0} months ends in 1, not 11"
+msgstr[1] "{0} months ends in 2-4, not 12-14"
+msgstr[2] "{0} months everything else"
+
+#~ msgid "Plural-Forms 1"
+#~ msgstr "Plural-Forms 1 (translated)"