HazardableBehaviorTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /**
  8. * HazardableBehaviorTest::setUp()
  9. *
  10. * @return void
  11. */
  12. public function setUp() {
  13. parent::setUp();
  14. $this->Model = ClassRegistry::init('Comment');
  15. $this->Model->Behaviors->load('Tools.Hazardable');
  16. }
  17. public function testObject() {
  18. $this->assertInstanceOf('HazardableBehavior', $this->Model->Behaviors->Hazardable);
  19. }
  20. /**
  21. * HazardableBehaviorTest::testSaveAndFind()
  22. *
  23. * @return void
  24. */
  25. public function testSaveAndFind() {
  26. $data = array(
  27. 'comment' => 'foo',
  28. );
  29. $this->Model->create();
  30. $res = $this->Model->save($data);
  31. $this->assertTrue((bool)$res);
  32. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  33. $this->assertTrue((bool)$res);
  34. $this->assertEquals('<', $res['Comment']['published']);
  35. $this->assertTrue(!empty($res['Comment']['comment']));
  36. }
  37. /**
  38. * HazardableBehaviorTest::testFind()
  39. *
  40. * @return void
  41. */
  42. public function testReplaceFind() {
  43. $this->Model->Behaviors->unload('Hazardable');
  44. $data = array(
  45. 'comment' => 'foo',
  46. );
  47. $this->Model->create();
  48. $res = $this->Model->save($data);
  49. $this->assertTrue((bool)$res);
  50. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  51. $this->assertTrue((bool)$res);
  52. $this->assertEquals('foo', $res['Comment']['comment']);
  53. $this->Model->Behaviors->load('Tools.Hazardable', array('replaceFind' => true));
  54. $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
  55. $this->assertTrue((bool)$res);
  56. $this->assertEquals('<', $res['Comment']['published']);
  57. $this->assertTrue(!empty($res['Comment']['comment']));
  58. $this->assertNotEquals('foo', $res['Comment']['comment']);
  59. }
  60. }