ソースを参照

Merge branch 'master' into 3.1

antograssiot 10 年 前
コミット
45227cecf3

+ 9 - 7
src/I18n/Number.php

@@ -253,7 +253,7 @@ class Number
      *
      * - `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
-     *    numbers representing money.
+     *    numbers representing money or a NumberFormatter constant.
      * - `places` - Number of decimal places to use. e.g. 2
      * - `precision` - Maximum Number of decimal places to use, e.g. 2
      * - `pattern` - An ICU number pattern to use for formatting the number. e.g #,###.00
@@ -272,8 +272,11 @@ class Number
         }
 
         $type = NumberFormatter::DECIMAL;
-        if (!empty($options['type']) && $options['type'] === 'currency') {
-            $type = NumberFormatter::CURRENCY;
+        if (!empty($options['type'])) {
+            $type = $options['type'];
+            if ($options['type'] === 'currency') {
+                $type = NumberFormatter::CURRENCY;
+            }
         }
 
         if (!isset(static::$_formatters[$locale][$type])) {
@@ -349,12 +352,11 @@ class Number
      * Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])
      *
      * @param int|float $value An integer
+     * @param array $options An array with options.
      * @return string
      */
-    public static function ordinal($value)
+    public static function ordinal($value, array $options = [])
     {
-        $locale = I18n::locale();
-        $formatter = new NumberFormatter($locale, NumberFormatter::ORDINAL);
-        return $formatter->format($value);
+        return static::formatter(['type' => NumberFormatter::ORDINAL] + $options)->format($value);
     }
 }

+ 4 - 0
src/ORM/Table.php

@@ -1488,7 +1488,11 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
         }
         $keys = array_fill(0, count($primary), null);
         $id = (array)$this->_newId($primary) + $keys;
+
+        // Generate primary keys preferring values in $data.
         $primary = array_combine($primary, $id);
+        $primary = array_intersect_key($data, $primary) + $primary;
+
         $filteredKeys = array_filter($primary, 'strlen');
         $data = $data + $filteredKeys;
 

+ 13 - 0
src/TestSuite/Fixture/FixtureInjector.php

@@ -21,6 +21,7 @@ use PHPUnit_Framework_AssertionFailedError;
 use PHPUnit_Framework_Test;
 use PHPUnit_Framework_TestListener;
 use PHPUnit_Framework_TestSuite;
+use PHPUnit_Framework_Warning;
 
 /**
  * Test listener used to inject a fixture manager in all tests that
@@ -97,6 +98,18 @@ class FixtureInjector implements PHPUnit_Framework_TestListener
     /**
      * Not Implemented
      *
+     * @param \PHPUnit_Framework_Test $test The test to add warnings from.
+     * @param \PHPUnit_Warning $e The warning
+     * @param float $time current time
+     * @return void
+     */
+    public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time)
+    {
+    }
+    
+    /**
+     * Not Implemented
+     *
      * @param \PHPUnit_Framework_Test $test The test case
      * @param \PHPUnit_Framework_AssertionFailedError $e The failed assertion
      * @param float $time current time

+ 3 - 2
src/View/Helper/NumberHelper.php

@@ -235,10 +235,11 @@ class NumberHelper extends Helper
      * Formats a number into locale specific ordinal suffix.
      *
      * @param int|float $value An integer
+     * @param array $options An array with options.
      * @return string formatted number
      */
-    public function ordinal($value)
+    public function ordinal($value, array $options = [])
     {
-        return $this->_engine->ordinal($value);
+        return $this->_engine->ordinal($value, $options);
     }
 }

+ 5 - 0
tests/TestCase/I18n/NumberTest.php

@@ -571,6 +571,11 @@ class NumberTest extends TestCase
         $result = $this->Number->ordinal(2);
         $this->assertEquals('2nd', $result);
 
+        $result = $this->Number->ordinal(2, [
+            'locale' => 'fr_FR'
+        ]);
+        $this->assertEquals('2e', $result);
+
         $result = $this->Number->ordinal(3);
         $this->assertEquals('3rd', $result);
 

+ 1 - 0
tests/TestCase/ORM/TableUuidTest.php

@@ -97,6 +97,7 @@ class TableUuidTest extends TestCase
         ]);
         $table = TableRegistry::get('uuiditems');
         $this->assertSame($entity, $table->save($entity));
+        $this->assertSame($id, $entity->id);
 
         $row = $table->find('all')->where(['id' => $id])->first();
         $this->assertNotEmpty($row);