OfflineBaseUserServiceTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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_BaseUserServiceTest::main');
  24. }
  25. /**
  26. * Test helper
  27. */
  28. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  29. /**
  30. * @see Zend_Service_DeveloperGarden_BaseUserService
  31. */
  32. require_once 'Zend/Service/DeveloperGarden/BaseUserService.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_OfflineBaseUserServiceTest extends PHPUnit_Framework_TestCase
  44. {
  45. /**
  46. * @todo add more tests for the ClientAbstract
  47. */
  48. /**
  49. * @var Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock
  50. */
  51. protected $_service = null;
  52. protected $_limit = 10;
  53. public static function main()
  54. {
  55. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  56. PHPUnit_TextUI_TestRunner::run($suite);
  57. }
  58. public function setUp()
  59. {
  60. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN')) {
  61. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'Unknown');
  62. }
  63. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD')) {
  64. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'Unknown');
  65. }
  66. $config = array(
  67. 'username' => TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN,
  68. 'password' => TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD,
  69. );
  70. $this->service = new Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock($config);
  71. }
  72. public function testGetModuleIds()
  73. {
  74. $ids = $this->service->getModuleIds();
  75. $this->assertType('array', $ids);
  76. $this->assertNotNull($ids);
  77. $this->assertGreaterThan(0, count($ids));
  78. }
  79. /**
  80. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  81. */
  82. public function testBuildModuleStringThrowsException()
  83. {
  84. $this->service->getBuildModuleString('foo', 'bar');
  85. }
  86. public function testBuildModuleStringSandbox()
  87. {
  88. $modules = array('Sms', 'localsearch', 'IPLocation', 'CCS', 'VoiceButler');
  89. foreach ($modules as $v) {
  90. $ret = $this->service->getBuildModuleString(
  91. $v,
  92. Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock::ENV_SANDBOX
  93. );
  94. $this->assertNotNull($ret);
  95. }
  96. }
  97. public function testBuildModuleStringProduction()
  98. {
  99. $modules = array('Sms', 'localsearch', 'IPLocation', 'CCS', 'VoiceButler');
  100. foreach ($modules as $v) {
  101. $ret = $this->service->getBuildModuleString(
  102. $v,
  103. Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock::ENV_PRODUCTION
  104. );
  105. $this->assertNotNull($ret);
  106. }
  107. }
  108. /**
  109. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  110. */
  111. public function testBuildModuleStringMockMustFail()
  112. {
  113. $modules = array('Sms', 'localsearch', 'IPLocation', 'CCS', 'VoiceButler');
  114. foreach ($modules as $v) {
  115. $ret = $this->service->getBuildModuleString(
  116. $v,
  117. Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock::ENV_MOCK
  118. );
  119. $this->assertNotNull($ret);
  120. }
  121. }
  122. public function testModuleIds()
  123. {
  124. $moduleIds = $this->service->getModuleIds();
  125. $this->assertType('array', $moduleIds);
  126. $this->assertEquals(10, count($moduleIds));
  127. }
  128. /**
  129. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  130. */
  131. public function testModuleIdsException()
  132. {
  133. $this->service->checkModuleId('WRONG');
  134. }
  135. /**
  136. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  137. */
  138. public function testBuildModuleStringException()
  139. {
  140. $this->service->buildModuleString(
  141. 'WrongModule',
  142. Zend_Service_DeveloperGarden_OfflineBaseUserService_Mock::ENV_SANDBOX
  143. );
  144. }
  145. public function testGetCredentialOnSoapObject()
  146. {
  147. $this->assertType(
  148. 'Zend_Service_DeveloperGarden_Credential',
  149. $this->service->getSoapClient()->getCredential()
  150. );
  151. }
  152. public function testGetTokenServiceOnSoapObject()
  153. {
  154. $this->assertType(
  155. 'Zend_Service_DeveloperGarden_SecurityTokenServer',
  156. $this->service->getSoapClient()->getTokenService()
  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. }