Permalink
Browse files

Fixing php4 compatibility in model_read test.

  • Loading branch information...
1 parent 3a38e08 commit 371ac3971aa6c665a1cf51bf9fc64d05d928568b @markstory markstory committed Jan 15, 2010
Showing with 86 additions and 86 deletions.
  1. +86 −86 cake/tests/cases/libs/model/model_read.test.php
@@ -7171,98 +7171,98 @@ function testFindQueryTypeInCallbacks() {
* @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);
-
- $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', '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);
-
- $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);
+ 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);
+
+ $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('two')));
+ $this->assertEqual($result['Post']['two'], 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 <' => 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);
-
- 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');
-
- $Post->create();
- $Post->virtualFields = array(
- 'year' => 'YEAR(Post.created)',
- 'unique_test_field' => 'COUNT(Post.id)'
- );
+ $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);
- $expectation = array(
- 'Post' => array(
- 'year' => 2007,
- 'unique_test_field' => 3
- )
- );
+ ClassRegistry::flush();
+ $Post =& ClassRegistry::init('Post');
- $result = $Post->find('first', array(
- 'fields' => array_keys($Post->virtualFields),
- 'group' => array('year')
- ));
+ $Post->create();
+ $Post->virtualFields = array(
+ 'year' => 'YEAR(Post.created)',
+ 'unique_test_field' => 'COUNT(Post.id)'
+ );
- $this->assertEqual($result, $expectation);
- }
+ $expectation = array(
+ 'Post' => array(
+ 'year' => 2007,
+ 'unique_test_field' => 3
+ )
+ );
+
+ $result = $Post->find('first', array(
+ 'fields' => array_keys($Post->virtualFields),
+ 'group' => array('year')
+ ));
+
+ $this->assertEqual($result, $expectation);
+ }
}
?>

0 comments on commit 371ac39

Please sign in to comment.