Browse Source

Merge branch 'master' into 3.next

# Conflicts:
#	.travis.yml
Robert Pustułka 8 years ago
parent
commit
34a5989bd1

+ 1 - 0
.travis.yml

@@ -65,6 +65,7 @@ before_install:
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "7" ]] ; then echo "yes" | pecl install channel://pecl.php.net/apcu-5.1.5 || true; fi
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "7" ]] ; then echo "yes" | pecl install channel://pecl.php.net/apcu-5.1.5 || true; fi
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" ]] ; then echo "yes" | pecl install apcu-4.0.11 || true; fi
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" ]] ; then echo "yes" | pecl install apcu-4.0.11 || true; fi
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" && $DB = 'mysql' ]] ; then wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz; tar xf xcache-3.2.0.tar.gz; pushd xcache-3.2.0; phpize; ./configure; make; NO_INTERACTION=1 make test; make install; popd;printf "extension=xcache.so\nxcache.size=64M\nxcache.var_size=16M\nxcache.test=On" > ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" && $DB = 'mysql' ]] ; then wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz; tar xf xcache-3.2.0.tar.gz; pushd xcache-3.2.0; phpize; ./configure; make; NO_INTERACTION=1 make test; make install; popd;printf "extension=xcache.so\nxcache.size=64M\nxcache.var_size=16M\nxcache.test=On" > ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
+  - sudo locale-gen da_DK
 
 
 before_script:
 before_script:
   - composer install --prefer-dist --no-interaction
   - composer install --prefer-dist --no-interaction

+ 3 - 1
src/Console/ConsoleIo.php

@@ -209,7 +209,9 @@ class ConsoleIo
         // Store length of content + fill so if the new content
         // Store length of content + fill so if the new content
         // is shorter than the old content the next overwrite
         // is shorter than the old content the next overwrite
         // will work.
         // will work.
-        $this->_lastWritten = $newBytes + $fill;
+        if ($fill > 0) {
+            $this->_lastWritten = $newBytes + $fill;
+        }
     }
     }
 
 
     /**
     /**

+ 4 - 3
src/Database/Type/DateTimeType.php

@@ -162,11 +162,12 @@ class DateTimeType extends Type implements TypeInterface
             if ($value === '' || $value === null || $value === false || $value === true) {
             if ($value === '' || $value === null || $value === false || $value === true) {
                 return null;
                 return null;
             }
             }
-            if (is_numeric($value)) {
+            $isString = is_string($value);
+            if (ctype_digit($value)) {
                 $date = new $class('@' . $value);
                 $date = new $class('@' . $value);
-            } elseif (is_string($value) && $this->_useLocaleParser) {
+            } elseif ($isString && $this->_useLocaleParser) {
                 return $this->_parseValue($value);
                 return $this->_parseValue($value);
-            } elseif (is_string($value)) {
+            } elseif ($isString) {
                 $date = new $class($value);
                 $date = new $class($value);
                 $compare = true;
                 $compare = true;
             }
             }

+ 2 - 2
src/ORM/Association.php

@@ -498,7 +498,7 @@ abstract class Association
      * Sets the name of the field representing the binding field with the target table.
      * Sets the name of the field representing the binding field with the target table.
      * When not manually specified the primary key of the owning side table is used.
      * When not manually specified the primary key of the owning side table is used.
      *
      *
-     * @param string $key the table field to be used to link both tables together
+     * @param string|array $key the table field or fields to be used to link both tables together
      * @return $this
      * @return $this
      */
      */
     public function setBindingKey($key)
     public function setBindingKey($key)
@@ -557,7 +557,7 @@ abstract class Association
     /**
     /**
      * Sets the name of the field representing the foreign key to the target table.
      * Sets the name of the field representing the foreign key to the target table.
      *
      *
-     * @param string $key the key to be used to link both tables together
+     * @param string|array $key the key or keys to be used to link both tables together
      * @return $this
      * @return $this
      */
      */
     public function setForeignKey($key)
     public function setForeignKey($key)

+ 2 - 2
src/Routing/RouteBuilder.php

@@ -718,7 +718,7 @@ class RouteBuilder
      * ```
      * ```
      *
      *
      * Redirects /home/* to /posts/view and passes the parameters to /posts/view. Using an array as the
      * Redirects /home/* to /posts/view and passes the parameters to /posts/view. Using an array as the
-     * redirect destination allows you to use other routes to define where an URL string should be redirected to.
+     * redirect destination allows you to use other routes to define where a URL string should be redirected to.
      *
      *
      * ```
      * ```
      * $routes->redirect('/posts/*', 'http://google.com', ['status' => 302]);
      * $routes->redirect('/posts/*', 'http://google.com', ['status' => 302]);
@@ -733,7 +733,7 @@ class RouteBuilder
      *   routes that end in `*` are greedy. As you can remap URLs and not loose any passed args.
      *   routes that end in `*` are greedy. As you can remap URLs and not loose any passed args.
      *
      *
      * @param string $route A string describing the template of the route
      * @param string $route A string describing the template of the route
-     * @param array|string $url An URL to redirect to. Can be a string or a Cake array-based URL
+     * @param array|string $url A URL to redirect to. Can be a string or a Cake array-based URL
      * @param array $options An array matching the named elements in the route to regular expressions which that
      * @param array $options An array matching the named elements in the route to regular expressions which that
      *   element should match. Also contains additional parameters such as which routed parameters should be
      *   element should match. Also contains additional parameters such as which routed parameters should be
      *   shifted into the passed arguments. As well as supplying patterns for routing parameters.
      *   shifted into the passed arguments. As well as supplying patterns for routing parameters.

+ 3 - 3
src/Routing/Router.php

@@ -216,7 +216,7 @@ class Router
      * Compatibility proxy to \Cake\Routing\RouteBuilder::redirect() in the `/` scope.
      * Compatibility proxy to \Cake\Routing\RouteBuilder::redirect() in the `/` scope.
      *
      *
      * @param string $route A string describing the template of the route
      * @param string $route A string describing the template of the route
-     * @param array $url An URL to redirect to. Can be a string or a Cake array-based URL
+     * @param array $url A URL to redirect to. Can be a string or a Cake array-based URL
      * @param array $options An array matching the named elements in the route to regular expressions which that
      * @param array $options An array matching the named elements in the route to regular expressions which that
      *   element should match. Also contains additional parameters such as which routed parameters should be
      *   element should match. Also contains additional parameters such as which routed parameters should be
      *   shifted into the passed arguments. As well as supplying patterns for routing parameters.
      *   shifted into the passed arguments. As well as supplying patterns for routing parameters.
@@ -547,7 +547,7 @@ class Router
     /**
     /**
      * Finds URL for specified action.
      * Finds URL for specified action.
      *
      *
-     * Returns an URL pointing to a combination of controller and action.
+     * Returns a URL pointing to a combination of controller and action.
      *
      *
      * ### Usage
      * ### Usage
      *
      *
@@ -781,7 +781,7 @@ class Router
     }
     }
 
 
     /**
     /**
-     * Normalizes an URL for purposes of comparison.
+     * Normalizes a URL for purposes of comparison.
      *
      *
      * Will strip the base path off and replace any double /'s.
      * Will strip the base path off and replace any double /'s.
      * It will not unify the casing and underscoring of the input value.
      * It will not unify the casing and underscoring of the input value.

+ 1 - 1
src/View/Form/EntityContext.php

@@ -263,7 +263,7 @@ class EntityContext implements ContextInterface
         if (is_array($entity) || $entity instanceof ArrayAccess) {
         if (is_array($entity) || $entity instanceof ArrayAccess) {
             $key = array_pop($parts);
             $key = array_pop($parts);
 
 
-            return isset($entity[$key]) ? $entity[$key] : null;
+            return isset($entity[$key]) ? $entity[$key] : $options['default'];
         }
         }
 
 
         return null;
         return null;

+ 40 - 1
tests/TestCase/Console/ConsoleIoTest.php

@@ -337,7 +337,7 @@ class ConsoleIoTest extends TestCase
      *
      *
      * @return void
      * @return void
      */
      */
-    public function testOverwriteShorterContent()
+    public function testOverwriteWithShorterContent()
     {
     {
         $length = strlen('12345');
         $length = strlen('12345');
 
 
@@ -384,6 +384,45 @@ class ConsoleIoTest extends TestCase
     }
     }
 
 
     /**
     /**
+     * Test overwriting content with longer content
+     *
+     * @return void
+     */
+    public function testOverwriteWithLongerContent()
+    {
+        $this->out->expects($this->at(0))
+            ->method('write')
+            ->with('1')
+            ->will($this->returnValue(1));
+
+        // Backspaces
+        $this->out->expects($this->at(1))
+            ->method('write')
+            ->with(str_repeat("\x08", 1), 0)
+            ->will($this->returnValue(1));
+
+        $this->out->expects($this->at(2))
+            ->method('write')
+            ->with('123', 0)
+            ->will($this->returnValue(3));
+
+        // Backspaces
+        $this->out->expects($this->at(3))
+            ->method('write')
+            ->with(str_repeat("\x08", 3), 0)
+            ->will($this->returnValue(3));
+
+        $this->out->expects($this->at(4))
+            ->method('write')
+            ->with('12345', 0)
+            ->will($this->returnValue(5));
+
+        $this->io->out('1');
+        $this->io->overwrite('123', 0);
+        $this->io->overwrite('12345', 0);
+    }
+
+    /**
      * Tests that setLoggers works properly
      * Tests that setLoggers works properly
      *
      *
      * @return void
      * @return void

+ 38 - 3
tests/TestCase/Database/Type/TimeTypeTest.php

@@ -15,6 +15,7 @@
 namespace Cake\Test\TestCase\Database\Type;
 namespace Cake\Test\TestCase\Database\Type;
 
 
 use Cake\Database\Type\TimeType;
 use Cake\Database\Type\TimeType;
+use Cake\I18n\I18n;
 use Cake\I18n\Time;
 use Cake\I18n\Time;
 use Cake\TestSuite\TestCase;
 use Cake\TestSuite\TestCase;
 
 
@@ -26,12 +27,17 @@ class TimeTypeTest extends TestCase
     /**
     /**
      * @var \Cake\Database\Type\TimeType
      * @var \Cake\Database\Type\TimeType
      */
      */
-    public $type;
+    protected $type;
 
 
     /**
     /**
      * @var \Cake\Database\Driver
      * @var \Cake\Database\Driver
      */
      */
-    public $driver;
+    protected $driver;
+
+    /**
+     * @var string
+     */
+    protected $locale;
 
 
     /**
     /**
      * Setup
      * Setup
@@ -43,6 +49,18 @@ class TimeTypeTest extends TestCase
         parent::setUp();
         parent::setUp();
         $this->type = new TimeType();
         $this->type = new TimeType();
         $this->driver = $this->getMockBuilder('Cake\Database\Driver')->getMock();
         $this->driver = $this->getMockBuilder('Cake\Database\Driver')->getMock();
+        $this->locale = I18n::locale();
+    }
+
+    /**
+     * Teardown
+     *
+     * @return void
+     */
+    public function tearDown()
+    {
+        parent::tearDown();
+        I18n::locale($this->locale);
     }
     }
 
 
     /**
     /**
@@ -181,7 +199,7 @@ class TimeTypeTest extends TestCase
     }
     }
 
 
     /**
     /**
-     * Tests marshalling dates using the locale aware parser
+     * Tests marshalling times using the locale aware parser
      *
      *
      * @return void
      * @return void
      */
      */
@@ -196,6 +214,23 @@ class TimeTypeTest extends TestCase
     }
     }
 
 
     /**
     /**
+     * Tests marshalling times in denmark.
+     *
+     * @return void
+     */
+    public function testMarshalWithLocaleParsingDanishLocale()
+    {
+        $updated = setlocale(LC_COLLATE, 'da_DK.utf8');
+        $this->skipIf($updated === false, 'Could not set locale to da_DK.utf8, skipping test.');
+
+        I18n::locale('da_DK');
+        $this->type->useLocaleParser();
+        $expected = new Time('03:20:00');
+        $result = $this->type->marshal('03.20');
+        $this->assertEquals($expected->format('H:i'), $result->format('H:i'));
+    }
+
+    /**
      * Test that toImmutable changes all the methods to create frozen time instances.
      * Test that toImmutable changes all the methods to create frozen time instances.
      *
      *
      * @return void
      * @return void

+ 17 - 0
tests/TestCase/View/Form/EntityContextTest.php

@@ -454,6 +454,23 @@ class EntityContextTest extends TestCase
     }
     }
 
 
     /**
     /**
+     * Test default values when entity is an array.
+     *
+     * @return void
+     */
+    public function testValDefaultArray()
+    {
+        $context = new EntityContext($this->request, [
+            'entity' => new Article([
+                'prop' => ['title' => 'foo']
+            ]),
+            'table' => 'Articles',
+        ]);
+        $this->assertEquals('foo', $context->val('prop.title', ['default' => 'bar']));
+        $this->assertEquals('bar', $context->val('prop.nope', ['default' => 'bar']));
+    }
+
+    /**
      * Test reading array values from an entity.
      * Test reading array values from an entity.
      *
      *
      * @return void
      * @return void