|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Omikron\Factfinder\Test\Unit\ViewModel; |
| 6 | + |
| 7 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 8 | +use Magento\Framework\Serialize\Serializer\Json; |
| 9 | +use Omikron\Factfinder\ViewModel\ProductsPerPage; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +class ProductPerPageTest extends TestCase |
| 13 | +{ |
| 14 | + /** @var ProductsPerPage */ |
| 15 | + private $productsPerPage; |
| 16 | + |
| 17 | + private $scopeConfigMock; |
| 18 | + |
| 19 | + public function test_will_unserialize_stored_values() |
| 20 | + { |
| 21 | + $this->scopeConfigMock->method('getValue')->with('factfinder/components_options/products_per_page') |
| 22 | + ->willReturn('{"_1648807417584_584":{"value":"8"},"_1648807420544_544":{"value":"12"},"_1648807422801_801":{"value":"16"}}'); |
| 23 | + |
| 24 | + $this->assertIsString($this->productsPerPage->getProductsPerPageConfiguration()); |
| 25 | + } |
| 26 | + |
| 27 | + public function test_output_have_correct_structure() |
| 28 | + { |
| 29 | + $this->scopeConfigMock->method('getValue')->with('factfinder/components_options/products_per_page') |
| 30 | + ->willReturn('{"_1648807417584_584":{"value":"8"},"_1648807420544_544":{"value":"12"},"_1648807422801_801":{"value":"16"}}'); |
| 31 | + |
| 32 | + $actual = $this->productsPerPage->getProductsPerPageConfiguration(); |
| 33 | + |
| 34 | + $this->assertStringContainsString('{"value":"8","selected":false,"default":false}', $actual); |
| 35 | + } |
| 36 | + |
| 37 | + public function test_return_empty_array_literal_if_no_stored_values() |
| 38 | + { |
| 39 | + $this->scopeConfigMock->method('getValue')->with('factfinder/components_options/products_per_page') |
| 40 | + ->willReturn(null); |
| 41 | + |
| 42 | + $this->assertEquals('[]', $this->productsPerPage->getProductsPerPageConfiguration()); |
| 43 | + } |
| 44 | + |
| 45 | + protected function setUp(): void |
| 46 | + { |
| 47 | + $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class); |
| 48 | + $this->productsPerPage = new ProductsPerPage( |
| 49 | + $this->scopeConfigMock, |
| 50 | + new Json(), |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
0 commit comments