mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
created, modified and updated fields now use static timestamp in testcases
This commit is contained in:
parent
dec67ef259
commit
f0bd7386e2
7 changed files with 124 additions and 96 deletions
|
@ -1629,7 +1629,7 @@ class Model extends Object implements CakeEventListener {
|
|||
if (!array_key_exists('format', $colType)) {
|
||||
$time = strtotime('now');
|
||||
} else {
|
||||
$time = $colType['formatter']($colType['format']);
|
||||
$time = call_user_func($colType['formatter'], $colType['format']);
|
||||
}
|
||||
if (!empty($this->whitelist)) {
|
||||
$this->whitelist[] = $updateCol;
|
||||
|
|
|
@ -163,7 +163,6 @@ class FormAuthenticateTest extends CakeTestCase {
|
|||
), App::RESET);
|
||||
CakePlugin::load('TestPlugin');
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser');
|
||||
$user['id'] = 1;
|
||||
$user['username'] = 'gwoo';
|
||||
|
@ -185,7 +184,7 @@ class FormAuthenticateTest extends CakeTestCase {
|
|||
'username' => 'gwoo',
|
||||
'created' => '2007-03-17 01:16:23'
|
||||
);
|
||||
$this->assertTrue($result['updated'] >= $ts);
|
||||
$this->assertEquals(self::date(), $result['updated']);
|
||||
unset($result['updated']);
|
||||
$this->assertEquals($expected, $result);
|
||||
CakePlugin::unload();
|
||||
|
|
|
@ -1867,7 +1867,6 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'doomed' => true
|
||||
))));
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$TestModel->save();
|
||||
|
||||
$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']);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
|
|
@ -1613,7 +1613,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$TestModel->id = 2;
|
||||
$data = array('Tag' => array('Tag' => array(2)));
|
||||
$TestModel->save($data);
|
||||
|
@ -1627,7 +1626,7 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'body' => 'Second Article Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => $ts
|
||||
'updated' => self::date()
|
||||
),
|
||||
'Tag' => array(
|
||||
array(
|
||||
|
@ -2562,29 +2561,28 @@ class ModelWriteTest extends BaseModelTest {
|
|||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$TestModel->id = 1;
|
||||
$data = array(
|
||||
'JoinA' => array(
|
||||
'id' => '1',
|
||||
'name' => 'New name for Join A 1',
|
||||
'updated' => $ts
|
||||
'updated' => self::date()
|
||||
),
|
||||
'JoinB' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'join_b_id' => 2,
|
||||
'other' => 'New data for Join A 1 Join B 2',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
)),
|
||||
'JoinC' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'join_c_id' => 2,
|
||||
'other' => 'New data for Join A 1 Join C 2',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
)));
|
||||
|
||||
$TestModel->set($data);
|
||||
|
@ -2597,7 +2595,7 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'name' => 'New name for Join A 1',
|
||||
'body' => 'Join A 1 Body',
|
||||
'created' => '2008-01-03 10:54:23',
|
||||
'updated' => $ts
|
||||
'updated' => self::date()
|
||||
),
|
||||
'JoinB' => array(
|
||||
0 => array(
|
||||
|
@ -2610,8 +2608,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'join_a_id' => 1,
|
||||
'join_b_id' => 2,
|
||||
'other' => 'New data for Join A 1 Join B 2',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
))),
|
||||
'JoinC' => array(
|
||||
0 => array(
|
||||
|
@ -2624,8 +2622,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'join_a_id' => 1,
|
||||
'join_c_id' => 2,
|
||||
'other' => 'New data for Join A 1 Join C 2',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
))));
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -2643,7 +2641,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$result = $TestModel->find('all');
|
||||
$this->assertEquals(3, count($result));
|
||||
$this->assertFalse(isset($result[3]));
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
|
||||
$TestModel->saveAll(array(
|
||||
'Post' => array(
|
||||
|
@ -2670,10 +2667,10 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
|
||||
'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);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[3]['Author']['created']);
|
||||
$this->assertEquals(self::date(), $result[3]['Author']['updated']);
|
||||
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
|
||||
unset($result[3]['Author']['created'], $result[3]['Author']['updated']);
|
||||
$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
|
||||
$this->db->truncate($TestModel);
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$TestModel->saveAll(array(
|
||||
array(
|
||||
'title' => 'Multi-record post 1',
|
||||
|
@ -2719,16 +2715,15 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'body' => 'Second multi-record post',
|
||||
'published' => 'N'
|
||||
)));
|
||||
$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);
|
||||
$this->assertEquals(self::date(), $result[0]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[0]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[1]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[1]['Post']['updated']);
|
||||
unset($result[0]['Post']['created'], $result[0]['Post']['updated']);
|
||||
unset($result[1]['Post']['created'], $result[1]['Post']['updated']);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$TestModel = new Comment();
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$result = $TestModel->saveAll(array(
|
||||
'Comment' => array(
|
||||
'article_id' => 2,
|
||||
|
@ -2749,8 +2744,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'comment' => 'New comment with attachment',
|
||||
'published' => 'Y'
|
||||
);
|
||||
$this->assertTrue($result[6]['Comment']['created'] >= $ts);
|
||||
$this->assertTrue($result[6]['Comment']['updated'] >= $ts);
|
||||
$this->assertEquals(self::date(), $result[6]['Comment']['created']);
|
||||
$this->assertEquals(self::date(), $result[6]['Comment']['updated']);
|
||||
unset($result[6]['Comment']['created'], $result[6]['Comment']['updated']);
|
||||
$this->assertEquals($expected, $result[6]['Comment']);
|
||||
|
||||
|
@ -2759,8 +2754,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'comment_id' => '7',
|
||||
'attachment' => 'some_file.tgz'
|
||||
);
|
||||
$this->assertTrue($result[6]['Attachment']['created'] >= $ts);
|
||||
$this->assertTrue($result[6]['Attachment']['updated'] >= $ts);
|
||||
$this->assertEquals(self::date(), $result[6]['Attachment']['created']);
|
||||
$this->assertEquals(self::date(), $result[6]['Attachment']['updated']);
|
||||
unset($result[6]['Attachment']['created'], $result[6]['Attachment']['updated']);
|
||||
$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' => '')
|
||||
);
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$this->assertFalse($TestModel->saveAll($data));
|
||||
|
||||
$result = $TestModel->find('all', array('recursive' => -1));
|
||||
|
@ -4099,8 +4093,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'title' => 'New Fourth Post',
|
||||
'body' => null,
|
||||
'published' => 'N',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
));
|
||||
|
||||
$expected[] = array(
|
||||
|
@ -4110,8 +4104,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'title' => 'New Fifth Post',
|
||||
'body' => null,
|
||||
'published' => 'N',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
));
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -4126,7 +4120,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
array('author_id' => 1, 'title' => ''),
|
||||
array('author_id' => 1, 'title' => 'New Sixth Post')
|
||||
);
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$this->assertFalse($TestModel->saveAll($data));
|
||||
|
||||
$result = $TestModel->find('all', array('recursive' => -1));
|
||||
|
@ -4168,8 +4161,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'title' => 'New Fourth Post',
|
||||
'body' => 'Third Post Body',
|
||||
'published' => 'N',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
));
|
||||
|
||||
$expected[] = array(
|
||||
|
@ -4179,8 +4172,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'title' => 'Third Post',
|
||||
'body' => 'Third Post Body',
|
||||
'published' => 'N',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
));
|
||||
}
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -4265,7 +4258,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'author_id' => 2
|
||||
));
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$this->assertTrue($TestModel->saveAll($data));
|
||||
|
||||
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
|
||||
|
@ -4306,10 +4298,10 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'body' => 'Fourth post body',
|
||||
'published' => 'N'
|
||||
)));
|
||||
$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);
|
||||
$this->assertEquals(self::date(), $result[0]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[1]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['updated']);
|
||||
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
|
||||
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -4400,10 +4392,10 @@ class ModelWriteTest extends BaseModelTest {
|
|||
)
|
||||
);
|
||||
|
||||
$this->assertTrue($result[0]['Post']['updated'] >= $ts);
|
||||
$this->assertTrue($result[1]['Post']['updated'] >= $ts);
|
||||
$this->assertTrue($result[3]['Post']['updated'] >= $ts);
|
||||
$this->assertTrue($result[3]['Post']['created'] >= $ts);
|
||||
$this->assertEquals(self::date(), $result[0]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[1]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['created']);
|
||||
unset(
|
||||
$result[0]['Post']['updated'], $result[1]['Post']['updated'],
|
||||
$result[3]['Post']['updated'], $result[3]['Post']['created']
|
||||
|
@ -4731,7 +4723,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$result = $TestModel->find('all');
|
||||
$this->assertEquals(3, count($result));
|
||||
$this->assertFalse(isset($result[3]));
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
|
||||
$TestModel->saveAssociated(array(
|
||||
'Post' => array(
|
||||
|
@ -4758,10 +4749,10 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
|
||||
'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);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[3]['Author']['created']);
|
||||
$this->assertEquals(self::date(), $result[3]['Author']['updated']);
|
||||
unset(
|
||||
$result[3]['Post']['updated'], $result[3]['Post']['created'],
|
||||
$result[3]['Author']['updated'], $result[3]['Author']['created']
|
||||
|
@ -4769,10 +4760,7 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$this->assertEquals($expected, $result[3]);
|
||||
$this->assertEquals(4, count($result));
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
|
||||
$TestModel = new Comment();
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$result = $TestModel->saveAssociated(array(
|
||||
'Comment' => array(
|
||||
'article_id' => 2,
|
||||
|
@ -4793,8 +4781,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'comment' => 'New comment with attachment',
|
||||
'published' => 'Y'
|
||||
);
|
||||
$this->assertTrue($result[6]['Comment']['updated'] >= $ts);
|
||||
$this->assertTrue($result[6]['Comment']['created'] >= $ts);
|
||||
$this->assertEquals(self::date(), $result[6]['Comment']['updated']);
|
||||
$this->assertEquals(self::date(), $result[6]['Comment']['created']);
|
||||
unset($result[6]['Comment']['updated'], $result[6]['Comment']['created']);
|
||||
$this->assertEquals($expected, $result[6]['Comment']);
|
||||
|
||||
|
@ -4803,8 +4791,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'comment_id' => '7',
|
||||
'attachment' => 'some_file.tgz'
|
||||
);
|
||||
$this->assertTrue($result[6]['Attachment']['updated'] >= $ts);
|
||||
$this->assertTrue($result[6]['Attachment']['created'] >= $ts);
|
||||
$this->assertEquals(self::date(), $result[6]['Attachment']['updated']);
|
||||
$this->assertEquals(self::date(), $result[6]['Attachment']['created']);
|
||||
unset($result[6]['Attachment']['updated'], $result[6]['Attachment']['created']);
|
||||
$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
|
||||
$this->db->truncate($TestModel);
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$TestModel->saveMany(array(
|
||||
array(
|
||||
'title' => 'Multi-record post 1',
|
||||
|
@ -4860,10 +4847,10 @@ class ModelWriteTest extends BaseModelTest {
|
|||
)
|
||||
)
|
||||
);
|
||||
$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);
|
||||
$this->assertEquals(self::date(), $result[0]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[0]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[1]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[1]['Post']['created']);
|
||||
unset($result[0]['Post']['updated'], $result[0]['Post']['created']);
|
||||
unset($result[1]['Post']['updated'], $result[1]['Post']['created']);
|
||||
$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' => '')
|
||||
);
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$this->assertFalse($TestModel->saveMany($data));
|
||||
|
||||
$result = $TestModel->find('all', array('recursive' => -1));
|
||||
|
@ -5468,10 +5454,10 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'published' => 'N',
|
||||
));
|
||||
|
||||
$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);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[4]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[4]['Post']['updated']);
|
||||
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
|
||||
unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -5486,7 +5472,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
array('author_id' => 1, 'title' => ''),
|
||||
array('author_id' => 1, 'title' => 'New Sixth Post')
|
||||
);
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$this->assertFalse($TestModel->saveMany($data));
|
||||
|
||||
$result = $TestModel->find('all', array('recursive' => -1));
|
||||
|
@ -5538,10 +5523,10 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'body' => 'Third Post Body',
|
||||
'published' => 'N'
|
||||
));
|
||||
$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);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[4]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[4]['Post']['updated']);
|
||||
unset($result[3]['Post']['created'], $result[3]['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');
|
||||
$TestModel = new Post();
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$data = array(
|
||||
array(
|
||||
'id' => '1',
|
||||
|
@ -5673,10 +5657,10 @@ class ModelWriteTest extends BaseModelTest {
|
|||
)
|
||||
);
|
||||
|
||||
$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);
|
||||
$this->assertEquals(self::date(), $result[0]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[1]['Post']['updated']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['created']);
|
||||
$this->assertEquals(self::date(), $result[3]['Post']['updated']);
|
||||
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
|
||||
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -6373,7 +6357,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$result = $TestModel->find('all');
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertFalse(isset($result[3]));
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
|
||||
// test belongsTo
|
||||
$fieldList = array(
|
||||
|
@ -6399,15 +6382,15 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'title' => 'Post without body',
|
||||
'body' => null,
|
||||
'published' => 'N',
|
||||
'created' => $ts,
|
||||
'updated' => $ts,
|
||||
'created' => self::date(),
|
||||
'updated' => self::date(),
|
||||
),
|
||||
'Author' => array (
|
||||
'id' => '5',
|
||||
'user' => 'bob',
|
||||
'password' => null,
|
||||
'created' => $ts,
|
||||
'updated' => $ts,
|
||||
'created' => self::date(),
|
||||
'updated' => self::date(),
|
||||
'test' => 'working',
|
||||
),
|
||||
);
|
||||
|
@ -6419,7 +6402,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
// test multirecord
|
||||
$this->db->truncate($TestModel);
|
||||
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$fieldList = array('title', 'author_id');
|
||||
$TestModel->saveAll(array(
|
||||
array(
|
||||
|
@ -6445,8 +6427,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'title' => 'Multi-record post 1',
|
||||
'body' => '',
|
||||
'published' => 'N',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
)
|
||||
),
|
||||
array(
|
||||
|
@ -6456,8 +6438,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'title' => 'Multi-record post 2',
|
||||
'body' => '',
|
||||
'published' => 'N',
|
||||
'created' => $ts,
|
||||
'updated' => $ts
|
||||
'created' => self::date(),
|
||||
'updated' => self::date()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -6545,7 +6527,6 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$result = $TestModel->find('all');
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertFalse(isset($result[3]));
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
|
||||
// test belongsTo
|
||||
$fieldList = array(
|
||||
|
|
|
@ -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
|
||||
|
||||
/**
|
||||
|
|
|
@ -247,6 +247,7 @@ class CakeTestSuiteDispatcher {
|
|||
restore_error_handler();
|
||||
|
||||
try {
|
||||
self::time();
|
||||
$command = new CakeTestSuiteCommand('CakeTestLoader', $commandArgs);
|
||||
$result = $command->run($options);
|
||||
} 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,5 +53,18 @@ class CakeTestModel extends Model {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue