created, modified and updated fields now use static timestamp in testcases

This commit is contained in:
Ceeram 2012-03-28 17:49:41 +02:00
parent dec67ef259
commit f0bd7386e2
7 changed files with 124 additions and 96 deletions

View file

@ -1629,7 +1629,7 @@ class Model extends Object implements CakeEventListener {
if (!array_key_exists('format', $colType)) { if (!array_key_exists('format', $colType)) {
$time = strtotime('now'); $time = strtotime('now');
} else { } else {
$time = $colType['formatter']($colType['format']); $time = call_user_func($colType['formatter'], $colType['format']);
} }
if (!empty($this->whitelist)) { if (!empty($this->whitelist)) {
$this->whitelist[] = $updateCol; $this->whitelist[] = $updateCol;

View file

@ -163,7 +163,6 @@ class FormAuthenticateTest extends CakeTestCase {
), App::RESET); ), App::RESET);
CakePlugin::load('TestPlugin'); CakePlugin::load('TestPlugin');
$ts = date('Y-m-d H:i:s');
$PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser'); $PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser');
$user['id'] = 1; $user['id'] = 1;
$user['username'] = 'gwoo'; $user['username'] = 'gwoo';
@ -185,7 +184,7 @@ class FormAuthenticateTest extends CakeTestCase {
'username' => 'gwoo', 'username' => 'gwoo',
'created' => '2007-03-17 01:16:23' 'created' => '2007-03-17 01:16:23'
); );
$this->assertTrue($result['updated'] >= $ts); $this->assertEquals(self::date(), $result['updated']);
unset($result['updated']); unset($result['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
CakePlugin::unload(); CakePlugin::unload();

View file

@ -1867,7 +1867,6 @@ class ModelIntegrationTest extends BaseModelTest {
'doomed' => true 'doomed' => true
)))); ))));
$ts = date('Y-m-d H:i:s');
$TestModel->save(); $TestModel->save();
$TestModel->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC'; $TestModel->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC';
@ -1921,7 +1920,7 @@ class ModelIntegrationTest extends BaseModelTest {
) )
) )
); );
$this->assertTrue($result['Something']['updated'] >= $ts); $this->assertEquals(self::date(), $result['Something']['updated']);
unset($result['Something']['updated']); unset($result['Something']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }

View file

@ -1613,7 +1613,6 @@ class ModelWriteTest extends BaseModelTest {
); );
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$ts = date('Y-m-d H:i:s');
$TestModel->id = 2; $TestModel->id = 2;
$data = array('Tag' => array('Tag' => array(2))); $data = array('Tag' => array('Tag' => array(2)));
$TestModel->save($data); $TestModel->save($data);
@ -1627,7 +1626,7 @@ class ModelWriteTest extends BaseModelTest {
'body' => 'Second Article Body', 'body' => 'Second Article Body',
'published' => 'Y', 'published' => 'Y',
'created' => '2007-03-18 10:41:23', 'created' => '2007-03-18 10:41:23',
'updated' => $ts 'updated' => self::date()
), ),
'Tag' => array( 'Tag' => array(
array( array(
@ -2562,29 +2561,28 @@ class ModelWriteTest extends BaseModelTest {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$ts = date('Y-m-d H:i:s');
$TestModel->id = 1; $TestModel->id = 1;
$data = array( $data = array(
'JoinA' => array( 'JoinA' => array(
'id' => '1', 'id' => '1',
'name' => 'New name for Join A 1', 'name' => 'New name for Join A 1',
'updated' => $ts 'updated' => self::date()
), ),
'JoinB' => array( 'JoinB' => array(
array( array(
'id' => 1, 'id' => 1,
'join_b_id' => 2, 'join_b_id' => 2,
'other' => 'New data for Join A 1 Join B 2', 'other' => 'New data for Join A 1 Join B 2',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)), )),
'JoinC' => array( 'JoinC' => array(
array( array(
'id' => 1, 'id' => 1,
'join_c_id' => 2, 'join_c_id' => 2,
'other' => 'New data for Join A 1 Join C 2', 'other' => 'New data for Join A 1 Join C 2',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
))); )));
$TestModel->set($data); $TestModel->set($data);
@ -2597,7 +2595,7 @@ class ModelWriteTest extends BaseModelTest {
'name' => 'New name for Join A 1', 'name' => 'New name for Join A 1',
'body' => 'Join A 1 Body', 'body' => 'Join A 1 Body',
'created' => '2008-01-03 10:54:23', 'created' => '2008-01-03 10:54:23',
'updated' => $ts 'updated' => self::date()
), ),
'JoinB' => array( 'JoinB' => array(
0 => array( 0 => array(
@ -2610,8 +2608,8 @@ class ModelWriteTest extends BaseModelTest {
'join_a_id' => 1, 'join_a_id' => 1,
'join_b_id' => 2, 'join_b_id' => 2,
'other' => 'New data for Join A 1 Join B 2', 'other' => 'New data for Join A 1 Join B 2',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
))), ))),
'JoinC' => array( 'JoinC' => array(
0 => array( 0 => array(
@ -2624,8 +2622,8 @@ class ModelWriteTest extends BaseModelTest {
'join_a_id' => 1, 'join_a_id' => 1,
'join_c_id' => 2, 'join_c_id' => 2,
'other' => 'New data for Join A 1 Join C 2', 'other' => 'New data for Join A 1 Join C 2',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)))); ))));
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -2643,7 +2641,6 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->find('all'); $result = $TestModel->find('all');
$this->assertEquals(3, count($result)); $this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3])); $this->assertFalse(isset($result[3]));
$ts = date('Y-m-d H:i:s');
$TestModel->saveAll(array( $TestModel->saveAll(array(
'Post' => array( 'Post' => array(
@ -2670,10 +2667,10 @@ class ModelWriteTest extends BaseModelTest {
'password' => '5f4dcc3b5aa765d61d8327deb882cf90', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
'test' => 'working' 'test' => 'working'
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[3]['Author']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Author']['created']);
$this->assertTrue($result[3]['Author']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Author']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[3]['Author']['created'], $result[3]['Author']['updated']); unset($result[3]['Author']['created'], $result[3]['Author']['updated']);
$this->assertEquals($expected, $result[3]); $this->assertEquals($expected, $result[3]);
@ -2685,7 +2682,6 @@ class ModelWriteTest extends BaseModelTest {
// SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass // SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass
$this->db->truncate($TestModel); $this->db->truncate($TestModel);
$ts = date('Y-m-d H:i:s');
$TestModel->saveAll(array( $TestModel->saveAll(array(
array( array(
'title' => 'Multi-record post 1', 'title' => 'Multi-record post 1',
@ -2719,16 +2715,15 @@ class ModelWriteTest extends BaseModelTest {
'body' => 'Second multi-record post', 'body' => 'Second multi-record post',
'published' => 'N' 'published' => 'N'
))); )));
$this->assertTrue($result[0]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['created']);
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[1]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['created']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
unset($result[0]['Post']['created'], $result[0]['Post']['updated']); unset($result[0]['Post']['created'], $result[0]['Post']['updated']);
unset($result[1]['Post']['created'], $result[1]['Post']['updated']); unset($result[1]['Post']['created'], $result[1]['Post']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$TestModel = new Comment(); $TestModel = new Comment();
$ts = date('Y-m-d H:i:s');
$result = $TestModel->saveAll(array( $result = $TestModel->saveAll(array(
'Comment' => array( 'Comment' => array(
'article_id' => 2, 'article_id' => 2,
@ -2749,8 +2744,8 @@ class ModelWriteTest extends BaseModelTest {
'comment' => 'New comment with attachment', 'comment' => 'New comment with attachment',
'published' => 'Y' 'published' => 'Y'
); );
$this->assertTrue($result[6]['Comment']['created'] >= $ts); $this->assertEquals(self::date(), $result[6]['Comment']['created']);
$this->assertTrue($result[6]['Comment']['updated'] >= $ts); $this->assertEquals(self::date(), $result[6]['Comment']['updated']);
unset($result[6]['Comment']['created'], $result[6]['Comment']['updated']); unset($result[6]['Comment']['created'], $result[6]['Comment']['updated']);
$this->assertEquals($expected, $result[6]['Comment']); $this->assertEquals($expected, $result[6]['Comment']);
@ -2759,8 +2754,8 @@ class ModelWriteTest extends BaseModelTest {
'comment_id' => '7', 'comment_id' => '7',
'attachment' => 'some_file.tgz' 'attachment' => 'some_file.tgz'
); );
$this->assertTrue($result[6]['Attachment']['created'] >= $ts); $this->assertEquals(self::date(), $result[6]['Attachment']['created']);
$this->assertTrue($result[6]['Attachment']['updated'] >= $ts); $this->assertEquals(self::date(), $result[6]['Attachment']['updated']);
unset($result[6]['Attachment']['created'], $result[6]['Attachment']['updated']); unset($result[6]['Attachment']['created'], $result[6]['Attachment']['updated']);
$this->assertEquals($expected, $result[6]['Attachment']); $this->assertEquals($expected, $result[6]['Attachment']);
} }
@ -4057,7 +4052,6 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => 'New Fifth Post'), array('author_id' => 1, 'title' => 'New Fifth Post'),
array('author_id' => 1, 'title' => '') array('author_id' => 1, 'title' => '')
); );
$ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveAll($data)); $this->assertFalse($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
@ -4099,8 +4093,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'New Fourth Post', 'title' => 'New Fourth Post',
'body' => null, 'body' => null,
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)); ));
$expected[] = array( $expected[] = array(
@ -4110,8 +4104,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'New Fifth Post', 'title' => 'New Fifth Post',
'body' => null, 'body' => null,
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)); ));
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -4126,7 +4120,6 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => ''), array('author_id' => 1, 'title' => ''),
array('author_id' => 1, 'title' => 'New Sixth Post') array('author_id' => 1, 'title' => 'New Sixth Post')
); );
$ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveAll($data)); $this->assertFalse($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
@ -4168,8 +4161,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'New Fourth Post', 'title' => 'New Fourth Post',
'body' => 'Third Post Body', 'body' => 'Third Post Body',
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)); ));
$expected[] = array( $expected[] = array(
@ -4179,8 +4172,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Third Post', 'title' => 'Third Post',
'body' => 'Third Post Body', 'body' => 'Third Post Body',
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)); ));
} }
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -4265,7 +4258,6 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => 2 'author_id' => 2
)); ));
$ts = date('Y-m-d H:i:s');
$this->assertTrue($TestModel->saveAll($data)); $this->assertTrue($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
@ -4306,10 +4298,10 @@ class ModelWriteTest extends BaseModelTest {
'body' => 'Fourth post body', 'body' => 'Fourth post body',
'published' => 'N' 'published' => 'N'
))); )));
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']); unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -4400,10 +4392,10 @@ class ModelWriteTest extends BaseModelTest {
) )
); );
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
unset( unset(
$result[0]['Post']['updated'], $result[1]['Post']['updated'], $result[0]['Post']['updated'], $result[1]['Post']['updated'],
$result[3]['Post']['updated'], $result[3]['Post']['created'] $result[3]['Post']['updated'], $result[3]['Post']['created']
@ -4731,7 +4723,6 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->find('all'); $result = $TestModel->find('all');
$this->assertEquals(3, count($result)); $this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3])); $this->assertFalse(isset($result[3]));
$ts = date('Y-m-d H:i:s');
$TestModel->saveAssociated(array( $TestModel->saveAssociated(array(
'Post' => array( 'Post' => array(
@ -4758,10 +4749,10 @@ class ModelWriteTest extends BaseModelTest {
'password' => '5f4dcc3b5aa765d61d8327deb882cf90', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
'test' => 'working' 'test' => 'working'
)); ));
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Author']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Author']['created']);
$this->assertTrue($result[3]['Author']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Author']['updated']);
unset( unset(
$result[3]['Post']['updated'], $result[3]['Post']['created'], $result[3]['Post']['updated'], $result[3]['Post']['created'],
$result[3]['Author']['updated'], $result[3]['Author']['created'] $result[3]['Author']['updated'], $result[3]['Author']['created']
@ -4769,10 +4760,7 @@ class ModelWriteTest extends BaseModelTest {
$this->assertEquals($expected, $result[3]); $this->assertEquals($expected, $result[3]);
$this->assertEquals(4, count($result)); $this->assertEquals(4, count($result));
$ts = date('Y-m-d H:i:s');
$TestModel = new Comment(); $TestModel = new Comment();
$ts = date('Y-m-d H:i:s');
$result = $TestModel->saveAssociated(array( $result = $TestModel->saveAssociated(array(
'Comment' => array( 'Comment' => array(
'article_id' => 2, 'article_id' => 2,
@ -4793,8 +4781,8 @@ class ModelWriteTest extends BaseModelTest {
'comment' => 'New comment with attachment', 'comment' => 'New comment with attachment',
'published' => 'Y' 'published' => 'Y'
); );
$this->assertTrue($result[6]['Comment']['updated'] >= $ts); $this->assertEquals(self::date(), $result[6]['Comment']['updated']);
$this->assertTrue($result[6]['Comment']['created'] >= $ts); $this->assertEquals(self::date(), $result[6]['Comment']['created']);
unset($result[6]['Comment']['updated'], $result[6]['Comment']['created']); unset($result[6]['Comment']['updated'], $result[6]['Comment']['created']);
$this->assertEquals($expected, $result[6]['Comment']); $this->assertEquals($expected, $result[6]['Comment']);
@ -4803,8 +4791,8 @@ class ModelWriteTest extends BaseModelTest {
'comment_id' => '7', 'comment_id' => '7',
'attachment' => 'some_file.tgz' 'attachment' => 'some_file.tgz'
); );
$this->assertTrue($result[6]['Attachment']['updated'] >= $ts); $this->assertEquals(self::date(), $result[6]['Attachment']['updated']);
$this->assertTrue($result[6]['Attachment']['created'] >= $ts); $this->assertEquals(self::date(), $result[6]['Attachment']['created']);
unset($result[6]['Attachment']['updated'], $result[6]['Attachment']['created']); unset($result[6]['Attachment']['updated'], $result[6]['Attachment']['created']);
$this->assertEquals($expected, $result[6]['Attachment']); $this->assertEquals($expected, $result[6]['Attachment']);
} }
@ -4823,7 +4811,6 @@ class ModelWriteTest extends BaseModelTest {
// SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass // SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass
$this->db->truncate($TestModel); $this->db->truncate($TestModel);
$ts = date('Y-m-d H:i:s');
$TestModel->saveMany(array( $TestModel->saveMany(array(
array( array(
'title' => 'Multi-record post 1', 'title' => 'Multi-record post 1',
@ -4860,10 +4847,10 @@ class ModelWriteTest extends BaseModelTest {
) )
) )
); );
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[0]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['created']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
$this->assertTrue($result[1]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['created']);
unset($result[0]['Post']['updated'], $result[0]['Post']['created']); unset($result[0]['Post']['updated'], $result[0]['Post']['created']);
unset($result[1]['Post']['updated'], $result[1]['Post']['created']); unset($result[1]['Post']['updated'], $result[1]['Post']['created']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -5415,7 +5402,6 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => 'New Fifth Post'), array('author_id' => 1, 'title' => 'New Fifth Post'),
array('author_id' => 1, 'title' => '') array('author_id' => 1, 'title' => '')
); );
$ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveMany($data)); $this->assertFalse($TestModel->saveMany($data));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
@ -5468,10 +5454,10 @@ class ModelWriteTest extends BaseModelTest {
'published' => 'N', 'published' => 'N',
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[4]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[4]['Post']['created']);
$this->assertTrue($result[4]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[4]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[4]['Post']['created'], $result[4]['Post']['updated']); unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -5486,7 +5472,6 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => ''), array('author_id' => 1, 'title' => ''),
array('author_id' => 1, 'title' => 'New Sixth Post') array('author_id' => 1, 'title' => 'New Sixth Post')
); );
$ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveMany($data)); $this->assertFalse($TestModel->saveMany($data));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
@ -5538,10 +5523,10 @@ class ModelWriteTest extends BaseModelTest {
'body' => 'Third Post Body', 'body' => 'Third Post Body',
'published' => 'N' 'published' => 'N'
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[4]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[4]['Post']['created']);
$this->assertTrue($result[4]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[4]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[4]['Post']['created'], $result[4]['Post']['updated']); unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
} }
@ -5610,7 +5595,6 @@ class ModelWriteTest extends BaseModelTest {
$this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment');
$TestModel = new Post(); $TestModel = new Post();
$ts = date('Y-m-d H:i:s');
$data = array( $data = array(
array( array(
'id' => '1', 'id' => '1',
@ -5673,10 +5657,10 @@ class ModelWriteTest extends BaseModelTest {
) )
); );
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']); unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -6373,7 +6357,6 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->find('all'); $result = $TestModel->find('all');
$this->assertCount(3, $result); $this->assertCount(3, $result);
$this->assertFalse(isset($result[3])); $this->assertFalse(isset($result[3]));
$ts = date('Y-m-d H:i:s');
// test belongsTo // test belongsTo
$fieldList = array( $fieldList = array(
@ -6399,15 +6382,15 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Post without body', 'title' => 'Post without body',
'body' => null, 'body' => null,
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts, 'updated' => self::date(),
), ),
'Author' => array ( 'Author' => array (
'id' => '5', 'id' => '5',
'user' => 'bob', 'user' => 'bob',
'password' => null, 'password' => null,
'created' => $ts, 'created' => self::date(),
'updated' => $ts, 'updated' => self::date(),
'test' => 'working', 'test' => 'working',
), ),
); );
@ -6419,7 +6402,6 @@ class ModelWriteTest extends BaseModelTest {
// test multirecord // test multirecord
$this->db->truncate($TestModel); $this->db->truncate($TestModel);
$ts = date('Y-m-d H:i:s');
$fieldList = array('title', 'author_id'); $fieldList = array('title', 'author_id');
$TestModel->saveAll(array( $TestModel->saveAll(array(
array( array(
@ -6445,8 +6427,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Multi-record post 1', 'title' => 'Multi-record post 1',
'body' => '', 'body' => '',
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
) )
), ),
array( array(
@ -6456,8 +6438,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Multi-record post 2', 'title' => 'Multi-record post 2',
'body' => '', 'body' => '',
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
) )
) )
); );
@ -6545,7 +6527,6 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->find('all'); $result = $TestModel->find('all');
$this->assertCount(3, $result); $this->assertCount(3, $result);
$this->assertFalse(isset($result[3])); $this->assertFalse(isset($result[3]));
$ts = date('Y-m-d H:i:s');
// test belongsTo // test belongsTo
$fieldList = array( $fieldList = array(

View file

@ -152,6 +152,16 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
} }
} }
/**
* See CakeTestSuiteDispatcher::date()
*
* @param string $format format to be used.
* @return string
*/
public static function date($format = 'Y-m-d H:i:s') {
return CakeTestSuiteDispatcher::date($format);
}
// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP // @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP
/** /**

View file

@ -247,6 +247,7 @@ class CakeTestSuiteDispatcher {
restore_error_handler(); restore_error_handler();
try { try {
self::time();
$command = new CakeTestSuiteCommand('CakeTestLoader', $commandArgs); $command = new CakeTestSuiteCommand('CakeTestLoader', $commandArgs);
$result = $command->run($options); $result = $command->run($options);
} catch (MissingConnectionException $exception) { } catch (MissingConnectionException $exception) {
@ -257,4 +258,29 @@ class CakeTestSuiteDispatcher {
} }
} }
/**
* Sets a static timestamp
*
* @param boolean $reset to set new static timestamp.
* @return integer timestamp
*/
public static function time($reset = false) {
static $now;
if ($reset || !$now) {
$now = time();
}
return $now;
}
/**
* Returns formatted date string using static time
* This method is being used as formatter for created, modified and updated fields in Model::save()
*
* @param string $format format to be used.
* @return string formatted date
*/
public static function date($format) {
return date($format, self::time());
}
} }

View file

@ -53,5 +53,18 @@ class CakeTestModel extends Model {
} }
return $queryData; return $queryData;
} }
/**
* Overriding save() to set CakeTestSuiteDispatcher::date() as formatter for created, modified and updated fields
*
* @param array $data
* @param mixed $validate
* @param array $fieldList
*/
public function save($data = null, $validate = true, $fieldList = array()) {
$db = $this->getDataSource();
$db->columns['datetime']['formatter'] = 'CakeTestSuiteDispatcher::date';
return parent::save($data, $validate, $fieldList);
}
} }