3 defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION') ?
null : define('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION', false);
4 defined('AK_TEST_DATABASE_ON') ?
null : define('AK_TEST_DATABASE_ON', true);
6 require_once(dirname(__FILE__
).'/../../../fixtures/config/config.php');
8 class test_AkActiveRecord_findOrCreateBy
extends AkUnitTest
12 $this->installAndIncludeModels(array('Account'));
15 function test_should_create_new_users()
17 $Account = new Account();
18 $Bermi =& $Account->findOrCreateBy('username', 'Bermi');
20 $this->assertFalse($Bermi->isNewRecord());
21 $this->assertEqual($Bermi->get('username'), 'Bermi');
23 $Alicia =& $Account->findOrCreateBy('username AND password', 'Alicia', 'pass');
25 $this->assertFalse($Alicia->isNewRecord());
26 $this->assertEqual($Alicia->get('username'), 'Alicia');
27 $this->assertEqual($Alicia->get('password'), 'pass');
29 $SavedBermi =& $Account->findFirstBy('username', 'Bermi');
30 $this->assertEqual($SavedBermi->getId(), $Bermi->getId());
31 $SavedBermi =& $Account->findOrCreateBy('username', 'Bermi');
32 $this->assertEqual($SavedBermi->getId(), $Bermi->getId());
34 $SavedAlicia =& $Account->findOrCreateBy('username', 'Alicia');
35 $this->assertEqual($SavedAlicia->getId(), $Alicia->getId());
38 function test_should_return_existing_record()
40 $Account = new Account();
41 $Alicia =& $Account->findFirstBy('username', 'Alicia');
42 $this->assertEqual($Alicia->get('password'), 'pass');
46 ak_test('test_AkActiveRecord_findOrCreateBy',true);