Skip to content

Commit 7776cdc

Browse files
committed
Add timestamp behavior test
1 parent ec3a1ed commit 7776cdc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/TestCase/Model/Behavior/InsertBehaviorTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,32 @@ public function testInsertOnce()
172172
$this->assertCount(1, $actual, 'fail insert once.');
173173
}
174174

175+
/**
176+
* insertOnce() test add timestamp behavior
177+
*
178+
* @return void
179+
*/
180+
public function testInsertOnceAddTimestampBehavior()
181+
{
182+
$this->Articles->addBehavior('Timestamp');
183+
184+
$newData = [
185+
'title' => 'New Article',
186+
'body' => 'New Article Body',
187+
'published' => 1
188+
];
189+
$entity = $this->Articles->newEntity($newData);
190+
$now = Chronos::now();
191+
192+
$this->Articles->insertOnce($entity);
193+
194+
$newData['created'] = $now;
195+
$newData['modified'] = $now;
196+
197+
$actual = $this->Articles->exists($newData);
198+
$this->assertTrue($actual, 'fail insert.');
199+
}
200+
175201
/**
176202
* insertOnce() test when duplicated
177203
*

0 commit comments

Comments
 (0)