OfflineBaseUserServiceTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_BaseUserServiceTest::main');
  24. }
  25. /**
  26. * @see Zend_Service_DeveloperGarden_BaseUserService
  27. */
  28. require_once 'Zend/Service/DeveloperGarden/BaseUserService.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_OfflineBaseUserServiceTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * @todo add more tests for the ClientAbstract
  43. */
  44. /**
  45. * @var Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock
  46. */
  47. protected $_service = null;
  48. protected $_limit = 10;
  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. $config = array(
  63. 'username' => TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN,
  64. 'password' => TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD,
  65. );
  66. $this->service = new Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock($config);
  67. }
  68. public function testGetModuleIds()
  69. {
  70. $ids = $this->service->getModuleIds();
  71. $this->assertTrue(is_array($ids));
  72. $this->assertNotNull($ids);
  73. $this->assertGreaterThan(0, count($ids));
  74. }
  75. /**
  76. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  77. */
  78. public function testBuildModuleStringThrowsException()
  79. {
  80. $this->service->getBuildModuleString('foo', 'bar');
  81. }
  82. public function testBuildModuleStringSandbox()
  83. {
  84. $modules = array('Sms', 'localsearch', 'IPLocation', 'CCS', 'VoiceButler');
  85. foreach ($modules as $v) {
  86. $ret = $this->service->getBuildModuleString(
  87. $v,
  88. Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock::ENV_SANDBOX
  89. );
  90. $this->assertNotNull($ret);
  91. }
  92. }
  93. public function testBuildModuleStringProduction()
  94. {
  95. $modules = array('Sms', 'localsearch', 'IPLocation', 'CCS', 'VoiceButler');
  96. foreach ($modules as $v) {
  97. $ret = $this->service->getBuildModuleString(
  98. $v,
  99. Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock::ENV_PRODUCTION
  100. );
  101. $this->assertNotNull($ret);
  102. }
  103. }
  104. /**
  105. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  106. */
  107. public function testBuildModuleStringMockMustFail()
  108. {
  109. $modules = array('Sms', 'localsearch', 'IPLocation', 'CCS', 'VoiceButler');
  110. foreach ($modules as $v) {
  111. $ret = $this->service->getBuildModuleString(
  112. $v,
  113. Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock::ENV_MOCK
  114. );
  115. $this->assertNotNull($ret);
  116. }
  117. }
  118. public function testModuleIds()
  119. {
  120. $moduleIds = $this->service->getModuleIds();
  121. $this->assertTrue(is_array($moduleIds));
  122. $this->assertEquals(10, count($moduleIds));
  123. }
  124. /**
  125. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  126. */
  127. public function testModuleIdsException()
  128. {
  129. $this->service->checkModuleId('WRONG');
  130. }
  131. /**
  132. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  133. */
  134. public function testBuildModuleStringException()
  135. {
  136. $this->service->buildModuleString(
  137. 'WrongModule',
  138. Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock::ENV_SANDBOX
  139. );
  140. }
  141. public function testGetCredentialOnSoapObject()
  142. {
  143. if (!extension_loaded('soap')) {
  144. $this->markTestSkipped('SOAP extension is not loaded');
  145. }
  146. $this->assertTrue(
  147. $this->service->getSoapClient()->getCredential() instanceof Zend_Service_DeveloperGarden_Credential
  148. );
  149. }
  150. public function testGetTokenServiceOnSoapObject()
  151. {
  152. if (!extension_loaded('soap')) {
  153. $this->markTestSkipped('SOAP extension is not loaded');
  154. }
  155. $this->assertTrue(
  156. $this->service->getSoapClient()->getTokenService() instanceof Zend_Service_DeveloperGarden_SecurityTokenServer
  157. );
  158. }
  159. }
  160. class Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock
  161. extends Zend_Service_DeveloperGarden_BaseUserService
  162. {
  163. /**
  164. * returns the correct module string
  165. *
  166. * @param string $module
  167. * @param integer $environment
  168. * @return string
  169. */
  170. public function getBuildModuleString($module, $environment)
  171. {
  172. return $this->_buildModuleString($module, $environment);
  173. }
  174. public function checkModuleId($moduleId)
  175. {
  176. return $this->_checkModuleId($moduleId);
  177. }
  178. public function buildModuleString($module, $environment)
  179. {
  180. return $this->_buildModuleString($module, $environment);
  181. }
  182. }
  183. if (PHPUnit_MAIN_METHOD == 'Zend_Service_DeveloperGarden_OfflineBaseUserServiceTest::main') {
  184. Zend_Service_DeveloperGarden_OfflineBaseUserServiceTest::main();
  185. }