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');
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');
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');
80 Ak
::debug($this->AkTestingObjectInspectionChildInstance
);
81 $debug_str = ob_get_contents();
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()
98 $expected_methods = array('AkTestingObjectInspectionChild','child_function','child_method');
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 function Test_of_compress_decompress()
145 $original = Ak
::file_get_contents(__FILE__
);
146 $compressed = Ak
::compress($original);
147 Ak
::file_put_contents(AK_TEST_DIR
.DS
.'tmp'.DS
.'gzip_test.gz',$compressed);
148 $this->assertTrue(strlen($compressed) < strlen($original));
149 $compressed_file = Ak
::file_get_contents(AK_TEST_DIR
.DS
.'tmp'.DS
.'gzip_test.gz');
150 $this->assertEqual($compressed_file, $compressed);
151 $uncompressed_from_file = Ak
::uncompress($compressed_file);
152 $uncompressed_from_string = Ak
::uncompress($compressed);
153 $this->assertEqual($uncompressed_from_file, $uncompressed_from_string);
157 function Test_for_StatusKeys()
161 $this->assertFalse(Ak
::objectHasBeenModified($Object));
163 $this->assertEqual(Ak
::getStatusKey($Object), Ak
::getStatusKey($Object));
165 $Object->name
= 'Bermi';
166 $this->assertTrue(Ak
::objectHasBeenModified($Object));
167 $this->assertTrue(Ak
::objectHasBeenModified($Object));
169 Ak
::resetObjectModificationsWacther($Object);
171 $this->assertFalse(Ak
::objectHasBeenModified($Object));
177 ak_test('test_of_Ak_object_inspection',true);