ResetBehaviorTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. App::uses('ResetBehavior', 'Tools.Model/Behavior');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. App::uses('AppModel', 'Model');
  5. class ResetBehaviorTest extends MyCakeTestCase {
  6. public $ResetBehavior;
  7. public $Model;
  8. public $fixtures = array('core.comment');
  9. public function setUp() {
  10. parent::setUp();
  11. $this->ResetBehavior = new ResetBehavior();
  12. $this->Model = ClassRegistry::init('MyComment');
  13. $this->Model->Behaviors->attach('Tools.Reset');
  14. }
  15. public function testObject() {
  16. $this->assertTrue(is_object($this->ResetBehavior));
  17. $this->assertInstanceOf('ResetBehavior', $this->ResetBehavior);
  18. }
  19. public function testResetRecords() {
  20. $x = $this->Model->find('first', array('order' => array('updated'=>'DESC')));
  21. $result = $this->Model->resetRecords();
  22. $this->assertTrue($result);
  23. $y = $this->Model->find('first', array('order' => array('updated'=>'DESC')));
  24. $this->assertSame($x, $y);
  25. }
  26. public function testResetRecordsWithUpdatedTimestamp() {
  27. $this->Model->Behaviors->unload('Reset');
  28. $this->Model->Behaviors->load('Tools.Reset', array('updateTimestamp' => true));
  29. $x = $this->Model->find('first', array('order' => array('updated'=>'DESC')));
  30. $this->assertTrue($x['MyComment']['updated'] < '2007-12-31');
  31. $result = $this->Model->resetRecords();
  32. $this->assertTrue($result);
  33. $x = $this->Model->find('first', array('order' => array('updated'=>'ASC')));
  34. $this->assertTrue($x['MyComment']['updated'] > (date('Y')-1) . '-12-31');
  35. }
  36. }
  37. class MyComment extends AppModel {
  38. public $fixture = 'core.comment';
  39. public $useTable = 'comments';
  40. }