16 private $objectManager;
20 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23 public function testEntityToDatabase()
25 $searchResult = $this->getMockBuilder(\
Magento\Framework\Api\SearchResults::class)
26 ->disableOriginalConstructor()
27 ->setMethods([
'getItems'])
29 $searchResult->expects($this->any())
31 ->will($this->returnValue($this->getAttributes()));
34 ->disableOriginalConstructor()
35 ->setMethods([
'getList'])
39 ->will($this->returnValue($searchResult));
41 $metadata = $this->objectManager->getObject(
42 \
Magento\Framework\EntityManager\EntityMetadata::class,
44 'entityTableName' =>
'test',
45 'identifierField' =>
'entity_id',
46 'eavEntityType' =>
'customer_address' 50 $metadataPool = $this->getMockBuilder(\
Magento\Framework\EntityManager\MetadataPool::class)
51 ->disableOriginalConstructor()
52 ->setMethods([
'getMetadata',
'hasConfiguration'])
54 $metadataPool->expects($this->any())
55 ->method(
'hasConfiguration')
57 $metadataPool->expects($this->any())
58 ->method(
'getMetadata')
59 ->with($this->equalTo(\
Magento\Framework\Api\CustomAttributesDataInterface::class))
60 ->will($this->returnValue($metadata));
61 $metadataPool->expects($this->once())
62 ->method(
'hasConfiguration')
66 ->disableOriginalConstructor()
67 ->setMethods([
'addFilter',
'create'])
70 ->disableOriginalConstructor()
80 $customAttributesMapper = $this->objectManager
81 ->getObject(\
Magento\Eav\Model\CustomAttributesMapper::class, [
83 'metadataPool' => $metadataPool,
87 $actual = $customAttributesMapper->entityToDatabase(
88 \
Magento\Framework\Api\CustomAttributesDataInterface::class,
90 \
Magento\Framework\Api\CustomAttributesDataInterface::CUSTOM_ATTRIBUTES => [
92 \
Magento\Framework\Api\AttributeInterface::ATTRIBUTE_CODE =>
'test',
93 \
Magento\Framework\Api\AttributeInterface::VALUE =>
'test' 96 \
Magento\Framework\Api\AttributeInterface::ATTRIBUTE_CODE =>
'test4',
97 \
Magento\Framework\Api\AttributeInterface::VALUE =>
'test4' 100 \
Magento\Framework\Api\AttributeInterface::ATTRIBUTE_CODE =>
'test2',
101 \
Magento\Framework\Api\AttributeInterface::VALUE =>
'test2' 119 $this->assertEquals($expected, $actual);
122 public function testDatabaseToEntity()
124 $searchResult = $this->getMockBuilder(\
Magento\Framework\Api\SearchResults::class)
125 ->disableOriginalConstructor()
126 ->setMethods([
'getItems'])
128 $searchResult->expects($this->any())
130 ->will($this->returnValue($this->getAttributes()));
133 ->disableOriginalConstructor()
134 ->setMethods([
'getList'])
138 ->will($this->returnValue($searchResult));
140 $metadata = $this->objectManager->getObject(
141 \
Magento\Framework\EntityManager\EntityMetadata::class,
143 'entityTableName' =>
'test',
144 'identifierField' =>
'entity_id',
145 'eavEntityType' =>
'customer_address' 149 $metadataPool = $this->getMockBuilder(\
Magento\Framework\EntityManager\MetadataPool::class)
150 ->disableOriginalConstructor()
151 ->setMethods([
'getMetadata'])
153 $metadataPool->expects($this->any())
154 ->method(
'getMetadata')
155 ->with($this->equalTo(\
Magento\Framework\Api\CustomAttributesDataInterface::class))
156 ->will($this->returnValue($metadata));
159 ->disableOriginalConstructor()
160 ->setMethods([
'addFilter',
'create'])
163 ->disableOriginalConstructor()
166 ->method(
'addFilter')
173 $customAttributesMapper = $this->objectManager
174 ->getObject(\
Magento\Eav\Model\CustomAttributesMapper::class, [
176 'metadataPool' => $metadataPool,
179 $actual = $customAttributesMapper->databaseToEntity(
180 \
Magento\Framework\Api\CustomAttributesDataInterface::class,
198 $this->assertEquals($expected, $actual);
204 private function getAttributes()
207 $attribute = $this->getMockBuilder(\
Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
208 ->disableOriginalConstructor()
209 ->setMethods([
'isStatic',
'getAttributeCode'])
210 ->getMockForAbstractClass();
213 ->will($this->returnValue(
false));
215 ->method(
'getAttributeCode')
216 ->will($this->returnValue(
'test'));
219 $attribute1 = $this->getMockBuilder(\
Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
220 ->disableOriginalConstructor()
221 ->setMethods([
'isStatic',
'getAttributeCode'])
222 ->getMockForAbstractClass();
225 ->will($this->returnValue(
false));
227 ->method(
'getAttributeCode')
228 ->will($this->returnValue(
'test1'));
231 $attribute2 = $this->getMockBuilder(\
Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
232 ->disableOriginalConstructor()
233 ->setMethods([
'isStatic',
'getAttributeCode'])
234 ->getMockForAbstractClass();
237 ->will($this->returnValue(
true));
239 ->method(
'getAttributeCode')
240 ->will($this->returnValue(
'test2'));