mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding failing tests for bool updates switching with the field name
This commit is contained in:
parent
4b49a287a6
commit
a5685947b9
1 changed files with 49 additions and 0 deletions
|
@ -6078,6 +6078,55 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
$result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count')));
|
$result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count')));
|
||||||
$this->assertEquals(array(6, 4, 5, 2), $result);
|
$this->assertEquals(array(6, 4, 5, 2), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testToggleBoolFields() {
|
||||||
|
$this->loadFixtures('CounterCachePost');
|
||||||
|
$Post = new CounterCachePost();
|
||||||
|
$Post->unbindModel(array('belongsTo' => array('User')), true);
|
||||||
|
|
||||||
|
$true = array('Post' => array('published' => true, 'id' => 2));
|
||||||
|
$false = array('Post' => array('published' => false, 'id' => 2));
|
||||||
|
$fields = array('Post.published', 'Post.id');
|
||||||
|
$updateConditions = array('Post.id' => 2);
|
||||||
|
|
||||||
|
// check its true
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $true);
|
||||||
|
|
||||||
|
// Testing without the alias
|
||||||
|
$this->assertTrue($Post->updateAll(array('published' => '1 - published'), $updateConditions));
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $false);
|
||||||
|
|
||||||
|
$this->assertTrue($Post->updateAll(array('published' => '1 - published'), $updateConditions));
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $true);
|
||||||
|
|
||||||
|
// Testing with the alias
|
||||||
|
$this->assertTrue($Post->updateAll(array('Post.published' => '1 - Post.published'), $updateConditions));
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $false);
|
||||||
|
|
||||||
|
$this->assertTrue($Post->updateAll(array('Post.published' => '1 - Post.published'), $updateConditions));
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $true);
|
||||||
|
|
||||||
|
$this->assertTrue($Post->updateAll(array('Post.published = 1 - Post.published'), $updateConditions));
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $false);
|
||||||
|
|
||||||
|
$this->assertTrue($Post->updateAll(array('Post.published = 1 - Post.published'), $updateConditions));
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $true);
|
||||||
|
|
||||||
|
$this->assertTrue($Post->updateAll(array('Post.published' => '! Post.published'), $updateConditions));
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $false);
|
||||||
|
|
||||||
|
$this->assertTrue($Post->updateAll(array('Post.published' => 'NOT Post.published'), $updateConditions));
|
||||||
|
$result = $Post->find('first', array('conditions' => $updateConditions, 'fields' => $fields));
|
||||||
|
$this->assertEqual($result, $true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestFindAllWithoutForeignKey
|
* TestFindAllWithoutForeignKey
|
||||||
|
|
Loading…
Reference in a new issue