Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomOptionTest.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Catalog\Api\Data\CustomOptionExtensionInterface;
12 
13 class CustomOptionTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
21  private $extensionAttributesFactoryMock;
22 
24  private $extensionMock;
25 
29  protected $fileProcessor;
30 
31  protected function setUp()
32  {
33  $context = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36 
37  $registry = $this->getMockBuilder(\Magento\Framework\Registry::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40 
41  $this->extensionAttributesFactoryMock = $this->getMockBuilder(ExtensionAttributesFactory::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44 
45  $attributeValueFactory = $this->getMockBuilder(\Magento\Framework\Api\AttributeValueFactory::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $this->fileProcessor = $this->getMockBuilder(
50  \Magento\Catalog\Model\Webapi\Product\Option\Type\File\Processor::class
51  )
52  ->disableOriginalConstructor()
53  ->getMock();
54 
55  $resource = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\AbstractResource::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58 
59  $collection = $this->getMockBuilder(\Magento\Framework\Data\Collection\AbstractDb::class)
60  ->disableOriginalConstructor()
61  ->getMock();
62 
63  $this->extensionMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\CustomOptionExtensionInterface::class)
64  ->setMethods(['getFileInfo'])
65  ->getMockForAbstractClass();
66 
67  $this->extensionAttributesFactoryMock->expects(self::any())
68  ->method('create')->willReturn($this->extensionMock);
69 
70  $this->model = new CustomOption(
71  $context,
72  $registry,
73  $this->extensionAttributesFactoryMock,
74  $attributeValueFactory,
75  $this->fileProcessor,
76  $resource,
78  );
79  }
80 
81  public function testGetSetOptionId()
82  {
83  $this->assertNull($this->model->getOptionId());
84 
85  $this->model->setOptionId(1);
86  $this->assertEquals(1, $this->model->getOptionId());
87  }
88 
89  public function testGetOptionValue()
90  {
91  $this->assertNull($this->model->getOptionValue());
92 
93  $this->model->setData(\Magento\Catalog\Api\Data\CustomOptionInterface::OPTION_VALUE, 'test');
94  $this->assertEquals('test', $this->model->getOptionValue());
95 
96  $this->model->setData(\Magento\Catalog\Api\Data\CustomOptionInterface::OPTION_VALUE, 'file');
97  $this->assertEquals('file', $this->model->getOptionValue());
98  }
99 
101  {
102  $imageContent = $this->getMockBuilder(\Magento\Framework\Api\Data\ImageContentInterface::class)
103  ->getMockForAbstractClass();
104 
105  $this->extensionMock->expects($this->once())
106  ->method('getFileInfo')
107  ->willReturn($imageContent);
108 
109  $imageResult = [
110  'type' => 'type',
111  'title' => 'title',
112  'fullpath' => 'fullpath',
113  'quote_path' => 'quote_path',
114  'order_path' => 'order_path',
115  'size' => 100,
116  'width' => 100,
117  'height' => 100,
118  'secret_key' => 'secret_key',
119  ];
120 
121  $this->fileProcessor->expects($this->once())
122  ->method('processFileContent')
123  ->with($imageContent)
124  ->willReturn($imageResult);
125 
126  $this->model->setData(\Magento\Catalog\Api\Data\CustomOptionInterface::OPTION_VALUE, 'file');
127  $this->assertEquals($imageResult, $this->model->getOptionValue());
128  }
129 
130  public function testSetOptionValue()
131  {
132  $this->model->setOptionValue('test');
133  $this->assertEquals('test', $this->model->getOptionValue());
134  }
135 }
$resource
Definition: bulk.php:12