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
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
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;
48 $this->AkTestingObjectInspectionChildInstance
= new AkTestingObjectInspectionChild();
53 unset($this->AkTestingObjectInspectionChildInstance
);
59 require_once(AK_CONTRIB_DIR
.'/adodb/adodb.inc.php');
61 if(substr($GLOBALS['ak_test_db_dns'], 0, 6) == 'mysql:'){
62 $GLOBALS['ak_test_db_dns'] = substr_replace($GLOBALS['ak_test_db_dns'], 'mysqlt:', 0, 6);
65 $db =& Ak
::db($GLOBALS['ak_test_db_dns']);
66 $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"]');
67 $this->assertReference($db,Ak
::db($GLOBALS['ak_test_db_dns']),'Checking db connection singleton');
72 $text_to_translate = 'Hello, %name, today is %weekday';
73 $vars_to_replace = array('%name'=>'Bermi','%weekday'=>'monday');
75 $this->assertEqual(Ak
::t($text_to_translate),'Hello, %name, today is %weekday','String with tokens but no replacement array given.');
76 $this->assertEqual(Ak
::t($text_to_translate),'Hello, %name, today is %weekday','String with tokens but no replacement array given.');
77 $this->assertEqual(Ak
::t($text_to_translate,$vars_to_replace),'Hello, Bermi, today is monday');
84 Ak
::debug($this->AkTestingObjectInspectionChildInstance
);
85 $debug_str = ob_get_contents();
88 $this->assertFalse($debug_str == '','Ak::debug not working properly');
92 function Test_get_object_info()
94 $this->assertNotEqual(md5(serialize(Ak
::get_object_info($this->AkTestingObjectInspectionChildInstance
))),
95 md5(serialize(Ak
::get_object_info($this->AkTestingObjectInspectionChildInstance
,true))),'Object inspection does not exclude parent class methods');
99 function Test_get_this_object_methods()
102 $expected_methods = array('AkTestingObjectInspectionChild','child_function','child_method');
104 $expected_methods = array('aktestingobjectinspectionchild','child_function','child_method');
106 $resulting_methods = Ak
::get_this_object_methods($this->AkTestingObjectInspectionChildInstance
);
107 $this->assertEqual($expected_methods,$resulting_methods);
110 function Test_get_this_object_attributes()
112 $expected_attributes = array('child_var'=>null,'child_var_null'=>null,'child_var_string'=>'abc','child_var_int'=>123);
113 $resulting_attributes = Ak
::get_this_object_attributes($this->AkTestingObjectInspectionChildInstance
);
114 $this->assertEqual($expected_attributes,$resulting_attributes);
118 function Test_for_getTimestamp()
120 $this->assertEqual(Ak
::getTimestamp(), Ak
::time());
121 $this->assertEqual('17:52:03', Ak
::getDate(Ak
::getTimestamp('17:52:03'),'H:i:s'));
122 $this->assertEqual(date('Y-m-d').' 17:52:03', Ak
::getDate(Ak
::getTimestamp('17:52:03')));
123 $this->assertEqual('2005-12-25 00:00:00', Ak
::getDate(Ak
::getTimestamp('2005-12-25')));
124 $this->assertEqual('1592-10-09 00:00:00', Ak
::getDate(Ak
::getTimestamp('1592-10-09')));
125 $this->assertEqual('2192-10-09 00:00:00', Ak
::getDate(Ak
::getTimestamp('2192-10-09')));
126 $this->assertEqual('2192-10-09 01:02:03', Ak
::getDate(Ak
::getTimestamp('2192-10-9 01:02:03')));
129 function Test_for_getDate()
134 function Test_of_encrypt_decrypt()
136 $original = "Este es el texto que quiero encriptar";
137 $this->assertEqual(Ak
::decrypt(Ak
::encrypt($original)), $original);
139 $key = Ak
::randomString(20);
140 $file = Ak
::file_get_contents(__FILE__
);
141 $ecripted = Ak
::encrypt($file, $key);
142 $this->assertEqual(Ak
::decrypt($ecripted,$key), $file);
147 function Test_of_compress_decompress()
149 $original = Ak
::file_get_contents(__FILE__
);
150 $compressed = Ak
::compress($original);
151 Ak
::file_put_contents(AK_TEST_DIR
.DS
.'tmp'.DS
.'gzip_test.gz',$compressed);
152 $this->assertTrue(strlen($compressed) < strlen($original));
153 $compressed_file = Ak
::file_get_contents(AK_TEST_DIR
.DS
.'tmp'.DS
.'gzip_test.gz');
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);
161 function Test_for_StatusKeys()
165 $this->assertFalse(Ak
::objectHasBeenModified($Object));
167 $this->assertEqual(Ak
::getStatusKey($Object), Ak
::getStatusKey($Object));
169 $Object->name
= 'Bermi';
170 $this->assertTrue(Ak
::objectHasBeenModified($Object));
171 $this->assertTrue(Ak
::objectHasBeenModified($Object));
173 Ak
::resetObjectModificationsWacther($Object);
175 $this->assertFalse(Ak
::objectHasBeenModified($Object));
181 ak_test('test_of_Ak_object_inspection',true);