Browse Source

Using pre-existing fixture + CS Fix

james.byrne 10 years ago
parent
commit
c45341845e

+ 2 - 2
src/ORM/Rule/IsUnique.php

@@ -54,7 +54,7 @@ class IsUnique
         }
 
         $permitMultipleNulls = true;
-        if(isset($options['permitMultipleNulls'])) {
+        if (isset($options['permitMultipleNulls'])) {
             $permitMultipleNulls = $options['permitMultipleNulls'] === true ? true : false;
         }
         
@@ -68,7 +68,7 @@ class IsUnique
             }
         }
 
-        if ($permitMultipleNulls) {
+        if (!$permitMultipleNulls) {
             foreach ($conditions as $key => $value) {
                 if ($value === null) {
                     $conditions[$key . ' IS'] = $value;

+ 0 - 49
tests/Fixture/LogsFixture.php

@@ -1,49 +0,0 @@
-<?php
-/**
- * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link          http://cakephp.org CakePHP(tm) Project
- * @since         1.2.0
- * @license       http://www.opensource.org/licenses/mit-license.php MIT License
- */
-namespace Cake\Test\Fixture;
-
-use Cake\TestSuite\Fixture\TestFixture;
-
-/**
- * Short description for class.
- *
- */
-class LogsFixture extends TestFixture
-{
-
-    /**
-     * fields property
-     *
-     * @var array
-     */
-    public $fields = [
-        'id' => ['type' => 'integer'],
-        'log_id' => ['type' => 'integer', 'null' => true],
-        'type' => ['type' => 'string', 'null' => true],
-        'information' => 'text',
-        '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
-    ];
-
-    /**
-     * records property
-     *
-     * @var array
-     */
-    public $records = [
-        ['log_id' => 1, 'type' => 'Action', 'information' => 'First Log Information'],
-        ['log_id' => null, 'type' => 'Change', 'information' => 'Second Log Information'],
-        ['log_id' => 3, 'type' => null, 'information' => 'Third Log Information']
-    ];
-}

+ 2 - 1
tests/Fixture/SpecialTagsFixture.php

@@ -48,6 +48,7 @@ class SpecialTagsFixture extends TestFixture
      */
     public $records = [
         ['article_id' => 1, 'tag_id' => 3, 'highlighted' => false, 'highlighted_time' => null, 'author_id' => 1],
-        ['article_id' => 2, 'tag_id' => 1, 'highlighted' => true, 'highlighted_time' => '2014-06-01 10:10:00', 'author_id' => 2]
+        ['article_id' => 2, 'tag_id' => 1, 'highlighted' => true, 'highlighted_time' => '2014-06-01 10:10:00', 'author_id' => 2],
+        ['article_id' => 10, 'tag_id' => 10, 'highlighted' => true, 'highlighted_time' => '2014-06-01 10:10:00', 'author_id' => null]
     ];
 }

+ 18 - 13
tests/TestCase/ORM/RulesCheckerIntegrationTest.php

@@ -29,7 +29,7 @@ class RulesCheckerIntegrationTest extends TestCase
      *
      * @var array
      */
-    public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags', 'core.logs'];
+    public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.special_tags'];
 
     /**
      * Tear down
@@ -378,21 +378,23 @@ class RulesCheckerIntegrationTest extends TestCase
     public function testIsUniquePermitMultipleNulls()
     {
         $entity = new Entity([
-            'log_id' => null
+            'article_id' => 11,
+            'tag_id' => 11,
+            'author_id' => null
         ]);
 
-        $table = TableRegistry::get('Logs');
+        $table = TableRegistry::get('SpecialTags');
         $rules = $table->rulesChecker();
-        $rules->add($rules->isUnique(['log_id']), ['permitMultipleNulls' => true]);
+        $rules->add($rules->isUnique(['author_id']), ['permitMultipleNulls' => false]);
 
         $this->assertFalse($table->save($entity));
-        $this->assertEquals(['_isUnique' => 'This value is already in use'], $entity->errors('log_id'));
+        $this->assertEquals(['_isUnique' => 'This value is already in use'], $entity->errors('author_id'));
 
-        $entity->log_id = 4;
+        $entity->author_id = 11;
         $this->assertSame($entity, $table->save($entity));
 
         $entity = $table->get(1);
-        $entity->dirty('log_id', true);
+        $entity->dirty('author_id', true);
         $this->assertSame($entity, $table->save($entity));
     }
 
@@ -405,19 +407,22 @@ class RulesCheckerIntegrationTest extends TestCase
     public function testIsUniqueMultipleFieldsPermitMultipleNulls()
     {
         $entity = new Entity([
-            'log_id' => 3,
-            'type' => null
+            'article_id' => 10,
+            'tag_id' => 12,
+            'author_id' => null
         ]);
 
-        $table = TableRegistry::get('Logs');
+        $table = TableRegistry::get('SpecialTags');
         $rules = $table->rulesChecker();
-        $rules->add($rules->isUnique(['log_id', 'type'], 'Nope'), ['permitMultipleNulls' => true]);
+        $rules->add($rules->isUnique(['author_id', 'article_id'], 'Nope'), ['permitMultipleNulls' => false]);
 
         $this->assertFalse($table->save($entity));
-        $this->assertEquals(['log_id' => ['_isUnique' => 'Nope']], $entity->errors());
+        $this->assertEquals(['author_id' => ['_isUnique' => 'Nope']], $entity->errors());
 
         $entity->clean();
-        $entity->type = 'Access';
+        $entity->article_id = 10;
+        $entity->tag_id = 12;
+        $entity->author_id = 12;
         $this->assertSame($entity, $table->save($entity));
     }