HazardableBehaviorTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $this->Model = ClassRegistry::init('Comment');
  9. $this->Model->Behaviors->load('Tools.Hazardable', array());
  10. }
  11. public function tearDown() {
  12. unset($this->Model);
  13. }
  14. public function testObject() {
  15. $this->assertTrue(is_a($this->Model->Behaviors->Hazardable, 'HazardableBehavior'));
  16. }
  17. public function testSaveAndFind() {
  18. $data = array(
  19. 'comment' => 'foo',
  20. );
  21. $this->Model->create();
  22. $res = $this->Model->save($data);
  23. $this->assertTrue((bool)$res);
  24. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  25. $this->assertTrue((bool)$res);
  26. $this->assertEquals('<', $res['Comment']['published']);
  27. $this->assertTrue(!empty($res['Comment']['comment']));
  28. //echo $res['Comment']['comment'];ob_flush();
  29. }
  30. public function testFind() {
  31. $this->Model->Behaviors->unload('Hazardable');
  32. $data = array(
  33. 'comment' => 'foo',
  34. );
  35. $this->Model->create();
  36. $res = $this->Model->save($data);
  37. $this->assertTrue((bool)$res);
  38. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  39. $this->assertTrue((bool)$res);
  40. $this->assertEquals('foo', $res['Comment']['comment']);
  41. $this->Model->Behaviors->load('Tools.Hazardable', array('replaceFind' => true));
  42. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  43. $this->assertTrue((bool)$res);
  44. $this->assertEquals('<', $res['Comment']['published']);
  45. $this->assertTrue(!empty($res['Comment']['comment']));
  46. $this->assertNotEquals('foo', $res['Comment']['comment']);
  47. //echo $res['Comment']['comment'];ob_flush();
  48. }
  49. }