OfflineClientTest.php 8.8 KB

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