|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Theme\Test\Unit\ViewModel\Block\Html\Header; |
| 9 | + |
| 10 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 11 | +use Magento\Store\Model\ScopeInterface; |
| 12 | +use Magento\Theme\ViewModel\Block\Html\Header\LogoSizeResolver; |
| 13 | +use PHPUnit\Framework\MockObject\MockObject; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +/** |
| 17 | + * Test logo size resolver view model |
| 18 | + */ |
| 19 | +class LogoSizeResolverTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var ScopeConfigInterface|MockObject |
| 23 | + */ |
| 24 | + private $scopeConfig; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var LogoSizeResolver |
| 28 | + */ |
| 29 | + private $model; |
| 30 | + |
| 31 | + /** |
| 32 | + * @inheritdoc |
| 33 | + */ |
| 34 | + protected function setUp(): void |
| 35 | + { |
| 36 | + parent::setUp(); |
| 37 | + $this->scopeConfig = $this->createMock(ScopeConfigInterface::class); |
| 38 | + $this->model = new LogoSizeResolver($this->scopeConfig); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @param string|null $configValue |
| 43 | + * @param int|null $expectedValue |
| 44 | + * @dataProvider configValueDataProvider |
| 45 | + */ |
| 46 | + public function testGetWidth(?string $configValue, ?int $expectedValue): void |
| 47 | + { |
| 48 | + $storeId = 1; |
| 49 | + $this->scopeConfig->method('getValue') |
| 50 | + ->with('design/header/logo_width', ScopeInterface::SCOPE_STORE, $storeId) |
| 51 | + ->willReturn($configValue); |
| 52 | + $this->assertEquals($expectedValue, $this->model->getWidth($storeId)); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @param string|null $configValue |
| 57 | + * @param int|null $expectedValue |
| 58 | + * @dataProvider configValueDataProvider |
| 59 | + */ |
| 60 | + public function testGetHeight(?string $configValue, ?int $expectedValue): void |
| 61 | + { |
| 62 | + $storeId = 1; |
| 63 | + $this->scopeConfig->method('getValue') |
| 64 | + ->with('design/header/logo_height', ScopeInterface::SCOPE_STORE, $storeId) |
| 65 | + ->willReturn($configValue); |
| 66 | + $this->assertEquals($expectedValue, $this->model->getHeight($storeId)); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @return array |
| 71 | + */ |
| 72 | + public function configValueDataProvider(): array |
| 73 | + { |
| 74 | + return [ |
| 75 | + [null, null], |
| 76 | + ['', null], |
| 77 | + ['0', 0], |
| 78 | + ['180', 180], |
| 79 | + ]; |
| 80 | + } |
| 81 | +} |
0 commit comments