PageRenderTime 107ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/OX/Dal/Market/tests/unit/RegistrationClient.lib.test.php

https://bitbucket.org/valmy/openx
PHP | 147 lines | 84 code | 26 blank | 37 comment | 0 complexity | 4b823dcd08240a73ba87cf04aeec1548 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: RegistrationClient.lib.test.php 42506 2009-09-02 09:33:27Z lukasz.wikierski $
  25. */
  26. require_once MAX_PATH . '/lib/OX/PC/API/SimpleClient.php';
  27. require_once dirname(dirname(__FILE__)) . '/util/RegistrationTestClient.php';
  28. /**
  29. * A class for testing the Registration Client
  30. *
  31. * @package OpenX
  32. * @subpackage TestSuite
  33. * @author Lukasz Wikierski <lukasz.wikierski@openx.org>
  34. */
  35. class OX_Dal_Market_RegistrationClientTest extends UnitTestCase
  36. {
  37. private $aMarketConfig;
  38. private $platformHash;
  39. public function __construct()
  40. {
  41. parent::__construct();
  42. Mock::generatePartial(
  43. 'OX_M2M_PearXmlRpcCustomClientExecutor',
  44. 'PartialMock_PearXmlRpcCustomClientExecutor',
  45. array('call')
  46. );
  47. $this->aMarketConfig = array(
  48. 'marketPcApiHost' => 'https://pc.host',
  49. 'fallbackPcApiHost' => 'http://pc.fallback',
  50. 'marketPublicApiUrl' => 'url/api/xml-rpc',
  51. );
  52. $this->platformHash = 'ph';
  53. }
  54. public function test__construct()
  55. {
  56. $regClient = new RegistrationTestClient($this->aMarketConfig, $this->platformHash);
  57. $pcApiClient = $regClient->getPcApiClient();
  58. $this->assertIsA($regClient, 'OX_Dal_Market_RegistrationClient');
  59. $this->assertIsA($pcApiClient, 'OX_PC_API_SimpleClient');
  60. }
  61. public function testCreateAccountBySsoCred()
  62. {
  63. $username = 'testUser';
  64. $password = 'testPass';
  65. $md5password = md5($password);
  66. $call = array('createAccountBySsoCred', array($username, $md5password, $this->platformHash));
  67. $response = array('accountUuid' => 'pub-acc-id', 'apiKey' => 'api-key');
  68. $regClient = $this->_prepareRegistrationClient(array(array('arguments' => $call, 'response' => $response)));
  69. $result = $regClient->createAccountBySsoCred($username, $password);
  70. $this->assertEqual($result, $response);
  71. }
  72. public function testCreateAccount()
  73. {
  74. $email = 'test@email.com';
  75. $username = 'testUser';
  76. $password = 'testPass';
  77. $md5password = md5($password);
  78. $captcha = 'captcha';
  79. $captcha_random = '21343451';
  80. $call = array('createAccount', array($email, $username, $md5password, $captcha, $captcha_random, $this->platformHash));
  81. $response = array('accountUuid' => 'pub-acc-id', 'apiKey' => 'api-key');
  82. $regClient = $this->_prepareRegistrationClient(array(array('arguments' => $call, 'response' => $response)));
  83. $result = $regClient->createAccount($email, $username, $password, $captcha, $captcha_random);
  84. $this->assertEqual($result, $response);
  85. }
  86. public function testIsSsoUserNameAvailable()
  87. {
  88. $userName1 = 'ada';
  89. $userName2 = 'adam';
  90. $calls = array(
  91. array('arguments' => array('isSsoUserNameAvailable', array($userName1)),
  92. 'response' => true),
  93. array('arguments' => array('isSsoUserNameAvailable', array($userName2)),
  94. 'response' => false));
  95. $regClient = $this->_prepareRegistrationClient($calls);
  96. $this->assertTrue($regClient->isSsoUserNameAvailable($userName1));
  97. $this->assertFalse($regClient->isSsoUserNameAvailable($userName2));
  98. }
  99. /**
  100. * Method to prepare RegistrationClient with mocked xmlrpc executor
  101. *
  102. * @param array $calls array of calls to xmlrpc executor (each call is array with 'argumetns' and 'response')
  103. * @return RegistrationTestClient
  104. */
  105. private function _prepareRegistrationClient($calls)
  106. {
  107. $oClientExecutor = new PartialMock_PearXmlRpcCustomClientExecutor($this);
  108. $callNo = 0;
  109. foreach ($calls as $call) {
  110. $oClientExecutor->expectArgumentsAt($callNo, 'call', $call['arguments']);
  111. $oClientExecutor->setReturnValueAt($callNo, 'call', $call['response']);
  112. $callNo++;
  113. }
  114. $oClientExecutor->expectCallCount('call', $callNo);
  115. $regClient = new RegistrationTestClient($this->aMarketConfig, $this->platformHash);
  116. $pcApiClient = new OX_PC_API_SimpleClient($oClientExecutor);
  117. $regClient->setPcApiClient($pcApiClient);
  118. return $regClient;
  119. }
  120. }
  121. ?>