Skip to content

Commit

Permalink
fix: update previous test
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Freoua-Alma committed Oct 29, 2024
1 parent 6399e6f commit 2c8eb85
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 22 deletions.
13 changes: 6 additions & 7 deletions alma/controllers/front/cmsdataexport.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function __construct()
$this->settingsHelper = $settingsHelperBuilder->getInstance();
}

/**
* @throws \PrestaShopException
*/
public function postProcess()
{
parent::postProcess();
Expand Down Expand Up @@ -86,7 +89,7 @@ public function postProcess()
'specific_features' => [], // no specific features in Prestashop
'country_restriction' => $this->getCountriesRestrictions(),
'custom_widget_css' => $this->configHelper->get(ProductEligibilityAdminFormBuilder::ALMA_WIDGET_POSITION_SELECTOR),
'is_multisite' => Shop::isFeatureActive(),
'is_multisite' => \Shop::isFeatureActive(),
];
$cmsInfo = new CmsInfo($cmsInfoDataArray);
$cmsFeature = new CmsFeatures($cmsFeatureDataArray);
Expand All @@ -96,11 +99,12 @@ public function postProcess()

private function getCountriesRestrictions()
{
// TODO : Need to implement this method with the db ps_module_country
return [];
}

/**
* @return mixed|string
* @return string
*/
private function getPhpClientVersion()
{
Expand All @@ -119,9 +123,4 @@ private function getPhpClientVersion()

return '';
}

public function getTestData()
{
return $this->configHelper->get('TEST_DATA');
}
}
10 changes: 8 additions & 2 deletions alma/lib/Traits/BuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ public function getSettingsHelper($settingsHelper = null)

return new SettingsHelper(
$this->getShopHelper(),
$this->getConfigurationHelper()
$this->getConfigurationHelper(),
$this->getCategoryFactory(),
$this->getContextFactory(),
$this->getValidateHelper()
);
}

Expand Down Expand Up @@ -967,7 +970,10 @@ public function getFeePlanHelper($feePlanHelper = null)
return new FeePlanHelper(
new SettingsHelper(
new ShopHelper(),
new ConfigurationHelper()
new ConfigurationHelper(),
new CategoryFactory(),
new ContextFactory(),
new ValidateHelper()
),
new EligibilityFactory()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Alma\PrestaShop\Tests\Unit\Builders\Helpers;

use Alma\PrestaShop\Builders\Helpers\EligibilityHelperBuilder;
use Alma\PrestaShop\Factories\CategoryFactory;
use Alma\PrestaShop\Factories\ContextFactory;
use Alma\PrestaShop\Helpers\ApiHelper;
use Alma\PrestaShop\Helpers\CarrierHelper;
Expand All @@ -38,6 +39,7 @@
use Alma\PrestaShop\Helpers\SettingsHelper;
use Alma\PrestaShop\Helpers\ShopHelper;
use Alma\PrestaShop\Helpers\ToolsHelper;
use Alma\PrestaShop\Helpers\ValidateHelper;
use Alma\PrestaShop\Model\CarrierData;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -88,7 +90,10 @@ public function setUp()

$this->settingsHelper = new SettingsHelper(
new ShopHelper(),
new ConfigurationHelper()
new ConfigurationHelper(),
new CategoryFactory(),
new ContextFactory(),
new ValidateHelper()
);
$this->priceHelper = \Mockery::mock(PriceHelper::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Alma\PrestaShop\Tests\Unit\Builders\Helpers;

use Alma\PrestaShop\Builders\Helpers\PaymentOptionHelperBuilder;
use Alma\PrestaShop\Factories\CategoryFactory;
use Alma\PrestaShop\Factories\ContextFactory;
use Alma\PrestaShop\Factories\MediaFactory;
use Alma\PrestaShop\Helpers\ConfigurationHelper;
Expand All @@ -34,6 +35,7 @@
use Alma\PrestaShop\Helpers\PaymentOptionTemplateHelper;
use Alma\PrestaShop\Helpers\SettingsHelper;
use Alma\PrestaShop\Helpers\ShopHelper;
use Alma\PrestaShop\Helpers\ValidateHelper;
use PHPUnit\Framework\TestCase;

class PaymentOptionHelperBuilderTest extends TestCase
Expand All @@ -53,7 +55,10 @@ public function setUp()
$this->paymentOptionHelperBuilder = new PaymentOptionHelperBuilder();
$this->settingsHelper = new SettingsHelper(
new ShopHelper(),
new ConfigurationHelper()
new ConfigurationHelper(),
new CategoryFactory(),
new ContextFactory(),
new ValidateHelper()
);
}

Expand Down
7 changes: 6 additions & 1 deletion alma/tests/Unit/Builders/Models/PaymentDataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Alma\PrestaShop\Tests\Unit\Builders\Models;

use Alma\PrestaShop\Builders\Models\PaymentDataBuilder;
use Alma\PrestaShop\Factories\CategoryFactory;
use Alma\PrestaShop\Factories\ContextFactory;
use Alma\PrestaShop\Helpers\AddressHelper;
use Alma\PrestaShop\Helpers\CarrierHelper;
Expand All @@ -40,6 +41,7 @@
use Alma\PrestaShop\Helpers\ShopHelper;
use Alma\PrestaShop\Helpers\StateHelper;
use Alma\PrestaShop\Helpers\ToolsHelper;
use Alma\PrestaShop\Helpers\ValidateHelper;
use Alma\PrestaShop\Model\CarrierData;
use Alma\PrestaShop\Model\CartData;
use Alma\PrestaShop\Model\PaymentData;
Expand Down Expand Up @@ -92,7 +94,10 @@ public function setUp()

$this->settingsHelper = new SettingsHelper(
new ShopHelper(),
new ConfigurationHelper()
new ConfigurationHelper(),
new CategoryFactory(),
new ContextFactory(),
new ValidateHelper()
);

$this->priceHelper = \Mockery::mock(PriceHelper::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Alma\PrestaShop\Builders\Factories\ModuleFactoryBuilder;
use Alma\PrestaShop\Builders\Services\PaymentServiceBuilder;
use Alma\PrestaShop\Factories\AddressFactory;
use Alma\PrestaShop\Factories\CategoryFactory;
use Alma\PrestaShop\Factories\ContextFactory;
use Alma\PrestaShop\Factories\ModuleFactory;
use Alma\PrestaShop\Helpers\CarrierHelper;
Expand All @@ -49,6 +50,7 @@
use Alma\PrestaShop\Helpers\ShopHelper;
use Alma\PrestaShop\Helpers\ToolsHelper;
use Alma\PrestaShop\Helpers\TranslationHelper;
use Alma\PrestaShop\Helpers\ValidateHelper;
use Alma\PrestaShop\Model\CarrierData;
use Alma\PrestaShop\Model\CartData;
use Alma\PrestaShop\Repositories\ProductRepository;
Expand Down Expand Up @@ -139,7 +141,10 @@ public function setUp()

$this->settingsHelper = new SettingsHelper(
new ShopHelper(),
$this->configurationHelper
$this->configurationHelper,
new CategoryFactory(),
new ContextFactory(),
new ValidateHelper()
);

$this->cartData = new CartData(
Expand Down
48 changes: 48 additions & 0 deletions alma/tests/Unit/Helper/ModuleHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* 2018-2024 Alma SAS.
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma SAS <[email protected]>
* @copyright 2018-2024 Alma SAS
* @license https://opensource.org/licenses/MIT The MIT License
*/

namespace Alma\PrestaShop\Tests\Unit\Helper;

use Alma\PrestaShop\Factories\ModuleFactory;
use Alma\PrestaShop\Helpers\ModuleHelper;
use PHPUnit\Framework\TestCase;

class ModuleHelperTest extends TestCase
{
/**
* @var ModuleHelper
*/
protected $moduleHelper;

public function setUp()
{
$this->moduleFactoryMock = $this->createMock(ModuleFactory::class);
$this->moduleHelper = new ModuleHelper();
}

public function testGetModuleListWithListOfModules()
{
$this->assertEquals([], $this->moduleHelper->getModuleList());
}
}
53 changes: 45 additions & 8 deletions alma/tests/Unit/Helper/SettingsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@

use Alma\API\Entities\FeePlan;
use Alma\PrestaShop\Builders\Helpers\SettingsHelperBuilder;
use Alma\PrestaShop\Factories\CategoryFactory;
use Alma\PrestaShop\Factories\ContextFactory;
use Alma\PrestaShop\Forms\InpageAdminFormBuilder;
use Alma\PrestaShop\Helpers\ConfigurationHelper;
use Alma\PrestaShop\Helpers\SettingsHelper;
use Alma\PrestaShop\Helpers\ShopHelper;
use Alma\PrestaShop\Helpers\ValidateHelper;
use PHPUnit\Framework\TestCase;

class SettingsHelperTest extends TestCase
Expand All @@ -41,27 +44,51 @@ class SettingsHelperTest extends TestCase
/**
* @var ShopHelper
*/
protected $shopHelper;
protected $shopHelperMock;
/**
* @var ConfigurationHelper
*/
protected $configurationHelper;
protected $configurationHelperMock;
/**
* @var (SettingsHelper&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit_Framework_MockObject_MockObject
*/
protected $settingsHelperMock;
/**
* @var \Alma\PrestaShop\Factories\CategoryFactory|(\Alma\PrestaShop\Factories\CategoryFactory&\PHPUnit_Framework_MockObject_MockObject)|\PHPUnit_Framework_MockObject_MockObject
*/
protected $categoryFactoryMock;
/**
* @var \Alma\PrestaShop\Factories\ContextFactory|(\Alma\PrestaShop\Factories\ContextFactory&\PHPUnit_Framework_MockObject_MockObject)|\PHPUnit_Framework_MockObject_MockObject
*/
protected $contextFactoryMock;
/**
* @var \Alma\PrestaShop\Helpers\ValidateHelper|(\Alma\PrestaShop\Helpers\ValidateHelper&\PHPUnit_Framework_MockObject_MockObject)|\PHPUnit_Framework_MockObject_MockObject
*/
protected $validateHelperMock;

public function setUp()
{
$this->shopHelper = $this->createMock(ShopHelper::class);
$this->configurationHelper = $this->createMock(ConfigurationHelper::class);
$this->shopHelperMock = $this->createMock(ShopHelper::class);
$this->configurationHelperMock = $this->createMock(ConfigurationHelper::class);
$this->categoryFactoryMock = $this->createMock(CategoryFactory::class);
$this->contextFactoryMock = $this->createMock(ContextFactory::class);
$this->validateHelperMock = $this->createMock(ValidateHelper::class);
$this->settingsHelper = new SettingsHelper(
$this->shopHelper,
$this->configurationHelper
$this->shopHelperMock,
$this->configurationHelperMock,
$this->categoryFactoryMock,
$this->contextFactoryMock,
$this->validateHelperMock
);

$this->settingsHelperMock = $this->getMockBuilder(SettingsHelper::class)
->setConstructorArgs([$this->shopHelper, $this->configurationHelper])
->setConstructorArgs([
$this->shopHelperMock,
$this->configurationHelperMock,
$this->categoryFactoryMock,
$this->contextFactoryMock,
$this->validateHelperMock,
])
->setMethods(['isInPageEnabled', 'getKey'])
->getMock();
}
Expand Down Expand Up @@ -372,7 +399,17 @@ protected function getSettingsHelperMockForIsPaymentTriggerEnabledByState($keyNa
$configurationHelperMock->shouldReceive('get')->with($keyName, null, 1, 1, '')->andReturn($keyValue);
$configurationHelperMock->shouldReceive('hasKey')->with($keyName, null, 1, 1)->andReturn(false);

return \Mockery::mock(SettingsHelper::class, [$shopHelperMock, $configurationHelperMock])->shouldAllowMockingProtectedMethods()->makePartial();
$categoryFactoryMock = \Mockery::mock(CategoryFactory::class);
$contextFactoryMock = \Mockery::mock(ContextFactory::class);
$validateHelperMock = \Mockery::mock(ValidateHelper::class);

return \Mockery::mock(SettingsHelper::class, [
$shopHelperMock,
$configurationHelperMock,
$categoryFactoryMock,
$contextFactoryMock,
$validateHelperMock,
])->shouldAllowMockingProtectedMethods()->makePartial();
}

public function testKey()
Expand Down
11 changes: 10 additions & 1 deletion alma/tests/Unit/Model/CartDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
namespace Alma\PrestaShop\Tests\Unit\Model;

use Alma\PrestaShop\Builders\Models\CartDataBuilder;
use Alma\PrestaShop\Factories\CategoryFactory;
use Alma\PrestaShop\Factories\ContextFactory;
use Alma\PrestaShop\Factories\CurrencyFactory;
use Alma\PrestaShop\Helpers\ConfigurationHelper;
use Alma\PrestaShop\Helpers\CurrencyHelper;
Expand All @@ -33,6 +35,7 @@
use Alma\PrestaShop\Helpers\SettingsHelper;
use Alma\PrestaShop\Helpers\ShopHelper;
use Alma\PrestaShop\Helpers\ToolsHelper;
use Alma\PrestaShop\Helpers\ValidateHelper;
use Alma\PrestaShop\Repositories\ProductRepository;
use Cart;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -235,7 +238,13 @@ public function testGetCartExclusion()
$cart = \Mockery::mock(\Cart::class);
$cart->allows()->getProducts(true)->andReturns([['id_product' => 1]]);

$settingsHelperMock = \Mockery::mock(SettingsHelper::class, [new ShopHelper(), new ConfigurationHelper()]);
$settingsHelperMock = \Mockery::mock(SettingsHelper::class, [
new ShopHelper(),
new ConfigurationHelper(),
new CategoryFactory(),
new ContextFactory(),
new ValidateHelper(),
]);
$settingsHelperMock->shouldReceive('getExcludedCategories')->andReturn(['cateexclue']);

$productHelperMock = \Mockery::mock(ProductHelper::class);
Expand Down

0 comments on commit 2c8eb85

Please sign in to comment.