PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Service/DeveloperGarden/OfflineClientTest.php

http://github.com/zendframework/zf2
PHP | 284 lines | 191 code | 32 blank | 61 comment | 2 complexity | 223921cbd52989ff80610aeaa131e7bf MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_DeveloperGarden
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Service_DeveloperGarden_IpLocation
  23. */
  24. /**
  25. * Zend_Service_DeveloperGarden test case
  26. *
  27. * @category Zend
  28. * @package Zend_Service_DeveloperGarden
  29. * @subpackage UnitTests
  30. * @group Zend_Service
  31. * @group Zend_Service_DeveloperGarden
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Service_DeveloperGarden_OfflineClientTest extends PHPUnit_Framework_TestCase
  36. {
  37. /**
  38. * @var Zend_Service_DeveloperGarden_OfflineCredential_Mock
  39. */
  40. protected $_service = null;
  41. public function setUp()
  42. {
  43. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN')) {
  44. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'Unknown');
  45. }
  46. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD')) {
  47. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'Unknown');
  48. }
  49. $this->service = new Zend_Service_DeveloperGarden_OfflineClient_Mock();
  50. }
  51. /**
  52. * @expectedException Zend_Service_DeveloperGarden_Exception
  53. */
  54. public function testConstructorCheckWsdl()
  55. {
  56. $client = new Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFile_Mock();
  57. $this->assertNull($client);
  58. }
  59. /**
  60. * @expectedException Zend_Service_DeveloperGarden_Exception
  61. */
  62. public function testConstructorCheckWsdlLocal()
  63. {
  64. $client = new Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFileLocal_Mock();
  65. $this->assertNull($client);
  66. }
  67. public function testOptionsConstructor()
  68. {
  69. $options = array(
  70. 'Username' => md5(microtime()),
  71. 'Password' => md5(microtime()),
  72. 'Realm' => md5(microtime()),
  73. 'Environment' => Zend_Service_DeveloperGarden_OfflineClient_Mock::ENV_MOCK
  74. );
  75. $this->service = new Zend_Service_DeveloperGarden_OfflineClient_Mock($options);
  76. $creds = $this->service->getCredential();
  77. $this->assertEquals($options['Username'], $creds->getUsername());
  78. $this->assertEquals($options['Password'], $creds->getPassword());
  79. $this->assertEquals($options['Realm'], $creds->getRealm());
  80. $this->assertEquals($options['Environment'], $this->service->getEnvironment());
  81. }
  82. public function testSetOptions()
  83. {
  84. $options = array(
  85. 'val1' => md5(microtime()),
  86. 'val2' => md5(microtime()),
  87. 'val3' => md5(microtime()),
  88. 'val4' => md5(microtime())
  89. );
  90. $this->assertNull($this->service->getOption('not_existing'));
  91. foreach ($options as $key => $value) {
  92. $this->assertNull($this->service->getOption($key));
  93. $this->assertType(
  94. 'Zend_Service_DeveloperGarden_Client_AbstractClient',
  95. $this->service->setOption($key, $value)
  96. );
  97. }
  98. }
  99. /**
  100. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  101. */
  102. public function testSetOptionsException()
  103. {
  104. $this->assertNull($this->service->setOption(0x100, 'Foobar'));
  105. $this->assertNull($this->service->setOption(100 , 'Foobar'));
  106. $this->assertNull($this->service->setOption(0100 , 'Foobar'));
  107. }
  108. public function testGetSoapClient()
  109. {
  110. $options = array(
  111. 'Username' => 'Zend',
  112. 'Password' => 'Framework',
  113. 'Realm' => 'zend.com',
  114. 'Environment' => Zend_Service_DeveloperGarden_OfflineClient_Mock::ENV_MOCK
  115. );
  116. $this->service = new Zend_Service_DeveloperGarden_OfflineClient_Mock($options);
  117. $this->assertType(
  118. 'Zend_Service_DeveloperGarden_OfflineClient_Mock',
  119. $this->service
  120. );
  121. $this->assertType(
  122. 'Zend_Service_DeveloperGarden_Client_Soap',
  123. $this->service->getSoapClient()
  124. );
  125. }
  126. public function testOnlineWsdl()
  127. {
  128. $this->assertType(
  129. 'Zend_Service_DeveloperGarden_Client_AbstractClient',
  130. $this->service->setUseLocalWsdl(false)
  131. );
  132. $this->assertEquals(
  133. 'http://framework.zend.com',
  134. $this->service->getWsdl()
  135. );
  136. }
  137. public function testSetLocalWsdl()
  138. {
  139. $this->assertType(
  140. 'Zend_Service_DeveloperGarden_Client_AbstractClient',
  141. $this->service->setLocalWsdl('my.wsdl')
  142. );
  143. $this->assertEquals(
  144. 'my.wsdl',
  145. $this->service->getWsdl()
  146. );
  147. }
  148. public function testSetWsdl()
  149. {
  150. $this->assertType(
  151. 'Zend_Service_DeveloperGarden_Client_AbstractClient',
  152. $this->service->setWsdl('http://my.wsdl')
  153. );
  154. $this->assertType(
  155. 'Zend_Service_DeveloperGarden_Client_AbstractClient',
  156. $this->service->setUseLocalWsdl(false)
  157. );
  158. $this->assertEquals(
  159. 'http://my.wsdl',
  160. $this->service->getWsdl()
  161. );
  162. }
  163. /**
  164. * @expectedException Zend_Service_DeveloperGarden_Exception
  165. */
  166. public function testSetLocalWsdlException()
  167. {
  168. $this->assertNull($this->service->setLocalWsdl(null));
  169. }
  170. /**
  171. * @expectedException Zend_Service_DeveloperGarden_Exception
  172. */
  173. public function testSetWsdlException()
  174. {
  175. $this->assertNull($this->service->setWsdl(null));
  176. }
  177. /**
  178. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  179. */
  180. public function testCheckEnv()
  181. {
  182. $this->assertNull($this->service->checkEnvironment(null));
  183. }
  184. public function testParticipantsAction()
  185. {
  186. $actions = $this->service->getParticipantActions();
  187. $this->assertType(
  188. 'array',
  189. $actions
  190. );
  191. $this->assertEquals(3, count($actions));
  192. }
  193. public function testParticipantsActionValid()
  194. {
  195. $actions = $this->service->getParticipantActions();
  196. foreach ($actions as $k => $v) {
  197. $this->assertNull($this->service->checkParticipantAction($k));
  198. }
  199. }
  200. /**
  201. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  202. */
  203. public function testParticipantsActionInValid()
  204. {
  205. $this->assertNull($this->service->checkParticipantAction('NotValid'));
  206. }
  207. public function testGetClientOptionsWithWsdlCache()
  208. {
  209. $this->assertNull(
  210. Zend_Service_DeveloperGarden_SecurityTokenServer_Cache::setWsdlCache(WSDL_CACHE_BOTH)
  211. );
  212. $options = $this->service->getClientOptions();
  213. $this->assertType(
  214. 'array',
  215. $options
  216. );
  217. $this->assertArrayHasKey('cache_wsdl', $options);
  218. $this->assertEquals(
  219. WSDL_CACHE_BOTH,
  220. $options['cache_wsdl']
  221. );
  222. }
  223. }
  224. class Zend_Service_DeveloperGarden_OfflineClient_Mock
  225. extends Zend_Service_DeveloperGarden_IpLocation
  226. {
  227. protected $_wsdlFile = 'http://framework.zend.com';
  228. protected $_options = array(
  229. 'val1' => null,
  230. 'val2' => null,
  231. 'val3' => null,
  232. 'val4' => null
  233. );
  234. /**
  235. * returns the internal options array
  236. * @return array
  237. */
  238. public function getOptionsArrayRaw()
  239. {
  240. return $this->_options;
  241. }
  242. }
  243. class Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFile_Mock
  244. extends Zend_Service_DeveloperGarden_IpLocation
  245. {
  246. protected $_wsdlFile = null;
  247. }
  248. class Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFileLocal_Mock
  249. extends Zend_Service_DeveloperGarden_IpLocation
  250. {
  251. protected $_wsdlFileLocal = null;
  252. }