mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing php4 compatibility in model_read test.
This commit is contained in:
parent
3a38e0869f
commit
371ac3971a
1 changed files with 77 additions and 77 deletions
|
@ -7171,98 +7171,98 @@ class ModelReadTest extends BaseModelTest {
|
|||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testVirtualFields() {
|
||||
$this->loadFixtures('Post','Author');
|
||||
$Post = ClassRegistry::init('Post');
|
||||
$Post->virtualFields = array('two' => "1 + 1");
|
||||
$result = $Post->find('first');
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
function testVirtualFields() {
|
||||
$this->loadFixtures('Post','Author');
|
||||
$Post =& ClassRegistry::init('Post');
|
||||
$Post->virtualFields = array('two' => "1 + 1");
|
||||
$result = $Post->find('first');
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
|
||||
$Post->Author->virtualFields = array('false' => '1 = 2');
|
||||
$result = $Post->find('first');
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
$this->assertEqual($result['Author']['false'],false);
|
||||
$Post->Author->virtualFields = array('false' => '1 = 2');
|
||||
$result = $Post->find('first');
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
$this->assertEqual($result['Author']['false'], false);
|
||||
|
||||
$result = $Post->find('first',array('fields' => array('author_id')));
|
||||
$this->assertFalse(isset($result['Post']['two']));
|
||||
$this->assertFalse(isset($result['Author']['false']));
|
||||
$result = $Post->find('first',array('fields' => array('author_id')));
|
||||
$this->assertFalse(isset($result['Post']['two']));
|
||||
$this->assertFalse(isset($result['Author']['false']));
|
||||
|
||||
$result = $Post->find('first',array('fields' => array('author_id', 'two')));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
$this->assertFalse(isset($result['Author']['false']));
|
||||
$result = $Post->find('first',array('fields' => array('author_id', 'two')));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
$this->assertFalse(isset($result['Author']['false']));
|
||||
|
||||
$result = $Post->find('first',array('fields' => array('two')));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
$result = $Post->find('first',array('fields' => array('two')));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
|
||||
$Post->id = 1;
|
||||
$result = $Post->field('two');
|
||||
$this->assertEqual($result, 2);
|
||||
$Post->id = 1;
|
||||
$result = $Post->field('two');
|
||||
$this->assertEqual($result, 2);
|
||||
|
||||
$result = $Post->find('first',array(
|
||||
'conditions' => array('two' => 2),
|
||||
'limit' => 1
|
||||
));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
$result = $Post->find('first',array(
|
||||
'conditions' => array('two' => 2),
|
||||
'limit' => 1
|
||||
));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
|
||||
$result = $Post->find('first',array(
|
||||
'conditions' => array('two <' => 3),
|
||||
'limit' => 1
|
||||
));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
$result = $Post->find('first',array(
|
||||
'conditions' => array('two <' => 3),
|
||||
'limit' => 1
|
||||
));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
|
||||
$result = $Post->find('first',array(
|
||||
'conditions' => array('NOT' => array('two >' => 3)),
|
||||
'limit' => 1
|
||||
));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
$result = $Post->find('first',array(
|
||||
'conditions' => array('NOT' => array('two >' => 3)),
|
||||
'limit' => 1
|
||||
));
|
||||
$this->assertEqual($result['Post']['two'], 2);
|
||||
|
||||
$dbo =& $Post->getDataSource();
|
||||
$Post->virtualFields = array('other_field' => 'Post.id + 1');
|
||||
$result = $Post->find('first',array(
|
||||
'conditions' => array('other_field' => 3),
|
||||
'limit' => 1
|
||||
));
|
||||
$this->assertEqual($result['Post']['id'], 2);
|
||||
$dbo =& $Post->getDataSource();
|
||||
$Post->virtualFields = array('other_field' => 'Post.id + 1');
|
||||
$result = $Post->find('first',array(
|
||||
'conditions' => array('other_field' => 3),
|
||||
'limit' => 1
|
||||
));
|
||||
$this->assertEqual($result['Post']['id'], 2);
|
||||
|
||||
$Post->virtualFields = array('other_field' => 'Post.id + 1');
|
||||
$result = $Post->find('all',array(
|
||||
'fields' => array($dbo->calculate($Post, 'max',array('other_field')))
|
||||
));
|
||||
$this->assertEqual($result[0][0]['other_field'], 4);
|
||||
$Post->virtualFields = array('other_field' => 'Post.id + 1');
|
||||
$result = $Post->find('all',array(
|
||||
'fields' => array($dbo->calculate($Post, 'max',array('other_field')))
|
||||
));
|
||||
$this->assertEqual($result[0][0]['other_field'], 4);
|
||||
|
||||
ClassRegistry::flush();
|
||||
$Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'), 'Model');
|
||||
$Writing->virtualFields = array('two' => "1 + 1");
|
||||
$result = $Writing->find('first');
|
||||
$this->assertEqual($result['Writing']['two'], 2);
|
||||
|
||||
$Post->create();
|
||||
$Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
|
||||
$result = $Post->field('other_field');
|
||||
$this->assertEqual($result, 4);
|
||||
ClassRegistry::flush();
|
||||
$Writing =& ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'), 'Model');
|
||||
$Writing->virtualFields = array('two' => "1 + 1");
|
||||
$result = $Writing->find('first');
|
||||
$this->assertEqual($result['Writing']['two'], 2);
|
||||
|
||||
$Post->create();
|
||||
$Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
|
||||
$result = $Post->field('other_field');
|
||||
$this->assertEqual($result, 4);
|
||||
|
||||
ClassRegistry::flush();
|
||||
$Post = ClassRegistry::init('Post');
|
||||
ClassRegistry::flush();
|
||||
$Post =& ClassRegistry::init('Post');
|
||||
|
||||
$Post->create();
|
||||
$Post->virtualFields = array(
|
||||
'year' => 'YEAR(Post.created)',
|
||||
'unique_test_field' => 'COUNT(Post.id)'
|
||||
);
|
||||
$Post->create();
|
||||
$Post->virtualFields = array(
|
||||
'year' => 'YEAR(Post.created)',
|
||||
'unique_test_field' => 'COUNT(Post.id)'
|
||||
);
|
||||
|
||||
$expectation = array(
|
||||
'Post' => array(
|
||||
'year' => 2007,
|
||||
'unique_test_field' => 3
|
||||
)
|
||||
);
|
||||
$expectation = array(
|
||||
'Post' => array(
|
||||
'year' => 2007,
|
||||
'unique_test_field' => 3
|
||||
)
|
||||
);
|
||||
|
||||
$result = $Post->find('first', array(
|
||||
'fields' => array_keys($Post->virtualFields),
|
||||
'group' => array('year')
|
||||
));
|
||||
$result = $Post->find('first', array(
|
||||
'fields' => array_keys($Post->virtualFields),
|
||||
'group' => array('year')
|
||||
));
|
||||
|
||||
$this->assertEqual($result, $expectation);
|
||||
}
|
||||
$this->assertEqual($result, $expectation);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue