HazardableBehaviorTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. App::uses('HazardableBehavior', 'Tools.Model/Behavior');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class HazardableBehaviorTest extends MyCakeTestCase {
  5. public $fixtures = array('core.comment');
  6. public $Model;
  7. public function setUp() {
  8. parent::setUp();
  9. $this->Model = ClassRegistry::init('Comment');
  10. $this->Model->Behaviors->load('Tools.Hazardable', array());
  11. }
  12. public function tearDown() {
  13. parent::tearDown();
  14. unset($this->Model);
  15. }
  16. public function testObject() {
  17. $this->assertInstanceOf('HazardableBehavior', $this->Model->Behaviors->Hazardable);
  18. }
  19. public function testSaveAndFind() {
  20. $data = array(
  21. 'comment' => 'foo',
  22. );
  23. $this->Model->create();
  24. $res = $this->Model->save($data);
  25. $this->assertTrue((bool)$res);
  26. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  27. $this->assertTrue((bool)$res);
  28. $this->assertEquals('<', $res['Comment']['published']);
  29. $this->assertTrue(!empty($res['Comment']['comment']));
  30. //echo $res['Comment']['comment'];ob_flush();
  31. }
  32. public function testFind() {
  33. $this->Model->Behaviors->unload('Hazardable');
  34. $data = array(
  35. 'comment' => 'foo',
  36. );
  37. $this->Model->create();
  38. $res = $this->Model->save($data);
  39. $this->assertTrue((bool)$res);
  40. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  41. $this->assertTrue((bool)$res);
  42. $this->assertEquals('foo', $res['Comment']['comment']);
  43. $this->Model->Behaviors->load('Tools.Hazardable', array('replaceFind' => true));
  44. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  45. $this->assertTrue((bool)$res);
  46. $this->assertEquals('<', $res['Comment']['published']);
  47. $this->assertTrue(!empty($res['Comment']['comment']));
  48. $this->assertNotEquals('foo', $res['Comment']['comment']);
  49. //echo $res['Comment']['comment'];ob_flush();
  50. }
  51. }