/lib/OX/Dal/Market/tests/unit/MarketPluginTools.dal.test.php

https://github.com/orchestra-io/sample-openx · PHP · 172 lines · 83 code · 36 blank · 53 comment · 0 complexity · d0bfff19d422058122e3e445c08168cb MD5 · raw file

  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  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: MarketPluginTools.dal.test.php 43253 2009-09-16 09:37:45Z lukasz.wikierski $
  25. */
  26. require_once MAX_PATH . '/lib/OX/Dal/Market/MarketPluginTools.php';
  27. require_once MAX_PATH . '/lib/OA/Dal/DataGenerator.php';
  28. /**
  29. * A class for testing the Market Plugin Tools
  30. *
  31. * @package OpenX
  32. * @subpackage TestSuite
  33. * @author Lukasz Wikierski <lukasz.wikierski@openx.org>
  34. */
  35. class OX_Dal_Market_MarketPluginToolsTest extends UnitTestCase
  36. {
  37. function tearDown()
  38. {
  39. DataGenerator::cleanUp();
  40. }
  41. function testGetMarketPlugin()
  42. {
  43. // make sure that plugin is uninstalled
  44. TestEnv::uninstallPluginPackage('openXMarket', false);
  45. // market plugin is not installed
  46. $this->assertFalse(OX_Dal_Market_MarketPluginTools::getMarketPlugin());
  47. // install market plugin
  48. TestEnv::uninstallPluginPackage('openXMarket', false);
  49. TestEnv::installPluginPackage('openXMarket', false);
  50. $result = OX_Dal_Market_MarketPluginTools::getMarketPlugin();
  51. $this->assertIsA($result, 'Plugins_admin_oxMarket_oxMarket');
  52. //disable plugin
  53. $oPkgMgr = new OX_PluginManager();
  54. $oPkgMgr->disablePackage('openXMarket');
  55. // should ignore disable status
  56. $result = OX_Dal_Market_MarketPluginTools::getMarketPlugin();
  57. $this->assertIsA($result, 'Plugins_admin_oxMarket_oxMarket');
  58. // unistall market plugin
  59. TestEnv::uninstallPluginPackage('openXMarket', false);
  60. $GLOBALS['_MAX']['CONF']['plugins']['openXMarket'] = null;
  61. }
  62. function testIsRegistrationRequired()
  63. {
  64. // market plugin is not installed
  65. $this->assertTrue(OX_Dal_Market_MarketPluginTools::isRegistrationRequired());
  66. // install market plugin
  67. TestEnv::uninstallPluginPackage('openXMarket', false);
  68. TestEnv::installPluginPackage('openXMarket', false);
  69. // still registration required, no associated accounts
  70. $this->assertTrue(OX_Dal_Market_MarketPluginTools::isRegistrationRequired());
  71. // Create admin account
  72. $doAccounts = OA_Dal::factoryDO('accounts');
  73. $doAccounts->account_type = OA_ACCOUNT_ADMIN;
  74. $adminAccountId = DataGenerator::generateOne($doAccounts);
  75. // Add association for admin account
  76. $oAccountAssocData = OA_Dal::factoryDO('ext_market_assoc_data');
  77. $doExtMarket = OA_DAL::factoryDO('ext_market_assoc_data');
  78. $doExtMarket->account_id = $adminAccountId;
  79. $doExtMarket->publisher_account_id = 'publisher_account_id';
  80. $doExtMarket->api_key = 'api_key';
  81. $doExtMarket->status =
  82. Plugins_admin_oxMarket_PublisherConsoleMarketPluginClient::LINK_IS_VALID_STATUS;
  83. $doExtMarket->insert();
  84. // registration not required
  85. $this->assertFalse(OX_Dal_Market_MarketPluginTools::isRegistrationRequired());
  86. //disable plugin
  87. $oPkgMgr = new OX_PluginManager();
  88. $oPkgMgr->disablePackage('openXMarket');
  89. // should ignore disable status
  90. $this->assertFalse(OX_Dal_Market_MarketPluginTools::isRegistrationRequired());
  91. // unistall market plugin
  92. TestEnv::uninstallPluginPackage('openXMarket', false);
  93. $GLOBALS['_MAX']['CONF']['plugins']['openXMarket'] = null;
  94. $this->assertTrue(OX_Dal_Market_MarketPluginTools::isRegistrationRequired());
  95. // Add association data to application variables (shouldn't require registration)
  96. OX_Dal_Market_MarketPluginTools::storeMarketAccountAssocData('publisher_account_id', 'api_key');
  97. $this->assertFalse(OX_Dal_Market_MarketPluginTools::isRegistrationRequired());
  98. // cleanup
  99. OA_Dal_ApplicationVariables::delete('oxMarket_publisher_account_id');
  100. OA_Dal_ApplicationVariables::delete('oxMarket_api_key');
  101. OA_Dal_ApplicationVariables::_getAll(false); //refresh cache
  102. }
  103. function testStoreMarketAccountAssocData()
  104. {
  105. $publisherAccountId = 'test_publ_isher_accountid';
  106. $apiKey = 'apikey';
  107. $result = OX_Dal_Market_MarketPluginTools::storeMarketAccountAssocData($publisherAccountId, $apiKey);
  108. $this->assertTrue($result);
  109. $result = OA_Dal_ApplicationVariables::_getAll();
  110. $result['oxMarket_publisher_account_id'] = $apiKey;
  111. $result['oxMarket_api_key'] = $publisherAccountId;
  112. // cleanup
  113. OA_Dal_ApplicationVariables::delete('oxMarket_publisher_account_id');
  114. OA_Dal_ApplicationVariables::delete('oxMarket_api_key');
  115. }
  116. function testGetMarketAccountAssocData()
  117. {
  118. $publisherAccountId = 'test2_publ_isher_accountid';
  119. $apiKey = 'apikey2';
  120. // Test only one data avaliable
  121. OA_Dal_ApplicationVariables::set('oxMarket_publisher_account_id', $publisherAccountId);
  122. $result = OX_Dal_Market_MarketPluginTools::getMarketAccountAssocData();
  123. $this->assertNull($result);
  124. // both data
  125. OA_Dal_ApplicationVariables::set('oxMarket_api_key', $apiKey);
  126. $result = OX_Dal_Market_MarketPluginTools::getMarketAccountAssocData();
  127. $this->assertEqual($result, array('apiKey' => $apiKey, 'accountUuid' => $publisherAccountId));
  128. // delete acountuuid
  129. OA_Dal_ApplicationVariables::delete('oxMarket_publisher_account_id');
  130. $result = OX_Dal_Market_MarketPluginTools::getMarketAccountAssocData();
  131. $this->assertNull($result);
  132. // cleanup
  133. OA_Dal_ApplicationVariables::delete('oxMarket_api_key');
  134. }
  135. }
  136. ?>