Fixing content type ordering when content_type is not defined.
[akelos.git] / test / unit / lib / utils / _Ak_object_inspection.php
bloba9d71df2d4dce542428b26bc76fa10a9477ddd9a
1 <?php
3 defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);
4 require_once(dirname(__FILE__).'/../../../fixtures/config/config.php');
6 require_once(AK_LIB_DIR.DS.'Ak.php');
8 //This class is used to check class inspection functions
9 class AkTestingObjectInspectionParent
11 var $parent_var;
12 var $parent_var_null = null;
13 var $parent_var_string = 'abc';
14 var $parent_var_int = 123;
16 function AkTestingObjectInspectionParent(){
18 function parent_function(){
20 function &parent_method(){
23 class AkTestingObjectInspectionChild extends AkTestingObjectInspectionParent
25 var $child_var;
26 var $child_var_null = null;
27 var $child_var_string = 'abc';
28 var $child_var_int = 123;
30 function AkTestingObjectInspectionChild(){
31 parent::AkTestingObjectInspectionParent();
33 function child_function(){
35 function &child_method(){
41 class test_of_Ak_object_inspection extends UnitTestCase
44 var $AkTestingObjectInspectionChildInstance;
46 function setUp()
48 $this->AkTestingObjectInspectionChildInstance = new AkTestingObjectInspectionChild();
51 function tearDown()
53 unset($this->AkTestingObjectInspectionChildInstance);
57 function Test_db()
59 require_once(AK_CONTRIB_DIR.'/adodb/adodb.inc.php');
61 $db =& Ak::db();
62 $this->assertFalse(!$db,'Connecting to the database. Please check your test_config.php file in order to set up a copy of $dns into $GLOBALS["ak_test_db_dns"]');
63 $this->assertReference($db,Ak::db(),'Checking db connection singleton');
66 function Test_t()
68 $text_to_translate = 'Hello, %name, today is %weekday';
69 $vars_to_replace = array('%name'=>'Bermi','%weekday'=>'monday');
71 $this->assertEqual(Ak::t($text_to_translate),'Hello, %name, today is %weekday','String with tokens but no replacement array given.');
72 $this->assertEqual(Ak::t($text_to_translate),'Hello, %name, today is %weekday','String with tokens but no replacement array given.');
73 $this->assertEqual(Ak::t($text_to_translate,$vars_to_replace),'Hello, Bermi, today is monday');
77 function Test_debug()
79 ob_start();
80 Ak::debug($this->AkTestingObjectInspectionChildInstance);
81 $debug_str = ob_get_contents();
82 ob_end_clean();
84 $this->assertFalse($debug_str == '','Ak::debug not working properly');
88 function Test_get_object_info()
90 $this->assertNotEqual(md5(serialize(Ak::get_object_info($this->AkTestingObjectInspectionChildInstance))),
91 md5(serialize(Ak::get_object_info($this->AkTestingObjectInspectionChildInstance,true))),'Object inspection does not exclude parent class methods');
95 function Test_get_this_object_methods()
97 if(AK_PHP5){
98 $expected_methods = array('AkTestingObjectInspectionChild','child_function','child_method');
99 }else {
100 $expected_methods = array('aktestingobjectinspectionchild','child_function','child_method');
102 $resulting_methods = Ak::get_this_object_methods($this->AkTestingObjectInspectionChildInstance);
103 $this->assertEqual($expected_methods,$resulting_methods);
106 function Test_get_this_object_attributes()
108 $expected_attributes = array('child_var'=>null,'child_var_null'=>null,'child_var_string'=>'abc','child_var_int'=>123);
109 $resulting_attributes = Ak::get_this_object_attributes($this->AkTestingObjectInspectionChildInstance);
110 $this->assertEqual($expected_attributes,$resulting_attributes);
114 function Test_for_getTimestamp()
116 $this->assertEqual(Ak::getTimestamp(), Ak::time());
117 $this->assertEqual('17:52:03', Ak::getDate(Ak::getTimestamp('17:52:03'),'H:i:s'));
118 $this->assertEqual(date('Y-m-d').' 17:52:03', Ak::getDate(Ak::getTimestamp('17:52:03')));
119 $this->assertEqual('2005-12-25 00:00:00', Ak::getDate(Ak::getTimestamp('2005-12-25')));
120 $this->assertEqual('1592-10-09 00:00:00', Ak::getDate(Ak::getTimestamp('1592-10-09')));
121 $this->assertEqual('2192-10-09 00:00:00', Ak::getDate(Ak::getTimestamp('2192-10-09')));
122 $this->assertEqual('2192-10-09 01:02:03', Ak::getDate(Ak::getTimestamp('2192-10-9 01:02:03')));
125 function Test_for_getDate()
130 function Test_of_encrypt_decrypt()
132 $original = "Este es el texto que quiero encriptar";
133 $this->assertEqual(Ak::decrypt(Ak::encrypt($original)), $original);
135 $key = Ak::randomString(20);
136 $file = Ak::file_get_contents(__FILE__);
137 $ecripted = Ak::encrypt($file, $key);
138 $this->assertEqual(Ak::decrypt($ecripted,$key), $file);
143 /**/
145 function Test_of_compress_decompress()
147 $original = Ak::file_get_contents(__FILE__);
148 $compressed = Ak::compress($original);
150 Ak::file_put_contents(AK_TMP_DIR.DS.'gzip_test.gz', $compressed, array('base_path'=>AK_TMP_DIR));
151 $this->assertTrue(strlen($compressed) < strlen($original));
153 $compressed_file = Ak::file_get_contents(AK_TMP_DIR.DS.'gzip_test.gz', array('base_path'=>AK_TMP_DIR));
154 $this->assertEqual($compressed_file, $compressed);
155 $uncompressed_from_file = Ak::uncompress($compressed_file);
156 $uncompressed_from_string = Ak::uncompress($compressed);
157 $this->assertEqual($uncompressed_from_file, $uncompressed_from_string);
160 /**/
162 function Test_for_StatusKeys()
164 $Object = new Ak();
166 $this->assertFalse(Ak::objectHasBeenModified($Object));
168 $this->assertEqual(Ak::getStatusKey($Object), Ak::getStatusKey($Object));
170 $Object->name = 'Bermi';
171 $this->assertTrue(Ak::objectHasBeenModified($Object));
172 $this->assertTrue(Ak::objectHasBeenModified($Object));
174 Ak::resetObjectModificationsWacther($Object);
176 $this->assertFalse(Ak::objectHasBeenModified($Object));
182 ak_test('test_of_Ak_object_inspection',true);