Browse Source

Merge branch 'master' into 4.next

Mark Story 5 years ago
parent
commit
0e6d770751

+ 0 - 2
.github/workflows/ci.yml

@@ -106,8 +106,6 @@ jobs:
 
         if [[ ${{ matrix.php-version }} == '7.2' ]]; then
           vendor/bin/phpunit
-        elif [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'mysql' ]]; then
-          vendor/bin/phpunit --teamcity --verbose
         else
           vendor/bin/phpunit --verbose
         fi

+ 10 - 5
src/Database/Type/BinaryUuidType.php

@@ -36,15 +36,20 @@ class BinaryUuidType extends BaseType
      *
      * @param mixed $value The value to convert.
      * @param \Cake\Database\DriverInterface $driver The driver instance to convert with.
-     * @return string|resource
+     * @return string|resource|null
      */
     public function toDatabase($value, DriverInterface $driver)
     {
-        if (is_string($value)) {
-            return $this->convertStringToBinaryUuid($value);
+        if (!is_string($value)) {
+            return $value;
         }
 
-        return $value;
+        $length = strlen($value);
+        if ($length !== 36 && $length !== 32) {
+            return null;
+        }
+
+        return $this->convertStringToBinaryUuid($value);
     }
 
     /**
@@ -126,7 +131,7 @@ class BinaryUuidType extends BaseType
     }
 
     /**
-     * Converts a string uuid to a binary representation
+     * Converts a string UUID (36 or 32 char) to a binary representation.
      *
      * @param string $string The value to convert.
      * @return string Converted value.

+ 1 - 1
src/Http/Middleware/CsrfProtectionMiddleware.php

@@ -55,7 +55,7 @@ class CsrfProtectionMiddleware implements MiddlewareInterface
      *    Defaults to browser session.
      *  - `secure` Whether or not the cookie will be set with the Secure flag. Defaults to false.
      *  - `httponly` Whether or not the cookie will be set with the HttpOnly flag. Defaults to false.
-     *  - 'samesite' "SameSite" attribute for cookies. Defaults to `null`.
+     *  - `samesite` "SameSite" attribute for cookies. Defaults to `null`.
      *    Valid values: `CookieInterface::SAMESITE_LAX`, `CookieInterface::SAMESITE_STRICT`,
      *    `CookieInterface::SAMESITE_NONE` or `null`.
      *  - `field` The form field to check. Changing this will also require configuring

+ 2 - 1
src/ORM/Behavior/Translate/ShadowTableStrategy.php

@@ -99,7 +99,8 @@ class ShadowTableStrategy implements TranslateStrategyInterface
     {
         $config = $this->getConfig();
 
-        $this->table->hasMany($config['translationTable'], [
+        $targetAlias = $this->translationTable->getAlias();
+        $this->table->hasMany($targetAlias, [
             'className' => $config['translationTable'],
             'foreignKey' => 'id',
             'strategy' => $config['strategy'],

+ 8 - 2
src/ORM/Locator/TableLocator.php

@@ -160,8 +160,14 @@ class TableLocator extends AbstractLocator implements LocatorInterface
      */
     protected function createInstance(string $alias, array $options)
     {
-        [, $classAlias] = pluginSplit($alias);
-        $options = ['alias' => $classAlias] + $options;
+        if (strpos($alias, '\\') === false) {
+            [, $classAlias] = pluginSplit($alias);
+            $options = ['alias' => $classAlias] + $options;
+        } elseif (!isset($options['alias'])) {
+            $options['className'] = $alias;
+            /** @psalm-suppress PossiblyFalseOperand */
+            $alias = substr($alias, strrpos($alias, '\\') + 1, -5);
+        }
 
         if (isset($this->_config[$alias])) {
             $options += $this->_config[$alias];

+ 0 - 3
src/ORM/TableRegistry.php

@@ -55,9 +55,6 @@ use Cake\ORM\Locator\LocatorInterface;
  * // Prior to 3.6.0
  * $table = TableRegistry::get('Users', $config);
  * ```
- *
- * @deprecated 4.1.0 Use {@see \Cake\ORM\Locator\LocatorAwareTrait::getTableLocator()}
- *   or \Cake\Datasource\FactoryLocator::get('Table') to get the table locator instance instead.
  */
 class TableRegistry
 {

+ 12 - 0
tests/TestCase/Database/Type/BinaryUuidTypeTest.php

@@ -104,6 +104,18 @@ class BinaryUuidTypeTest extends TestCase
     }
 
     /**
+     * Test converting to database format fails
+     *
+     * @return void
+     */
+    public function testToDatabaseInvalid()
+    {
+        $value = 'mUMPWUxCpaCi685A9fEwJZ';
+        $result = $this->type->toDatabase($value, $this->driver);
+        $this->assertNull($result);
+    }
+
+    /**
      * Test that the PDO binding type is correct.
      *
      * @return void

+ 1 - 1
tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php

@@ -91,7 +91,7 @@ class TranslateBehaviorTest extends TestCase
         $items = $table->associations();
         $i18n = $items->getByProperty('_i18n');
 
-        $this->assertSame(CustomI18nTable::class, $i18n->getName());
+        $this->assertSame('CustomI18n', $i18n->getName());
         $this->assertInstanceOf(CustomI18nTable::class, $i18n->getTarget());
         $this->assertSame('test_custom_i18n_datasource', $i18n->getTarget()->getConnection()->configName());
         $this->assertSame('custom_i18n_table', $i18n->getTarget()->getTable());

+ 4 - 0
tests/TestCase/ORM/Locator/TableLocatorTest.php

@@ -22,6 +22,7 @@ use Cake\ORM\Table;
 use Cake\TestSuite\TestCase;
 use Cake\Validation\Validator;
 use TestApp\Infrastructure\Table\AddressesTable;
+use TestApp\Model\Table\ArticlesTable;
 use TestApp\Model\Table\MyUsersTable;
 use TestPlugin\Infrastructure\Table\AddressesTable as PluginAddressesTable;
 
@@ -190,6 +191,9 @@ class TableLocatorTest extends TestCase
         $this->assertSame('my_articles', $result->getTable());
 
         $this->assertSame($this->_locator, $result->associations()->getTableLocator());
+
+        $result = $this->_locator->get(ArticlesTable::class);
+        $this->assertSame('Articles', $result->getAlias());
     }
 
     /**