Adding tests for securing private variable inclussion on templates.
[akelos.git] / test / unit / lib / AkActionWebService / AkActionWebServiceApi.php
blobedfdb224a7c91e3ca4b14a786a2b0c94d981a665
1 <?php
3 defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);
4 require_once(dirname(__FILE__).'/../../../fixtures/config/config.php');
7 require_once(AK_LIB_DIR.DS.'AkActionWebService'.DS.'AkActionWebServiceApi.php');
8 require_once(AK_LIB_DIR.DS.'AkActionWebService.php');
9 require_once(AK_APIS_DIR.DS.'todo_api.php');
12 class AkActionWebServiceApiTests extends UnitTestCase
15 function test_web_service_api()
17 $TodoApi =& new TodoApi();
19 // hasApiMethod
20 $this->assertTrue($TodoApi->hasApiMethod('create_list'));
21 $this->assertFalse($TodoApi->hasApiMethod('call the queen'));
22 $this->assertFalse($TodoApi->hasApiMethod('CreateList'));
24 // hasPublicApiMethod
25 $this->assertTrue($TodoApi->hasPublicApiMethod('CreateList'));
26 $this->assertFalse($TodoApi->hasPublicApiMethod('create_list'));
27 $this->assertFalse($TodoApi->hasPublicApiMethod('CallAlice'));
29 // getPublicApiMethodName
30 $this->assertEqual($TodoApi->getPublicApiMethodName('call ali') , 'CallAli');
31 $TodoApi->inflect_names = false;
32 $this->assertEqual($TodoApi->getPublicApiMethodName('call ali') , 'call ali');
33 $TodoApi->inflect_names = true;
35 // getApiMethodName
36 $this->assertEqual($TodoApi->getApiMethodName('CreateList'), 'create_list');
38 $api_methods =& $TodoApi->getApiMethods();
39 $methods = array_keys($api_methods);
41 foreach ($methods as $method_name){
42 $this->assertEqual(strtolower(get_class($api_methods[$method_name])), 'akactionwebservicemethod');
44 $this->assertReference($api_methods[$method_name], $TodoApi->getPublicApiMethodInstance($TodoApi->getPublicApiMethodName($method_name)));
45 $this->assertReference($api_methods[$method_name], $TodoApi->getApiMethodInstance($method_name));
49 $this->assertFalse($TodoApi->getDefaultApiMethodInstance());
51 $TodoApi->default_api_method = $method_name;
52 $TodoApi->default_api_method_instance =& $api_methods[$method_name];
53 $this->assertReference($api_methods[$method_name], $TodoApi->getDefaultApiMethodInstance());
55 $TodoApi->default_api_method = $methods[0];
56 $TodoApi->default_api_method_instance = false;
57 $ApiInstance = $TodoApi->getDefaultApiMethodInstance();
58 $this->assertEqual($api_methods[$TodoApi->default_api_method]->name, $ApiInstance->name);
61 $this->assertEqual($TodoApi->_getApiPublicMethodNames(), array_map(array($TodoApi, 'getPublicApiMethodName'), $methods));
63 //echo "<pre>".print_r($TodoApi,true)."</pre>";
66 function test_service_generator()
68 $TodoApi =& new TodoApi();
69 ob_start();
70 require_once(AK_LIB_DIR.DS.'utils'.DS.'generators'.DS.'AkelosGenerator.php');
71 $Generator = new AkelosGenerator();
72 $Generator->runCommand('service Todo');
73 ob_end_clean();
74 require_once(AK_MODELS_DIR.DS.'todo_service.php');
75 $TodoService =& new TodoService();
76 foreach (array_keys($TodoApi->getApiMethods()) as $method){
77 $this->assertTrue(method_exists($TodoService, $method));
81 function test_clear()
83 Ak::file_delete(AK_MODELS_DIR.DS.'todo_service.php');
88 ak_test('AkActionWebServiceApiTests',true);