|
10 | 10 | use Magento\Catalog\Block\Product\Compare\ListCompare;
|
11 | 11 | use Magento\Catalog\Block\Product\Context;
|
12 | 12 | use Magento\Catalog\Model\Product;
|
| 13 | +use Magento\Eav\Model\Entity\Attribute\AttributeInterface; |
| 14 | +use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend; |
13 | 15 | use Magento\Framework\Pricing\Render;
|
14 | 16 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
15 | 17 | use Magento\Framework\View\Layout;
|
@@ -50,6 +52,48 @@ protected function tearDown(): void
|
50 | 52 | $this->block = null;
|
51 | 53 | }
|
52 | 54 |
|
| 55 | + /** |
| 56 | + * @dataProvider attributeDataProvider |
| 57 | + * @param array $attributeData |
| 58 | + * @param string $expectedResult |
| 59 | + */ |
| 60 | + public function testProductAttributeValue($attributeData, $expectedResult) |
| 61 | + { |
| 62 | + $attribute = $this->getMockBuilder(AttributeInterface::class) |
| 63 | + ->addMethods(['getAttributeCode', 'getSourceModel', 'getFrontendInput', 'getFrontend']) |
| 64 | + ->getMockForAbstractClass(); |
| 65 | + $frontEndModel = $this->createPartialMock(AbstractFrontend::class, ['getValue']); |
| 66 | + $productMock = $this->createPartialMock(Product::class, ['getId', 'getData', 'hasData']); |
| 67 | + $productMock->expects($this->any()) |
| 68 | + ->method('hasData') |
| 69 | + ->with($attributeData['attribute_code']) |
| 70 | + ->willReturn(true); |
| 71 | + $productMock->expects($this->any()) |
| 72 | + ->method('getData') |
| 73 | + ->with($attributeData['attribute_code']) |
| 74 | + ->willReturn($attributeData['attribute_value']); |
| 75 | + $attribute->expects($this->any()) |
| 76 | + ->method('getAttributeCode') |
| 77 | + ->willReturn($attributeData['attribute_code']); |
| 78 | + $attribute->expects($this->any()) |
| 79 | + ->method('getSourceModel') |
| 80 | + ->willReturn($attributeData['source_model']); |
| 81 | + $attribute->expects($this->any()) |
| 82 | + ->method('getFrontendInput') |
| 83 | + ->willReturn($attributeData['frontend_input']); |
| 84 | + $frontEndModel->expects($this->any()) |
| 85 | + ->method('getValue') |
| 86 | + ->with($productMock) |
| 87 | + ->willReturn($attributeData['attribute_value']); |
| 88 | + $attribute->expects($this->any()) |
| 89 | + ->method('getFrontend') |
| 90 | + ->willReturn($frontEndModel); |
| 91 | + $this->assertEquals( |
| 92 | + $expectedResult, |
| 93 | + $this->block->getProductAttributeValue($productMock, $attribute) |
| 94 | + ); |
| 95 | + } |
| 96 | + |
53 | 97 | public function testGetProductPrice()
|
54 | 98 | {
|
55 | 99 | //Data
|
@@ -84,4 +128,31 @@ public function testGetProductPrice()
|
84 | 128 |
|
85 | 129 | $this->assertEquals($expectedResult, $this->block->getProductPrice($product, '-compare-list-top'));
|
86 | 130 | }
|
| 131 | + |
| 132 | + /** |
| 133 | + * @return array |
| 134 | + */ |
| 135 | + public function attributeDataProvider(): array |
| 136 | + { |
| 137 | + return [ |
| 138 | + [ |
| 139 | + 'attributeData' => [ |
| 140 | + 'attribute_code' => 'tier_price', |
| 141 | + 'source_model' => null, |
| 142 | + 'frontend_input' => 'text', |
| 143 | + 'attribute_value' => [] |
| 144 | + ], |
| 145 | + 'expectedResult' => __('N/A') |
| 146 | + ], |
| 147 | + [ |
| 148 | + 'attributeData' => [ |
| 149 | + 'attribute_code' => 'special_price', |
| 150 | + 'source_model' => null, |
| 151 | + 'frontend_input' => 'decimal', |
| 152 | + 'attribute_value' => 50.00 |
| 153 | + ], |
| 154 | + 'expectedResult' => '50.00' |
| 155 | + ] |
| 156 | + ]; |
| 157 | + } |
87 | 158 | }
|
0 commit comments