Making model tests less time dependent

This commit is contained in:
Jose Lorenzo Rodriguez 2011-10-03 14:51:07 -04:30
parent 71c73503c6
commit 0a2553cce5
3 changed files with 158 additions and 129 deletions

View file

@ -179,9 +179,10 @@ class FormAuthenticateTest extends CakeTestCase {
$expected = array( $expected = array(
'id' => 1, 'id' => 1,
'username' => 'gwoo', 'username' => 'gwoo',
'created' => '2007-03-17 01:16:23', 'created' => '2007-03-17 01:16:23'
'updated' => date('Y-m-d H:i:s')
); );
$this->assertTrue($result['updated'] >= date('Y-m-d H:i:s'));
unset($result['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
CakePlugin::unload(); CakePlugin::unload();
} }

View file

@ -1639,46 +1639,51 @@ class ModelIntegrationTest extends BaseModelTest {
'title' => 'First Post', 'title' => 'First Post',
'body' => 'First Post Body', 'body' => 'First Post Body',
'published' => 'Y', 'published' => 'Y',
'created' => '2007-03-18 10:39:23', 'created' => '2007-03-18 10:39:23'
'updated' => $ts), ),
'SomethingElse' => array( 'SomethingElse' => array(
array( array(
'id' => '1', 'id' => '1',
'title' => 'First Post', 'title' => 'First Post',
'body' => 'First Post Body', 'body' => 'First Post Body',
'published' => 'Y', 'published' => 'Y',
'created' => '2007-03-18 10:39:23', 'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31', 'updated' => '2007-03-18 10:41:31',
'JoinThing' => array( 'JoinThing' => array(
'doomed' => true, 'doomed' => true,
'something_id' => '1', 'something_id' => '1',
'something_else_id' => '1' 'something_else_id' => '1'
)), )
array( ),
'id' => '2', array(
'title' => 'Second Post', 'id' => '2',
'body' => 'Second Post Body', 'title' => 'Second Post',
'published' => 'Y', 'body' => 'Second Post Body',
'created' => '2007-03-18 10:41:23', 'published' => 'Y',
'updated' => '2007-03-18 10:43:31', 'created' => '2007-03-18 10:41:23',
'JoinThing' => array( 'updated' => '2007-03-18 10:43:31',
'doomed' => true, 'JoinThing' => array(
'something_id' => '1', 'doomed' => true,
'something_else_id' => '2' 'something_id' => '1',
)), 'something_else_id' => '2'
array( )
'id' => '3', ),
'title' => 'Third Post', array(
'body' => 'Third Post Body', 'id' => '3',
'published' => 'Y', 'title' => 'Third Post',
'created' => '2007-03-18 10:43:23', 'body' => 'Third Post Body',
'updated' => '2007-03-18 10:45:31', 'published' => 'Y',
'JoinThing' => array( 'created' => '2007-03-18 10:43:23',
'doomed' => false, 'updated' => '2007-03-18 10:45:31',
'something_id' => '1', 'JoinThing' => array(
'something_else_id' => '3' 'doomed' => false,
)))); 'something_id' => '1',
'something_else_id' => '3')
)
)
);
$this->assertTrue($result['Something']['updated'] >= $ts);
unset($result['Something']['updated']);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
} }

View file

@ -2496,18 +2496,20 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '5', 'author_id' => '5',
'title' => 'Post with Author', 'title' => 'Post with Author',
'body' => 'This post will be saved with an author', 'body' => 'This post will be saved with an author',
'published' => 'N', 'published' => 'N'
'created' => $ts,
'updated' => $ts
), ),
'Author' => array( 'Author' => array(
'id' => '5', 'id' => '5',
'user' => 'bob', 'user' => 'bob',
'password' => '5f4dcc3b5aa765d61d8327deb882cf90', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
'created' => $ts,
'updated' => $ts,
'test' => 'working' 'test' => 'working'
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts);
$this->assertTrue($result[3]['Post']['updated'] >= $ts);
$this->assertTrue($result[3]['Author']['created'] >= $ts);
$this->assertTrue($result[3]['Author']['updated'] >= $ts);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[3]['Author']['created'], $result[3]['Author']['updated']);
$this->assertEqual($result[3], $expected); $this->assertEqual($result[3], $expected);
$this->assertEqual(count($result), 4); $this->assertEqual(count($result), 4);
@ -2541,9 +2543,7 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '2', 'author_id' => '2',
'title' => 'Multi-record post 1', 'title' => 'Multi-record post 1',
'body' => 'First multi-record post', 'body' => 'First multi-record post',
'published' => 'N', 'published' => 'N'
'created' => $ts,
'updated' => $ts
)), )),
array( array(
'Post' => array( 'Post' => array(
@ -2551,10 +2551,14 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '2', 'author_id' => '2',
'title' => 'Multi-record post 2', 'title' => 'Multi-record post 2',
'body' => 'Second multi-record post', 'body' => 'Second multi-record post',
'published' => 'N', 'published' => 'N'
'created' => $ts,
'updated' => $ts
))); )));
$this->assertTrue($result[0]['Post']['created'] >= $ts);
$this->assertTrue($result[0]['Post']['updated'] >= $ts);
$this->assertTrue($result[1]['Post']['created'] >= $ts);
$this->assertTrue($result[1]['Post']['updated'] >= $ts);
unset($result[0]['Post']['created'], $result[0]['Post']['updated']);
unset($result[1]['Post']['created'], $result[1]['Post']['updated']);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$TestModel = new Comment(); $TestModel = new Comment();
@ -2577,30 +2581,22 @@ class ModelWriteTest extends BaseModelTest {
'article_id' => '2', 'article_id' => '2',
'user_id' => '2', 'user_id' => '2',
'comment' => 'New comment with attachment', 'comment' => 'New comment with attachment',
'published' => 'Y', 'published' => 'Y'
'created' => $ts,
'updated' => $ts
); );
$this->assertTrue($result[6]['Comment']['created'] >= $ts);
$this->assertTrue($result[6]['Comment']['updated'] >= $ts);
unset($result[6]['Comment']['created'], $result[6]['Comment']['updated']);
$this->assertEqual($result[6]['Comment'], $expected); $this->assertEqual($result[6]['Comment'], $expected);
$expected = array(
'id' => '7',
'article_id' => '2',
'user_id' => '2',
'comment' => 'New comment with attachment',
'published' => 'Y',
'created' => $ts,
'updated' => $ts
);
$this->assertEqual($result[6]['Comment'], $expected);
$expected = array( $expected = array(
'id' => '2', 'id' => '2',
'comment_id' => '7', 'comment_id' => '7',
'attachment' => 'some_file.tgz', 'attachment' => 'some_file.tgz'
'created' => $ts,
'updated' => $ts
); );
$this->assertTrue($result[6]['Attachment']['created'] >= $ts);
$this->assertTrue($result[6]['Attachment']['updated'] >= $ts);
unset($result[6]['Attachment']['created'], $result[6]['Attachment']['updated']);
$this->assertEqual($result[6]['Attachment'], $expected); $this->assertEqual($result[6]['Attachment'], $expected);
} }
@ -3424,9 +3420,9 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Un-Baleeted First Post', 'title' => 'Un-Baleeted First Post',
'body' => 'Not Baleeted!', 'body' => 'Not Baleeted!',
'published' => 'Y', 'published' => 'Y',
'created' => '2007-03-18 10:39:23', 'created' => '2007-03-18 10:39:23'
'updated' => $newTs )
)), ),
array( array(
'Post' => array( 'Post' => array(
'id' => '2', 'id' => '2',
@ -3434,9 +3430,9 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Just update the title', 'title' => 'Just update the title',
'body' => 'Second Post Body', 'body' => 'Second Post Body',
'published' => 'Y', 'published' => 'Y',
'created' => '2007-03-18 10:41:23', 'created' => '2007-03-18 10:41:23'
'updated' => $ts )
)), ),
array( array(
'Post' => array( 'Post' => array(
'id' => '3', 'id' => '3',
@ -3446,17 +3442,27 @@ class ModelWriteTest extends BaseModelTest {
'published' => 'Y', 'published' => 'Y',
'created' => '2007-03-18 10:43:23', 'created' => '2007-03-18 10:43:23',
'updated' => '2007-03-18 10:45:31' 'updated' => '2007-03-18 10:45:31'
)), )
),
array( array(
'Post' => array( 'Post' => array(
'id' => '4', 'id' => '4',
'author_id' => '2', 'author_id' => '2',
'title' => 'Creating a fourth post', 'title' => 'Creating a fourth post',
'body' => 'Fourth post body', 'body' => 'Fourth post body',
'published' => 'N', 'published' => 'N'
'created' => $ts, )
'updated' => $ts )
))); );
$this->assertTrue($result[0]['Post']['updated'] >= $newTs);
$this->assertTrue($result[1]['Post']['updated'] >= $newTs);
$this->assertTrue($result[3]['Post']['updated'] >= $newTs);
$this->assertTrue($result[3]['Post']['created'] >= $newTs);
unset(
$result[0]['Post']['updated'], $result[1]['Post']['updated'],
$result[3]['Post']['updated'], $result[3]['Post']['created']
);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$this->assertEqual($TestModel->validationErrors, $errors); $this->assertEqual($TestModel->validationErrors, $errors);
@ -3475,6 +3481,10 @@ class ModelWriteTest extends BaseModelTest {
$this->assertFalse($TestModel->saveAll($data, array('validate' => 'first'))); $this->assertFalse($TestModel->saveAll($data, array('validate' => 'first')));
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
unset(
$result[0]['Post']['updated'], $result[1]['Post']['updated'],
$result[3]['Post']['updated'], $result[3]['Post']['created']
);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$this->assertEqual($TestModel->validationErrors, $errors); $this->assertEqual($TestModel->validationErrors, $errors);
} }
@ -3796,18 +3806,22 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '5', 'author_id' => '5',
'title' => 'Post with Author', 'title' => 'Post with Author',
'body' => 'This post will be saved with an author', 'body' => 'This post will be saved with an author',
'published' => 'N', 'published' => 'N'
'created' => $ts,
'updated' => $ts
), ),
'Author' => array( 'Author' => array(
'id' => '5', 'id' => '5',
'user' => 'bob', 'user' => 'bob',
'password' => '5f4dcc3b5aa765d61d8327deb882cf90', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
'created' => $ts,
'updated' => $ts,
'test' => 'working' 'test' => 'working'
)); ));
$this->assertTrue($result[3]['Post']['updated'] >= $ts);
$this->assertTrue($result[3]['Post']['created'] >= $ts);
$this->assertTrue($result[3]['Author']['created'] >= $ts);
$this->assertTrue($result[3]['Author']['updated'] >= $ts);
unset(
$result[3]['Post']['updated'], $result[3]['Post']['created'],
$result[3]['Author']['updated'], $result[3]['Author']['created']
);
$this->assertEqual($result[3], $expected); $this->assertEqual($result[3], $expected);
$this->assertEqual(count($result), 4); $this->assertEqual(count($result), 4);
@ -3833,30 +3847,22 @@ class ModelWriteTest extends BaseModelTest {
'article_id' => '2', 'article_id' => '2',
'user_id' => '2', 'user_id' => '2',
'comment' => 'New comment with attachment', 'comment' => 'New comment with attachment',
'published' => 'Y', 'published' => 'Y'
'created' => $ts,
'updated' => $ts
); );
$this->assertTrue($result[6]['Comment']['updated'] >= $ts);
$this->assertTrue($result[6]['Comment']['created'] >= $ts);
unset($result[6]['Comment']['updated'], $result[6]['Comment']['created']);
$this->assertEqual($result[6]['Comment'], $expected); $this->assertEqual($result[6]['Comment'], $expected);
$expected = array(
'id' => '7',
'article_id' => '2',
'user_id' => '2',
'comment' => 'New comment with attachment',
'published' => 'Y',
'created' => $ts,
'updated' => $ts
);
$this->assertEqual($result[6]['Comment'], $expected);
$expected = array( $expected = array(
'id' => '2', 'id' => '2',
'comment_id' => '7', 'comment_id' => '7',
'attachment' => 'some_file.tgz', 'attachment' => 'some_file.tgz'
'created' => $ts,
'updated' => $ts
); );
$this->assertTrue($result[6]['Attachment']['updated'] >= $ts);
$this->assertTrue($result[6]['Attachment']['created'] >= $ts);
unset($result[6]['Attachment']['updated'], $result[6]['Attachment']['created']);
$this->assertEqual($result[6]['Attachment'], $expected); $this->assertEqual($result[6]['Attachment'], $expected);
} }
@ -3898,20 +3904,25 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '2', 'author_id' => '2',
'title' => 'Multi-record post 1', 'title' => 'Multi-record post 1',
'body' => 'First multi-record post', 'body' => 'First multi-record post',
'published' => 'N', 'published' => 'N'
'created' => $ts, )
'updated' => $ts ),
)),
array( array(
'Post' => array( 'Post' => array(
'id' => '2', 'id' => '2',
'author_id' => '2', 'author_id' => '2',
'title' => 'Multi-record post 2', 'title' => 'Multi-record post 2',
'body' => 'Second multi-record post', 'body' => 'Second multi-record post',
'published' => 'N', 'published' => 'N'
'created' => $ts, )
'updated' => $ts )
))); );
$this->assertTrue($result[0]['Post']['updated'] >= $ts);
$this->assertTrue($result[0]['Post']['created'] >= $ts);
$this->assertTrue($result[1]['Post']['updated'] >= $ts);
$this->assertTrue($result[1]['Post']['created'] >= $ts);
unset($result[0]['Post']['updated'], $result[0]['Post']['created']);
unset($result[1]['Post']['updated'], $result[1]['Post']['created']);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
} }
@ -4472,9 +4483,7 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => 1, 'author_id' => 1,
'title' => 'New Fourth Post', 'title' => 'New Fourth Post',
'body' => null, 'body' => null,
'published' => 'N', 'published' => 'N'
'created' => $ts,
'updated' => $ts
)); ));
$expected[] = array( $expected[] = array(
@ -4484,10 +4493,14 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'New Fifth Post', 'title' => 'New Fifth Post',
'body' => null, 'body' => null,
'published' => 'N', 'published' => 'N',
'created' => $ts,
'updated' => $ts
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts);
$this->assertTrue($result[3]['Post']['updated'] >= $ts);
$this->assertTrue($result[4]['Post']['created'] >= $ts);
$this->assertTrue($result[4]['Post']['updated'] >= $ts);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
// Skip the rest of the transactional tests // Skip the rest of the transactional tests
return; return;
@ -4541,9 +4554,7 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => 1, 'author_id' => 1,
'title' => 'New Fourth Post', 'title' => 'New Fourth Post',
'body' => 'Third Post Body', 'body' => 'Third Post Body',
'published' => 'N', 'published' => 'N'
'created' => $ts,
'updated' => $ts
)); ));
$expected[] = array( $expected[] = array(
@ -4552,10 +4563,14 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => 1, 'author_id' => 1,
'title' => 'Third Post', 'title' => 'Third Post',
'body' => 'Third Post Body', 'body' => 'Third Post Body',
'published' => 'N', 'published' => 'N'
'created' => $ts,
'updated' => $ts
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts);
$this->assertTrue($result[3]['Post']['updated'] >= $ts);
$this->assertTrue($result[4]['Post']['created'] >= $ts);
$this->assertTrue($result[4]['Post']['updated'] >= $ts);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
} }
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
@ -4650,9 +4665,9 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Baleeted First Post', 'title' => 'Baleeted First Post',
'body' => 'Baleeted!', 'body' => 'Baleeted!',
'published' => 'N', 'published' => 'N',
'created' => '2007-03-18 10:39:23', 'created' => '2007-03-18 10:39:23'
'updated' => $ts )
)), ),
array( array(
'Post' => array( 'Post' => array(
'id' => '2', 'id' => '2',
@ -4660,8 +4675,9 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Just update the title', 'title' => 'Just update the title',
'body' => 'Second Post Body', 'body' => 'Second Post Body',
'published' => 'Y', 'published' => 'Y',
'created' => '2007-03-18 10:41:23', 'updated' => $ts 'created' => '2007-03-18 10:41:23'
)), )
),
array( array(
'Post' => array( 'Post' => array(
'id' => '3', 'id' => '3',
@ -4678,10 +4694,17 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '2', 'author_id' => '2',
'title' => 'Creating a fourth post', 'title' => 'Creating a fourth post',
'body' => 'Fourth post body', 'body' => 'Fourth post body',
'published' => 'N', 'published' => 'N'
'created' => $ts, )
'updated' => $ts )
))); );
$this->assertTrue($result[0]['Post']['updated'] >= $ts);
$this->assertTrue($result[1]['Post']['updated'] >= $ts);
$this->assertTrue($result[3]['Post']['created'] >= $ts);
$this->assertTrue($result[3]['Post']['updated'] >= $ts);
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric');