Skip to content

Commit

Permalink
[ECP-8944] Committing changes to the PaymentMethods Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
khushboo-singhvi committed Mar 6, 2024
1 parent e4b9f0b commit 5b54573
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions Test/Unit/Helper/PaymentMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Magento\Framework\View\Asset\File;
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\View\Asset\Source;
use Magento\Framework\View\Design\ThemeInterface;
use Magento\Framework\View\DesignInterface;
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
use Magento\Payment\Helper\Data as MagentoDataHelper;
Expand Down Expand Up @@ -1185,4 +1186,91 @@ public function testManualCaptureAllowed(): void
$this->assertFalse($result); // Assuming manual capture is allowed, so it should return false
}

public function testShowLogosPaymentMethods()
{
$themeId = 123; // Assuming a theme ID
$this->adyenHelperMock->expects($this->any())
->method('showLogos')
->willReturn(true); // Mock the method to return true for this test
$paymentMethods = [
['type' => 'visa', 'brand' => 'visa']
];
$paymentMethodsExtraDetails = [
'visa' => []
];
$paymentMethodCode = 'visa';
$params = [
'area' => 'frontend',
'_secure' => '',
'theme' => 'Magento/blank'
];

// Set up the mock for design->getConfigurationDesignTheme
$this->designMock->expects($this->any())
->method('getConfigurationDesignTheme')
->willReturn($themeId);

// Set up the mock for themeProvider->getThemeById
$themeMock = $this->createMock(ThemeInterface::class);

// Set up the getCode method of the theme object
$themeMock->expects($this->any())
->method('getCode')
->willReturn('Magento/blank');

$this->themeProviderMock->expects($this->any())
->method('getThemeById')
->with($themeId)
->willReturn($themeMock);

$expectedSVGUrl = 'mocked_svg_url';
$expectedPNGUrl = 'mocked_png_url';
$svgAssetMock = $this->createMock(File::class);
$svgAssetMock->method('getUrl')->willReturn($expectedSVGUrl);
$pngAssetMock = $this->createMock(File::class);
$pngAssetMock->method('getUrl')->willReturn($expectedPNGUrl);

$this->assetRepoMock->method('createAsset')
->withConsecutive(
["Adyen_Payment::images/logos/{$paymentMethodCode}.svg", $params],
["Adyen_Payment::images/logos/{$paymentMethodCode}.png", $params]
)
->willReturnOnConsecutiveCalls($svgAssetMock, $pngAssetMock);

// Set up asset source mock for SVG asset
$this->assetSourceMock->method('findSource')
->with($svgAssetMock)
->willReturn(true);

// Set up asset source mock for PNG asset
$this->assetSourceMock->method('findSource')
->with($pngAssetMock)
->willReturn(false);

$paymentMethodsHelper = $this->objectManager->getObject(
PaymentMethods::class,
[
'adyenHelper' => $this->adyenHelperMock,
'design' => $this->designMock,
'themeProvider' => $this->themeProviderMock,
'assetRepo' => $this->assetRepoMock,
'assetSource' => $this->assetSourceMock
]
);

$method = $this->getPrivateMethod(
PaymentMethods::class,
'showLogosPaymentMethods'
);

// Call the protected method
$result = $method->invokeArgs($paymentMethodsHelper, [$paymentMethods, $paymentMethodsExtraDetails]);

// Assert that the returned array has the expected structure
$this->assertIsArray($result);
$this->assertArrayHasKey('visa', $result);
$this->assertArrayHasKey('icon', $result['visa']);
$this->assertArrayHasKey('isOpenInvoice', $result['visa']);
}

}

0 comments on commit 5b54573

Please sign in to comment.