|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2025 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\ProductAlert\Test\Unit\Model; |
| 9 | + |
| 10 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 11 | +use Magento\Framework\View\DesignInterface; |
| 12 | +use Magento\ProductAlert\Block\Email\Stock; |
| 13 | +use Magento\Framework\View\Element\Template\File\Resolver; |
| 14 | +use Magento\ProductAlert\Model\UpdateThemeParams; |
| 15 | +use Magento\Store\Model\Store; |
| 16 | +use Magento\Store\Model\StoreManagerInterface; |
| 17 | +use PHPUnit\Framework\MockObject\Exception; |
| 18 | +use PHPUnit\Framework\MockObject\MockObject; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +/** |
| 22 | + * Class UpdateThemeParamsTest to check valid |
| 23 | + * template file returns for multi store setup |
| 24 | + */ |
| 25 | +class UpdateThemeParamsTest extends TestCase |
| 26 | +{ |
| 27 | + /** |
| 28 | + * @var UpdateThemeParams |
| 29 | + */ |
| 30 | + private $model; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var DesignInterface|MockObject |
| 34 | + */ |
| 35 | + private $designMock; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var StoreManagerInterface|MockObject |
| 39 | + */ |
| 40 | + private $storeManagerMock; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var Stock|MockObject |
| 44 | + */ |
| 45 | + private $stockMock; |
| 46 | + |
| 47 | + /** |
| 48 | + * @inheritdoc |
| 49 | + */ |
| 50 | + protected function setUp(): void |
| 51 | + { |
| 52 | + $this->designMock = $this->createMock(DesignInterface::class); |
| 53 | + $this->storeManagerMock = $this->createMock(StoreManagerInterface::class); |
| 54 | + $this->stockMock = $this->createMock(Stock::class); |
| 55 | + |
| 56 | + $this->model = new UpdateThemeParams( |
| 57 | + $this->designMock, |
| 58 | + $this->storeManagerMock, |
| 59 | + $this->stockMock |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Test cases to check template file returns for multi store setup |
| 65 | + * |
| 66 | + * @param string $templateFileName |
| 67 | + * @param string $stockTemplateFileName |
| 68 | + * @param int $storeId |
| 69 | + * @param array $params |
| 70 | + * @return void |
| 71 | + * @throws Exception |
| 72 | + * @throws NoSuchEntityException |
| 73 | + * @dataProvider getTemplateFileDataProvider |
| 74 | + */ |
| 75 | + public function testBeforeGetTemplateFileName( |
| 76 | + string $templateFileName, |
| 77 | + string $stockTemplateFileName, |
| 78 | + int $storeId, |
| 79 | + array $params |
| 80 | + ): void { |
| 81 | + $resolverMock = $this->createMock(Resolver::class); |
| 82 | + $storeMock = $this->createMock(Store::class); |
| 83 | + $this->stockMock->method('getTemplate')->willReturn($stockTemplateFileName); |
| 84 | + $this->storeManagerMock->method('getStore')->willReturn($storeMock); |
| 85 | + $storeMock->method('getId')->willReturn($storeId); |
| 86 | + $this->designMock |
| 87 | + ->method('getConfigurationDesignTheme') |
| 88 | + ->willReturn($params['themeId']); |
| 89 | + |
| 90 | + $expectedArr = $this->model->beforeGetTemplateFileName($resolverMock, $templateFileName, $params); |
| 91 | + $this->assertEquals([$templateFileName, $params], $expectedArr); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Data provider for testBeforeGetTemplateFileName |
| 96 | + * |
| 97 | + * @return array |
| 98 | + */ |
| 99 | + public static function getTemplateFileDataProvider(): array |
| 100 | + { |
| 101 | + return [ |
| 102 | + 'test cases with valid template file name' => [ |
| 103 | + 'Magento_ProductAlert::email/stock.phtml', |
| 104 | + 'Magento_ProductAlert::email/stock.phtml', |
| 105 | + 1, |
| 106 | + ['themeId' => 1] |
| 107 | + ], |
| 108 | + 'test cases with invalid template file name' => [ |
| 109 | + 'test.phtml', |
| 110 | + 'Magento_ProductAlert::email/stock.phtml', |
| 111 | + 1, |
| 112 | + ['themeId' => 1] |
| 113 | + ] |
| 114 | + ]; |
| 115 | + } |
| 116 | +} |
0 commit comments