3 defined('AK_TEST_DATABASE_ON') ?
null : define('AK_TEST_DATABASE_ON', true);
4 require_once(dirname(__FILE__
).'/../../../fixtures/config/config.php');
6 class test_HasOne_cascading_destroy
extends AkUnitTest
8 #thumbnail belongsTo picture
10 * hasOne main_thumbnail, dependent => true
16 $this->installAndIncludeModels(array('Picture','Thumbnail'));
17 $Picture =& $this->Picture
->create(array('title'=>'This is not a picture'));
18 $Picture->main_thumbnail
->create(array('caption'=>'It cant have a thumbnail'));
21 function test_ensure_we_have_the_setup_right()
23 $Picture =& $this->Picture
->find('first',array('include'=>'main_thumbnail'));
24 $this->assertEqual(1,$Picture->main_thumbnail
->photo_id
);
26 $Thumb =& $this->Thumbnail
->find('first');
27 $this->assertEqual(1,$Thumb->photo_id
);
28 #var_dump($this->Picture->_db->select('SELECT * FROM thumbnails'));
31 function test_should_destroy_the_belonging_thumbnail()
33 $Picture =& $this->Picture
->find('first',array('include'=>'main_thumbnail'));
36 $this->assertFalse($this->Thumbnail
->find('first'));
39 function test_should_destroy_the_thumbnail_even_when_not_loaded()
41 $Picture =& $this->Picture
->find('first');
44 $this->assertFalse($this->Thumbnail
->find('first'),'Issue #125');
49 ak_test('test_HasOne_cascading_destroy',true);