PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/ksekar/campus
PHP | 299 lines | 203 code | 35 blank | 61 comment | 5 complexity | 18219b59fc41aa9123fcc41b8368fc04 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 24594 2012-01-05 21:27:01Z matthew $
  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 24594 2012-01-05 21:27:01Z matthew $
  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. $options = array(
  120. 'Username' => 'Zend',
  121. 'Password' => 'Framework',
  122. 'Realm' => 'zend.com',
  123. 'Environment' => Zend_Service_DeveloperGarden_OfflineClient_Mock::ENV_MOCK
  124. );
  125. $this->service = new Zend_Service_DeveloperGarden_OfflineClient_Mock($options);
  126. $this->assertType(
  127. 'Zend_Service_DeveloperGarden_OfflineClient_Mock',
  128. $this->service
  129. );
  130. $this->assertType(
  131. 'Zend_Service_DeveloperGarden_Client_Soap',
  132. $this->service->getSoapClient()
  133. );
  134. }
  135. public function testOnlineWsdl()
  136. {
  137. $this->assertType(
  138. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  139. $this->service->setUseLocalWsdl(false)
  140. );
  141. $this->assertEquals(
  142. 'http://framework.zend.com',
  143. $this->service->getWsdl()
  144. );
  145. }
  146. public function testSetLocalWsdl()
  147. {
  148. $this->assertType(
  149. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  150. $this->service->setLocalWsdl('my.wsdl')
  151. );
  152. $this->assertEquals(
  153. 'my.wsdl',
  154. $this->service->getWsdl()
  155. );
  156. }
  157. public function testSetWsdl()
  158. {
  159. $this->assertType(
  160. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  161. $this->service->setWsdl('http://my.wsdl')
  162. );
  163. $this->assertType(
  164. 'Zend_Service_DeveloperGarden_Client_ClientAbstract',
  165. $this->service->setUseLocalWsdl(false)
  166. );
  167. $this->assertEquals(
  168. 'http://my.wsdl',
  169. $this->service->getWsdl()
  170. );
  171. }
  172. /**
  173. * @expectedException Zend_Service_DeveloperGarden_Exception
  174. */
  175. public function testSetLocalWsdlException()
  176. {
  177. $this->assertNull($this->service->setLocalWsdl(null));
  178. }
  179. /**
  180. * @expectedException Zend_Service_DeveloperGarden_Exception
  181. */
  182. public function testSetWsdlException()
  183. {
  184. $this->assertNull($this->service->setWsdl(null));
  185. }
  186. /**
  187. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  188. */
  189. public function testCheckEnv()
  190. {
  191. $this->assertNull($this->service->checkEnvironment(null));
  192. }
  193. public function testParticipantsAction()
  194. {
  195. $actions = $this->service->getParticipantActions();
  196. $this->assertType(
  197. 'array',
  198. $actions
  199. );
  200. $this->assertEquals(3, count($actions));
  201. }
  202. public function testParticipantsActionValid()
  203. {
  204. $actions = $this->service->getParticipantActions();
  205. foreach ($actions as $k => $v) {
  206. $this->assertNull($this->service->checkParticipantAction($k));
  207. }
  208. }
  209. /**
  210. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  211. */
  212. public function testParticipantsActionInValid()
  213. {
  214. $this->assertNull($this->service->checkParticipantAction('NotValid'));
  215. }
  216. public function testGetClientOptionsWithWsdlCache()
  217. {
  218. $this->assertNull(
  219. Zend_Service_DeveloperGarden_SecurityTokenServer_Cache::setWsdlCache(WSDL_CACHE_BOTH)
  220. );
  221. $options = $this->service->getClientOptions();
  222. $this->assertType(
  223. 'array',
  224. $options
  225. );
  226. $this->assertArrayHasKey('cache_wsdl', $options);
  227. $this->assertEquals(
  228. WSDL_CACHE_BOTH,
  229. $options['cache_wsdl']
  230. );
  231. }
  232. }
  233. class Zend_Service_DeveloperGarden_OfflineClient_Mock
  234. extends Zend_Service_DeveloperGarden_IpLocation
  235. {
  236. protected $_wsdlFile = 'http://framework.zend.com';
  237. protected $_options = array(
  238. 'val1' => null,
  239. 'val2' => null,
  240. 'val3' => null,
  241. 'val4' => null
  242. );
  243. /**
  244. * returns the internal options array
  245. * @return array
  246. */
  247. public function getOptionsArrayRaw()
  248. {
  249. return $this->_options;
  250. }
  251. }
  252. class Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFile_Mock
  253. extends Zend_Service_DeveloperGarden_IpLocation
  254. {
  255. protected $_wsdlFile = null;
  256. }
  257. class Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFileLocal_Mock
  258. extends Zend_Service_DeveloperGarden_IpLocation
  259. {
  260. protected $_wsdlFileLocal = null;
  261. }
  262. if (PHPUnit_MAIN_METHOD == 'Zend_Service_DeveloperGarden_OfflineCredentialTest::main') {
  263. Zend_Service_DeveloperGarden_OfflineCredentialTest::main();
  264. }