| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- App::uses('HazardableBehavior', 'Tools.Model/Behavior');
- App::uses('MyCakeTestCase', 'Tools.TestSuite');
- class HazardableBehaviorTest extends MyCakeTestCase {
- public $fixtures = array('core.comment');
- public $Model;
- public function setUp() {
- $this->Model = ClassRegistry::init('Comment');
- $this->Model->Behaviors->load('Tools.Hazardable', array());
- }
- public function tearDown() {
- unset($this->Model);
- }
- public function testObject() {
- $this->assertTrue(is_a($this->Model->Behaviors->Hazardable, 'HazardableBehavior'));
- }
- public function testSaveAndFind() {
- $data = array(
- 'comment' => 'foo',
- );
- $this->Model->create();
- $res = $this->Model->save($data);
- $this->assertTrue((bool)$res);
- $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
- $this->assertTrue((bool)$res);
- $this->assertEquals('<', $res['Comment']['published']);
- $this->assertTrue(!empty($res['Comment']['comment']));
- //echo $res['Comment']['comment'];ob_flush();
- }
- public function testFind() {
- $this->Model->Behaviors->unload('Hazardable');
- $data = array(
- 'comment' => 'foo',
- );
- $this->Model->create();
- $res = $this->Model->save($data);
- $this->assertTrue((bool)$res);
- $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
- $this->assertTrue((bool)$res);
- $this->assertEquals('foo', $res['Comment']['comment']);
- $this->Model->Behaviors->load('Tools.Hazardable', array('replaceFind' => true));
- $res = $this->Model->find('first', array('conditions' => array('id' => $this->Model->id)));
- $this->assertTrue((bool)$res);
- $this->assertEquals('<', $res['Comment']['published']);
- $this->assertTrue(!empty($res['Comment']['comment']));
- $this->assertNotEquals('foo', $res['Comment']['comment']);
- //echo $res['Comment']['comment'];ob_flush();
- }
- }
|