OfflineClientTest.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @version $Id$
  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->assertTrue(
  103. $this->service->setOption($key, $value) instanceof Zend_Service_DeveloperGarden_Client_ClientAbstract
  104. );
  105. }
  106. }
  107. /**
  108. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  109. */
  110. public function testSetOptionsException()
  111. {
  112. $this->assertNull($this->service->setOption(0x100, 'Foobar'));
  113. $this->assertNull($this->service->setOption(100 , 'Foobar'));
  114. $this->assertNull($this->service->setOption(0100 , 'Foobar'));
  115. }
  116. public function testGetSoapClient()
  117. {
  118. if (!extension_loaded('soap')) {
  119. $this->markTestSkipped('SOAP extension is not loaded');
  120. }
  121. $options = array(
  122. 'Username' => 'Zend',
  123. 'Password' => 'Framework',
  124. 'Realm' => 'zend.com',
  125. 'Environment' => Zend_Service_DeveloperGarden_OfflineClient_Mock::ENV_MOCK
  126. );
  127. $this->service = new Zend_Service_DeveloperGarden_OfflineClient_Mock($options);
  128. $this->assertTrue(
  129. $this->service instanceof Zend_Service_DeveloperGarden_OfflineClient_Mock
  130. );
  131. $this->assertTrue(
  132. $this->service->getSoapClient() instanceof Zend_Service_DeveloperGarden_Client_Soap
  133. );
  134. }
  135. public function testOnlineWsdl()
  136. {
  137. $this->assertTrue(
  138. $this->service->setUseLocalWsdl(false) instanceof Zend_Service_DeveloperGarden_Client_ClientAbstract
  139. );
  140. $this->assertEquals(
  141. 'http://framework.zend.com',
  142. $this->service->getWsdl()
  143. );
  144. }
  145. public function testSetLocalWsdl()
  146. {
  147. $this->assertTrue(
  148. $this->service->setLocalWsdl('my.wsdl') instanceof Zend_Service_DeveloperGarden_Client_ClientAbstract
  149. );
  150. $this->assertEquals(
  151. 'my.wsdl',
  152. $this->service->getWsdl()
  153. );
  154. }
  155. public function testSetWsdl()
  156. {
  157. $this->assertTrue(
  158. $this->service->setWsdl('http://my.wsdl') instanceof Zend_Service_DeveloperGarden_Client_ClientAbstract
  159. );
  160. $this->assertTrue(
  161. $this->service->setUseLocalWsdl(false) instanceof Zend_Service_DeveloperGarden_Client_ClientAbstract
  162. );
  163. $this->assertEquals(
  164. 'http://my.wsdl',
  165. $this->service->getWsdl()
  166. );
  167. }
  168. /**
  169. * @expectedException Zend_Service_DeveloperGarden_Exception
  170. */
  171. public function testSetLocalWsdlException()
  172. {
  173. $this->assertNull($this->service->setLocalWsdl(null));
  174. }
  175. /**
  176. * @expectedException Zend_Service_DeveloperGarden_Exception
  177. */
  178. public function testSetWsdlException()
  179. {
  180. $this->assertNull($this->service->setWsdl(null));
  181. }
  182. /**
  183. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  184. */
  185. public function testCheckEnv()
  186. {
  187. $this->assertNull($this->service->checkEnvironment(null));
  188. }
  189. public function testParticipantsAction()
  190. {
  191. $actions = $this->service->getParticipantActions();
  192. $this->assertTrue(is_array($actions));
  193. $this->assertEquals(3, count($actions));
  194. }
  195. public function testParticipantsActionValid()
  196. {
  197. $actions = $this->service->getParticipantActions();
  198. foreach ($actions as $k => $v) {
  199. $this->assertNull($this->service->checkParticipantAction($k));
  200. }
  201. }
  202. /**
  203. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  204. */
  205. public function testParticipantsActionInValid()
  206. {
  207. $this->assertNull($this->service->checkParticipantAction('NotValid'));
  208. }
  209. public function testGetClientOptionsWithWsdlCache()
  210. {
  211. if (!extension_loaded('soap')) {
  212. $this->markTestSkipped('SOAP extension is not loaded');
  213. }
  214. $this->assertNull(
  215. Zend_Service_DeveloperGarden_SecurityTokenServer_Cache::setWsdlCache(WSDL_CACHE_BOTH)
  216. );
  217. $options = $this->service->getClientOptions();
  218. $this->assertTrue(is_array($options));
  219. $this->assertArrayHasKey('cache_wsdl', $options);
  220. $this->assertEquals(
  221. WSDL_CACHE_BOTH,
  222. $options['cache_wsdl']
  223. );
  224. }
  225. }
  226. class Zend_Service_DeveloperGarden_OfflineClient_Mock
  227. extends Zend_Service_DeveloperGarden_IpLocation
  228. {
  229. protected $_wsdlFile = 'http://framework.zend.com';
  230. protected $_options = array(
  231. 'val1' => null,
  232. 'val2' => null,
  233. 'val3' => null,
  234. 'val4' => null
  235. );
  236. /**
  237. * returns the internal options array
  238. * @return array
  239. */
  240. public function getOptionsArrayRaw()
  241. {
  242. return $this->_options;
  243. }
  244. }
  245. class Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFile_Mock
  246. extends Zend_Service_DeveloperGarden_IpLocation
  247. {
  248. protected $_wsdlFile = null;
  249. }
  250. class Zend_Service_DeveloperGarden_OfflineClientIncompleteWsdlFileLocal_Mock
  251. extends Zend_Service_DeveloperGarden_IpLocation
  252. {
  253. protected $_wsdlFileLocal = null;
  254. }
  255. if (PHPUnit_MAIN_METHOD == 'Zend_Service_DeveloperGarden_OfflineCredentialTest::main') {
  256. Zend_Service_DeveloperGarden_OfflineCredentialTest::main();
  257. }