Skip to content
Permalink
Browse files

added tests + corrections

  • Loading branch information...
JayPHP committed Apr 9, 2016
1 parent 466ecf9 commit 3a6372e69dbb4730a69ad2b1a261eb819dabd6c1
Showing with 63 additions and 14 deletions.
  1. +1 −1 src/ORM/RulesChecker.php
  2. +49 −0 tests/Fixture/LogsFixture.php
  3. +13 −13 tests/TestCase/ORM/RulesCheckerIntegrationTest.php
@@ -52,7 +52,7 @@ public function isUnique(array $fields, $message = null)
}
}
$errorField = isset($fields['errorField']) ? $fields['errorField'] : false;
$errorField = current($fields);
return $this->_addError(new IsUnique($fields), '_isUnique', compact('errorField', 'message'));
}
@@ -0,0 +1,49 @@
<?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']
];
}
@@ -29,7 +29,7 @@ class RulesCheckerIntegrationTest extends TestCase
*
* @var array
*/
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags'];
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags', 'core.logs'];
/**
* Tear down
@@ -378,22 +378,22 @@ public function testIsUniqueMultipleFields()
public function testIsUniqueCheckNull()
{
$entity = new Entity([
'name' => NULL
'log_id' => NULL
]);
$table = TableRegistry::get('Authors');
$table = TableRegistry::get('Logs');
$rules = $table->rulesChecker();
$rules->add($rules->isUnique(['name']),
$rules->add($rules->isUnique(['log_id']),
['checkNull' => true]);
$this->assertFalse($table->save($entity));
$this->assertEquals(['_isUnique' => 'This value is already in use'], $entity->errors('name'));
$this->assertEquals(['_isUnique' => 'This value is already in use'], $entity->errors('log_id'));
$entity->name = 'jose';
$entity->log_id = 4;
$this->assertSame($entity, $table->save($entity));
$entity = $table->get(1);
$entity->dirty('name', true);
$entity->dirty('log_id', true);
$this->assertSame($entity, $table->save($entity));
}
@@ -406,20 +406,20 @@ public function testIsUniqueCheckNull()
public function testIsUniqueMultipleFieldsCheckNull()
{
$entity = new Entity([
'author_id' => 1,
'title' => NULL
'log_id' => 3,
'type' => NULL
]);
$table = TableRegistry::get('Articles');
$table = TableRegistry::get('Logs');
$rules = $table->rulesChecker();
$rules->add($rules->isUnique(['title', 'author_id'], 'Nope'),
$rules->add($rules->isUnique(['log_id', 'type'], 'Nope'),
['checkNull' => true]);
$this->assertFalse($table->save($entity));
$this->assertEquals(['title' => ['_isUnique' => 'Nope']], $entity->errors());
$this->assertEquals(['log_id' => ['_isUnique' => 'Nope']], $entity->errors());
$entity->clean();
$entity->author_id = 2;
$entity->type = 'Access';
$this->assertSame($entity, $table->save($entity));
}
/**

0 comments on commit 3a6372e

Please sign in to comment.
You can’t perform that action at this time.