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

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

https://bitbucket.org/dbaltas/zend-framework-1.x-on-git
PHP | 307 lines | 209 code | 37 blank | 61 comment | 7 complexity | e99ca3d3591a287ed9484ead6d311f89 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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. * @version $Id: OfflineClientTest.php 24791 2012-05-11 06:18:17Z bate $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Service_DeveloperGarden_CredentialTest::main');
  24. }
  25. /**
  26. * @see Zend_Service_DeveloperGarden_IpLocation
  27. */
  28. require_once 'Zend/Service/DeveloperGarden/IpLocation.php';
  29. /**
  30. * Zend_Service_DeveloperGarden test case
  31. *
  32. * @category Zend
  33. * @package Zend_Service_DeveloperGarden
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @version $Id: OfflineClientTest.php 24791 2012-05-11 06:18:17Z bate $
  38. */
  39. class Zend_Service_DeveloperGarden_OfflineClientTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * @var Zend_Service_DeveloperGarden_OfflineCredential_Mock
  43. */
  44. protected $_service = null;
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  48. PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. public function setUp()
  51. {
  52. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN')) {
  53. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'Unknown');
  54. }
  55. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD')) {
  56. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'Unknown');
  57. }
  58. $this->service = new Zend_Service_DeveloperGarden_OfflineClient_Mock();
  59. }
  60. /**
  61. * @expectedException Zend_Service_DeveloperGarden_Exception
  62. */
  63. public function testConstructorCheckWsdl()
  64. {
  65. $client = new Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFile_Mock();
  66. $this->assertNull($client);
  67. }
  68. /**
  69. * @expectedException Zend_Service_DeveloperGarden_Exception
  70. */
  71. public function testConstructorCheckWsdlLocal()
  72. {
  73. $client = new Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFileLocal_Mock();
  74. $this->assertNull($client);
  75. }
  76. public function testOptionsConstructor()
  77. {
  78. $options = array(
  79. 'Username' => md5(microtime()),
  80. 'Password' => md5(microtime()),
  81. 'Realm' => md5(microtime()),
  82. 'Environment' => Zend_Service_DeveloperGarden_OfflineClient_Mock::ENV_MOCK
  83. );
  84. $this->service = new Zend_Service_DeveloperGarden_OfflineClient_Mock($options);
  85. $creds = $this->service->getCredential();
  86. $this->assertEquals($options['Username'], $creds->getUsername());
  87. $this->assertEquals($options['Password'], $creds->getPassword());
  88. $this->assertEquals($options['Realm'], $creds->getRealm());
  89. $this->assertEquals($options['Environment'], $this->service->getEnvironment());
  90. }
  91. public function testSetOptions()
  92. {
  93. $options = array(
  94. 'val1' => md5(microtime()),
  95. 'val2' => md5(microtime()),
  96. 'val3' => md5(microtime()),
  97. 'val4' => md5(microtime())
  98. );
  99. $this->assertNull($this->service->getOption('not_existing'));
  100. foreach ($options as $key => $value) {
  101. $this->assertNull($this->service->getOption($key));
  102. $this->assertType(
  103. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  104. $this->service->setOption($key, $value)
  105. );
  106. }
  107. }
  108. /**
  109. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  110. */
  111. public function testSetOptionsException()
  112. {
  113. $this->assertNull($this->service->setOption(0x100, 'Foobar'));
  114. $this->assertNull($this->service->setOption(100 , 'Foobar'));
  115. $this->assertNull($this->service->setOption(0100 , 'Foobar'));
  116. }
  117. public function testGetSoapClient()
  118. {
  119. if (!extension_loaded('soap')) {
  120. $this->markTestSkipped('SOAP extension is not loaded');
  121. }
  122. $options = array(
  123. 'Username' => 'Zend',
  124. 'Password' => 'Framework',
  125. 'Realm' => 'zend.com',
  126. 'Environment' => Zend_Service_DeveloperGarden_OfflineClient_Mock::ENV_MOCK
  127. );
  128. $this->service = new Zend_Service_DeveloperGarden_OfflineClient_Mock($options);
  129. $this->assertType(
  130. 'Zend_Service_DeveloperGarden_OfflineClient_Mock',
  131. $this->service
  132. );
  133. $this->assertType(
  134. 'Zend_Service_DeveloperGarden_Client_Soap',
  135. $this->service->getSoapClient()
  136. );
  137. }
  138. public function testOnlineWsdl()
  139. {
  140. $this->assertType(
  141. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  142. $this->service->setUseLocalWsdl(false)
  143. );
  144. $this->assertEquals(
  145. 'http://framework.zend.com',
  146. $this->service->getWsdl()
  147. );
  148. }
  149. public function testSetLocalWsdl()
  150. {
  151. $this->assertType(
  152. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  153. $this->service->setLocalWsdl('my.wsdl')
  154. );
  155. $this->assertEquals(
  156. 'my.wsdl',
  157. $this->service->getWsdl()
  158. );
  159. }
  160. public function testSetWsdl()
  161. {
  162. $this->assertType(
  163. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  164. $this->service->setWsdl('http://my.wsdl')
  165. );
  166. $this->assertType(
  167. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  168. $this->service->setUseLocalWsdl(false)
  169. );
  170. $this->assertEquals(
  171. 'http://my.wsdl',
  172. $this->service->getWsdl()
  173. );
  174. }
  175. /**
  176. * @expectedException Zend_Service_DeveloperGarden_Exception
  177. */
  178. public function testSetLocalWsdlException()
  179. {
  180. $this->assertNull($this->service->setLocalWsdl(null));
  181. }
  182. /**
  183. * @expectedException Zend_Service_DeveloperGarden_Exception
  184. */
  185. public function testSetWsdlException()
  186. {
  187. $this->assertNull($this->service->setWsdl(null));
  188. }
  189. /**
  190. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  191. */
  192. public function testCheckEnv()
  193. {
  194. $this->assertNull($this->service->checkEnvironment(null));
  195. }
  196. public function testParticipantsAction()
  197. {
  198. $actions = $this->service->getParticipantActions();
  199. $this->assertType(
  200. 'array',
  201. $actions
  202. );
  203. $this->assertEquals(3, count($actions));
  204. }
  205. public function testParticipantsActionValid()
  206. {
  207. $actions = $this->service->getParticipantActions();
  208. foreach ($actions as $k => $v) {
  209. $this->assertNull($this->service->checkParticipantAction($k));
  210. }
  211. }
  212. /**
  213. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  214. */
  215. public function testParticipantsActionInValid()
  216. {
  217. $this->assertNull($this->service->checkParticipantAction('NotValid'));
  218. }
  219. public function testGetClientOptionsWithWsdlCache()
  220. {
  221. if (!extension_loaded('soap')) {
  222. $this->markTestSkipped('SOAP extension is not loaded');
  223. }
  224. $this->assertNull(
  225. Zend_Service_DeveloperGarden_SecurityTokenServer_Cache::setWsdlCache(WSDL_CACHE_BOTH)
  226. );
  227. $options = $this->service->getClientOptions();
  228. $this->assertType(
  229. 'array',
  230. $options
  231. );
  232. $this->assertArrayHasKey('cache_wsdl', $options);
  233. $this->assertEquals(
  234. WSDL_CACHE_BOTH,
  235. $options['cache_wsdl']
  236. );
  237. }
  238. }
  239. class Zend_Service_DeveloperGarden_OfflineClient_Mock
  240. extends Zend_Service_DeveloperGarden_IpLocation
  241. {
  242. protected $_wsdlFile = 'http://framework.zend.com';
  243. protected $_options = array(
  244. 'val1' => null,
  245. 'val2' => null,
  246. 'val3' => null,
  247. 'val4' => null
  248. );
  249. /**
  250. * returns the internal options array
  251. * @return array
  252. */
  253. public function getOptionsArrayRaw()
  254. {
  255. return $this->_options;
  256. }
  257. }
  258. class Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFile_Mock
  259. extends Zend_Service_DeveloperGarden_IpLocation
  260. {
  261. protected $_wsdlFile = null;
  262. }
  263. class Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFileLocal_Mock
  264. extends Zend_Service_DeveloperGarden_IpLocation
  265. {
  266. protected $_wsdlFileLocal = null;
  267. }
  268. if (PHPUnit_MAIN_METHOD == 'Zend_Service_DeveloperGarden_OfflineCredentialTest::main') {
  269. Zend_Service_DeveloperGarden_OfflineCredentialTest::main();
  270. }