9 use Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory;
32 private $serializerMock;
37 private $storeManagerMock;
52 private $attributeMock;
66 $this->cacheTags = [
'tag1',
'tag2'];
68 $this->booleanFactory = $this->getMockBuilder(BooleanFactory::class)
69 ->disableOriginalConstructor()
71 $this->serializerMock = $this->getMockBuilder(Serializer::class)
73 $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
74 ->getMockForAbstractClass();
75 $this->storeMock = $this->getMockBuilder(StoreInterface::class)
76 ->getMockForAbstractClass();
77 $this->cacheMock = $this->getMockBuilder(CacheInterface::class)
78 ->getMockForAbstractClass();
79 $this->attributeMock = $this->getMockBuilder(AbstractAttribute::class)
80 ->disableOriginalConstructor()
81 ->setMethods([
'getAttributeCode',
'getSource'])
82 ->getMockForAbstractClass();
83 $this->sourceMock = $this->getMockBuilder(AbstractSource::class)
84 ->disableOriginalConstructor()
85 ->setMethods([
'getAllOptions'])
86 ->getMockForAbstractClass();
88 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
90 DefaultFrontend::class,
92 '_attrBooleanFactory' => $this->booleanFactory,
93 'cache' => $this->cacheMock,
94 'storeManager' => $this->storeManagerMock,
95 'serializer' => $this->serializerMock,
96 '_attribute' => $this->attributeMock,
97 'cacheTags' => $this->cacheTags
104 $attributeMock = $this->getMockBuilder(\
Magento\Eav\Model\Entity\
Attribute\AbstractAttribute::class)
105 ->disableOriginalConstructor()
112 $attributeMock->expects($this->once())
113 ->method(
'getIsRequired')
115 $attributeMock->expects($this->once())
116 ->method(
'getFrontendClass')
118 $attributeMock->expects($this->exactly(2))
119 ->method(
'getValidateRules')
122 $this->model->setAttribute($attributeMock);
123 $this->assertEmpty($this->model->getClass());
128 $attributeMock = $this->getMockBuilder(\
Magento\Eav\Model\Entity\
Attribute\AbstractAttribute::class)
129 ->disableOriginalConstructor()
136 $attributeMock->expects($this->once())
137 ->method(
'getIsRequired')
139 $attributeMock->expects($this->once())
140 ->method(
'getFrontendClass')
142 $attributeMock->expects($this->exactly(3))
143 ->method(
'getValidateRules')
145 'input_validation' =>
'alphanumeric',
146 'min_text_length' => 1,
147 'max_text_length' => 2,
150 $this->model->setAttribute($attributeMock);
151 $result = $this->model->getClass();
153 $this->assertContains(
'validate-alphanum',
$result);
154 $this->assertContains(
'minimum-length-1',
$result);
155 $this->assertContains(
'maximum-length-2',
$result);
156 $this->assertContains(
'validate-length',
$result);
161 $attributeMock = $this->getMockBuilder(\
Magento\Eav\Model\Entity\
Attribute\AbstractAttribute::class)
162 ->disableOriginalConstructor()
169 $attributeMock->expects($this->once())
170 ->method(
'getIsRequired')
172 $attributeMock->expects($this->once())
173 ->method(
'getFrontendClass')
175 $attributeMock->expects($this->exactly(3))
176 ->method(
'getValidateRules')
178 'input_validation' =>
'length',
179 'min_text_length' => 1,
180 'max_text_length' => 2,
183 $this->model->setAttribute($attributeMock);
184 $result = $this->model->getClass();
186 $this->assertContains(
'minimum-length-1',
$result);
187 $this->assertContains(
'maximum-length-2',
$result);
188 $this->assertContains(
'validate-length',
$result);
197 $serializedOptions =
"{['option1', 'option2']}";
199 $this->storeManagerMock->expects($this->once())
201 ->willReturn($this->storeMock);
202 $this->storeMock->expects($this->once())
205 $this->attributeMock->expects($this->once())
206 ->method(
'getAttributeCode')
208 $this->cacheMock->expects($this->once())
212 $this->attributeMock->expects($this->once())
213 ->method(
'getSource')
214 ->willReturn($this->sourceMock);
215 $this->sourceMock->expects($this->once())
216 ->method(
'getAllOptions')
218 $this->serializerMock->expects($this->once())
219 ->method(
'serialize')
221 ->willReturn($serializedOptions);
222 $this->cacheMock->expects($this->once())
224 ->with($serializedOptions, $cacheKey, $this->cacheTags);
226 $this->assertSame(
$options, $this->model->getSelectOptions());