Browse Source

Merge branch 'master' into 3.1

Mark Story 10 years ago
parent
commit
2fc2fa4d6a

+ 3 - 1
src/Controller/Component/RequestHandlerComponent.php

@@ -169,7 +169,9 @@ class RequestHandlerComponent extends Component
             return;
         }
 
-        $extensions = Router::extensions();
+        $extensions = array_unique(
+            array_merge(Router::extensions(), array_keys($this->_viewClassMap))
+        );
         foreach ($accepts as $types) {
             $ext = array_intersect($extensions, $types);
             if (!empty($ext)) {

+ 9 - 2
src/I18n/I18n.php

@@ -29,6 +29,13 @@ class I18n
 {
 
     /**
+     * Default locale
+     *
+     * @var string
+     */
+    const DEFAULT_LOCALE = 'en_US';
+
+    /**
      * The translators collection
      *
      * @var \Aura\Intl\TranslatorLocator
@@ -215,7 +222,7 @@ class I18n
 
         $current = Locale::getDefault();
         if ($current === '') {
-            $current = 'en_US';
+            $current = static::DEFAULT_LOCALE;
             Locale::setDefault($current);
         }
 
@@ -232,7 +239,7 @@ class I18n
     public static function defaultLocale()
     {
         if (static::$_defaultLocale === null) {
-            static::$_defaultLocale = Locale::getDefault() ?: 'en_US';
+            static::$_defaultLocale = Locale::getDefault() ?: static::DEFAULT_LOCALE;
         }
         return static::$_defaultLocale;
     }

+ 26 - 5
src/I18n/Number.php

@@ -27,6 +27,20 @@ class Number
 {
 
     /**
+     * Default locale
+     *
+     * @var string
+     */
+    const DEFAULT_LOCALE = 'en_US';
+
+    /**
+     * Format type to format as currency
+     *
+     * @var string
+     */
+    const FORMAT_CURRENCY = 'currency';
+
+    /**
      * A list of number formatters indexed by locale and type
      *
      * @var array
@@ -203,7 +217,7 @@ class Number
             return $options['zero'];
         }
 
-        $formatter = static::formatter(['type' => 'currency'] + $options);
+        $formatter = static::formatter(['type' => static::FORMAT_CURRENCY] + $options);
         $abs = abs($value);
         if (!empty($options['fractionSymbol']) && $abs > 0 && $abs < 1) {
             $value = $value * 100;
@@ -235,7 +249,7 @@ class Number
         }
 
         if (empty(self::$_defaultCurrency)) {
-            $locale = ini_get('intl.default_locale') ?: 'en_US';
+            $locale = ini_get('intl.default_locale') ?: static::DEFAULT_LOCALE;
             $formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
             self::$_defaultCurrency = $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
         }
@@ -249,7 +263,7 @@ class Number
      * using other methods in this class as only one formatter object needs to be
      * constructed.
      *
-     * The options array accepts the following keys:
+     * ### Options
      *
      * - `locale` - The locale name to use for formatting the number, e.g. fr_FR
      * - `type` - The formatter type to construct, set it to `currency` if you need to format
@@ -268,13 +282,13 @@ class Number
         $locale = isset($options['locale']) ? $options['locale'] : ini_get('intl.default_locale');
 
         if (!$locale) {
-            $locale = 'en_US';
+            $locale = static::DEFAULT_LOCALE;
         }
 
         $type = NumberFormatter::DECIMAL;
         if (!empty($options['type'])) {
             $type = $options['type'];
-            if ($options['type'] === 'currency') {
+            if ($options['type'] === static::FORMAT_CURRENCY) {
                 $type = NumberFormatter::CURRENCY;
             }
         }
@@ -351,6 +365,13 @@ class Number
     /**
      * Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])
      *
+     * ### Options
+     *
+     * - `type` - The formatter type to construct, set it to `currency` if you need to format
+     *    numbers representing money or a NumberFormatter constant.
+     *
+     * For all other options see formatter().
+     *
      * @param int|float $value An integer
      * @param array $options An array with options.
      * @return string

+ 11 - 5
src/Shell/Task/ExtractTask.php

@@ -106,6 +106,15 @@ class ExtractTask extends Shell
     protected $_extractCore = false;
 
     /**
+     * No welcome message.
+     *
+     * @return void
+     */
+    protected function _welcome()
+    {
+    }
+
+    /**
      * Method to interact with the User and get path selections.
      *
      * @return void
@@ -182,10 +191,6 @@ class ExtractTask extends Shell
 
         if ($this->_extractCore) {
             $this->_paths[] = CAKE;
-            $this->_exclude = array_merge($this->_exclude, [
-                CAKE . 'Test',
-                CAKE . 'Console' . DS . 'Templates'
-            ]);
         }
 
         if (isset($this->params['output'])) {
@@ -487,9 +492,10 @@ class ExtractTask extends Shell
                         $sentence .= "msgstr[1] \"\"\n\n";
                     }
 
-                    $this->_store($domain, $header, $sentence);
                     if ($domain !== 'default' && $this->_merge) {
                         $this->_store('default', $header, $sentence);
+                    } else {
+                        $this->_store($domain, $header, $sentence);
                     }
                 }
             }

+ 8 - 1
src/Validation/Validation.php

@@ -29,6 +29,13 @@ class Validation
 {
 
     /**
+     * Default locale
+     *
+     * @var string
+     */
+    const DEFAULT_LOCALE = 'en_US';
+
+    /**
      * Some complex patterns needed in multiple places
      *
      * @var array
@@ -497,7 +504,7 @@ class Validation
         }
 
         // account for localized floats.
-        $locale = ini_get('intl.default_locale') ?: 'en_US';
+        $locale = ini_get('intl.default_locale') ?: static::DEFAULT_LOCALE;
         $formatter = new NumberFormatter($locale, NumberFormatter::DECIMAL);
         $decimalPoint = $formatter->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
         $groupingSep = $formatter->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL);

+ 16 - 6
tests/TestCase/Controller/Component/RequestHandlerComponentTest.php

@@ -89,7 +89,8 @@ class RequestHandlerComponentTest extends TestCase
     {
         parent::tearDown();
         DispatcherFactory::clear();
-        $this->_init();
+        Router::reload();
+        Router::$initialized = false;
         unset($this->RequestHandler, $this->Controller);
     }
 
@@ -129,8 +130,9 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testInitializeContentTypeSettingExt()
     {
+        Router::reload();
+        Router::$initialized = true;
         $this->request->env('HTTP_ACCEPT', 'application/json');
-        Router::extensions('json', false);
 
         $this->RequestHandler->ext = null;
         $this->RequestHandler->startup(new Event('Controller.startup', $this->Controller));
@@ -144,6 +146,8 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testInitializeContentTypeWithjQueryAccept()
     {
+        Router::reload();
+        Router::$initialized = true;
         $this->request->env('HTTP_ACCEPT', 'application/json, application/javascript, */*; q=0.01');
         $this->request->env('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
         $this->RequestHandler->ext = null;
@@ -160,7 +164,8 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testInitializeContentTypeWithjQueryTextPlainAccept()
     {
-        Router::extensions('csv', false);
+        Router::reload();
+        Router::$initialized = true;
         $this->request->env('HTTP_ACCEPT', 'text/plain, */*; q=0.01');
 
         $this->RequestHandler->startup(new Event('Controller.startup', $this->Controller));
@@ -175,6 +180,8 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testInitializeContentTypeWithjQueryAcceptAndMultiplesExtensions()
     {
+        Router::reload();
+        Router::$initialized = true;
         $this->request->env('HTTP_ACCEPT', 'application/json, application/javascript, */*; q=0.01');
         $this->RequestHandler->ext = null;
         Router::extensions(['rss', 'json'], false);
@@ -190,9 +197,10 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testInitializeNoContentTypeWithSingleAccept()
     {
+        Router::reload();
+        Router::$initialized = true;
         $_SERVER['HTTP_ACCEPT'] = 'application/json, text/html, */*; q=0.01';
         $this->assertNull($this->RequestHandler->ext);
-        Router::extensions('json', false);
 
         $this->RequestHandler->startup(new Event('Controller.startup', $this->Controller));
         $this->assertNull($this->RequestHandler->ext);
@@ -232,12 +240,13 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testInitializeContentTypeWithMultipleAcceptedTypes()
     {
+        Router::reload();
+        Router::$initialized = true;
         $this->request->env(
             'HTTP_ACCEPT',
             'text/csv;q=1.0, application/json;q=0.8, application/xml;q=0.7'
         );
         $this->RequestHandler->ext = null;
-        Router::extensions(['xml', 'json'], false);
 
         $this->RequestHandler->startup(new Event('Controller.startup', $this->Controller));
         $this->assertEquals('json', $this->RequestHandler->ext);
@@ -250,12 +259,13 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testInitializeAmbiguousAndroidAccepts()
     {
+        Router::reload();
+        Router::$initialized = true;
         $this->request->env(
             'HTTP_ACCEPT',
             'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
         );
         $this->RequestHandler->ext = null;
-        Router::extensions(['html', 'xml'], false);
 
         $this->RequestHandler->startup(new Event('Controller.startup', $this->Controller));
         $this->assertNull($this->RequestHandler->ext);

+ 8 - 5
tests/TestCase/Network/RequestTest.php

@@ -1932,11 +1932,14 @@ class RequestTest extends TestCase
     public function testQuery()
     {
         $request = new Request([
-            'query' => ['foo' => 'bar']
+            'query' => ['foo' => 'bar', 'zero' => '0']
         ]);
 
         $result = $request->query('foo');
-        $this->assertEquals('bar', $result);
+        $this->assertSame('bar', $result);
+
+        $result = $request->query('zero');
+        $this->assertSame('0', $result);
 
         $result = $request->query('imaginary');
         $this->assertNull($result);
@@ -1981,9 +1984,9 @@ class RequestTest extends TestCase
         ]);
         $this->assertFalse($request->param('not_set'));
         $this->assertTrue($request->param('admin'));
-        $this->assertEquals(1, $request->param('truthy'));
-        $this->assertEquals('posts', $request->param('controller'));
-        $this->assertEquals('0', $request->param('zero'));
+        $this->assertSame(1, $request->param('truthy'));
+        $this->assertSame('posts', $request->param('controller'));
+        $this->assertSame('0', $request->param('zero'));
     }
 
     /**

+ 25 - 2
tests/TestCase/Shell/Task/ExtractTaskTest.php

@@ -72,11 +72,11 @@ class ExtractTaskTest extends TestCase
      */
     public function testExecute()
     {
-        $this->Task->interactive = false;
-
         $this->Task->params['paths'] = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Pages';
         $this->Task->params['output'] = $this->path . DS;
         $this->Task->params['extract-core'] = 'no';
+        $this->Task->params['merge'] = 'no';
+
         $this->Task->expects($this->never())->method('err');
         $this->Task->expects($this->any())->method('in')
             ->will($this->returnValue('y'));
@@ -136,6 +136,29 @@ class ExtractTaskTest extends TestCase
     }
 
     /**
+     * testExecute with merging on method
+     *
+     * @return void
+     */
+    public function testExecuteMerge()
+    {
+        $this->Task->params['paths'] = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Pages';
+        $this->Task->params['output'] = $this->path . DS;
+        $this->Task->params['extract-core'] = 'no';
+        $this->Task->params['merge'] = 'yes';
+
+        $this->Task->expects($this->never())->method('err');
+        $this->Task->expects($this->any())->method('in')
+            ->will($this->returnValue('y'));
+        $this->Task->expects($this->never())->method('_stop');
+
+        $this->Task->main();
+        $this->assertFileExists($this->path . DS . 'default.pot');
+        $this->assertFileNotExists($this->path . DS . 'cake.pot');
+        $this->assertFileNotExists($this->path . DS . 'domain.pot');
+    }
+
+    /**
      * test exclusions
      *
      * @return void