Fixing content type ordering when content_type is not defined.
[akelos.git] / test / unit / lib / AkActionView / helpers / active_record_helper.php
blob92a0d7c209451b042ae917254191f44b616f2022
1 <?php
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 require_once('_HelpersUnitTester.php');
9 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'active_record_helper.php');
10 require_once(AK_LIB_DIR.DS.'AkActionController.php');
11 require_once(AK_LIB_DIR.DS.'AkRequest.php');
13 ak_generate_mock('AkRequest');
16 class ActiveRecordHelperTests extends HelpersUnitTester
18 function test_setup()
20 $this->controller = &new AkActionController();
21 $this->controller->Request =& new MockAkRequest($this);
22 $this->controller->controller_name = 'test';
23 $this->controller->instantiateHelpers();
25 $this->active_record_helper =& $this->controller->active_record_helper;
26 $this->installAndIncludeModels(array('ProtectedPerson','Property'));
28 $this->controller->ProtectedPerson =& new ProtectedPerson();
29 $this->LuckyLuke =& $this->controller->ProtectedPerson;
30 $this->controller->ProtectedPerson->name = "Lucky Luke";
31 $this->controller->ProtectedPerson->created_by = "1";
32 $this->controller->ProtectedPerson->birthday = Ak::getDate(mktime(8,42,36,3,27,1982));
33 $this->controller->ProtectedPerson->save();
34 $this->controller->ProtectedPerson->created_at = Ak::getDate(mktime(8,42,36,3,27,1982));
35 $this->controller->ProtectedPerson->updated_at = Ak::getDate(mktime(8,42,36,3,27,1982));
37 $this->controller->Property =& new Property('description->','阿尔罕布拉宫','details->','阿尔罕布拉宫 <> & (阿拉伯语: الحمراء‎‎ = Al Ħamrā\'; 即"红色城堡")');
38 $this->alhambra =& $this->controller->Property;
39 $this->alhambra->save();
43 function tests_input()
45 $this->assertEqual(
46 $this->active_record_helper->input('ProtectedPerson', 'name'),
47 '<input id="ProtectedPerson_name" name="ProtectedPerson[name]" size="30" type="text" value="Lucky Luke" />'
49 $this->assertEqual(
50 $this->active_record_helper->input('ProtectedPerson', 'id'),
54 $this->assertEqual(
55 $this->active_record_helper->input('ProtectedPerson', 'birthday'),
56 file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_input_date.txt')
60 $this->assertEqual(
61 $this->active_record_helper->input('ProtectedPerson', 'is_active'),
62 '<input name="ProtectedPerson[is_active]" type="hidden" value="0" /><input checked="checked" id="ProtectedPerson_is_active" name="ProtectedPerson[is_active]" type="checkbox" value="1" />'
66 function test_form()
68 $this->assertEqual(
69 $this->active_record_helper->form('ProtectedPerson'),
70 file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_form.txt')
74 function test_should_render_limited_form_fields()
76 $this->assertEqual(
77 $this->active_record_helper->form('ProtectedPerson', array('columns'=>array('id','name'))),
78 file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_limited_form.txt')
82 function test_error_message_on()
84 $this->LuckyLuke->addError('name');
85 $this->assertEqual(
86 $this->active_record_helper->error_message_on('ProtectedPerson', 'name'),
87 '<div class="formError">is invalid</div>'
90 $this->assertEqual(
91 $this->active_record_helper->error_message_on('ProtectedPerson', 'name', 'before ',' after','nameError'),
92 '<div class="nameError">before is invalid after</div>'
96 function test_error_messages_for()
98 $this->LuckyLuke->addError('birthday');
99 $this->assertEqual(
100 $this->active_record_helper->error_messages_for('ProtectedPerson'),
101 file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_errors.txt')
104 $this->assertEqual(
105 $this->active_record_helper->error_messages_for('ProtectedPerson', array('header_tag'=>'h3','id'=>'LuckyLukeErrors','class'=>'errors')),
106 file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_errors_2.txt')
110 function test_textarea_should_escape_characters_correctly()
112 $this->assertEqual(
113 $this->active_record_helper->form('Property'),
114 file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_textarea_should_escape_characters_correctly.txt')
120 ak_test('ActiveRecordHelperTests');