Skip to content

Commit 70c8dfb

Browse files
author
Joan He
committed
MAGETWO-64216: Add integration test of \Magento\Eav\Model\Entity\AttributeLoader
1 parent 4627ab5 commit 70c8dfb

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

dev/tests/integration/testsuite/Magento/Eav/Model/Entity/AttributeLoaderTest.php

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* @magentoAppIsolation enabled
14-
* @magentoDataFixture Magento/Catalog/_files/category_attribute.php
14+
* @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
1515
*/
1616
class AttributeLoaderTest extends \PHPUnit_Framework_TestCase
1717
{
@@ -24,12 +24,28 @@ class AttributeLoaderTest extends \PHPUnit_Framework_TestCase
2424
* @var \Magento\Framework\ObjectManagerInterface
2525
*/
2626
private $objectManager;
27-
27+
28+
/**
29+
* @var \Magento\Eav\Model\Entity\AbstractEntity
30+
*/
31+
private $resource;
32+
2833
protected function setUp()
2934
{
3035
CacheCleaner::cleanAll();
3136
$this->objectManager = Bootstrap::getObjectManager();
3237
$this->attributeLoader = $this->objectManager->get(AttributeLoader::class);
38+
$entityType = $this->objectManager->create(\Magento\Eav\Model\Entity\Type::class)
39+
->loadByCode('test');
40+
$context = $this->objectManager->get(\Magento\Eav\Model\Entity\Context::class);
41+
$this->resource = $this->getMockBuilder(\Magento\Eav\Model\Entity\AbstractEntity::class)
42+
->setConstructorArgs([$context])
43+
->setMethods(['getEntityType', 'getLinkField'])
44+
->getMock();
45+
$this->resource->method('getEntityType')
46+
->willReturn($entityType);
47+
$this->resource->method('getLinkField')
48+
->willReturn('link_field');
3349
}
3450

3551
/**
@@ -43,50 +59,51 @@ public function testLoadAllAttributesTheFirstTime(
4359
$expectedNumOfAttributesByTable,
4460
$object
4561
) {
46-
/** @var \Magento\Catalog\Model\ResourceModel\Category $categoryResourceModel */
47-
$categoryResourceModel = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Category::class);
48-
4962
// Before load all attributes
50-
$attributesByCode = $categoryResourceModel->getAttributesByCode();
51-
$attributesByTable = $categoryResourceModel->getAttributesByTable();
63+
$attributesByCode = $this->resource->getAttributesByCode();
64+
$attributesByTable = $this->resource->getAttributesByTable();
5265
$this->assertEquals(0, count($attributesByCode));
5366
$this->assertEquals(0, count($attributesByTable));
5467

5568
// Load all attributes
56-
$categoryResourceModel2 = $this->attributeLoader->loadAllAttributes(
57-
$categoryResourceModel,
69+
$resource2 = $this->attributeLoader->loadAllAttributes(
70+
$this->resource,
5871
$object
5972
);
60-
$attributesByCode2 = $categoryResourceModel2->getAttributesByCode();
61-
$attributesByTable2 = $categoryResourceModel2->getAttributesByTable();
73+
$attributesByCode2 = $resource2->getAttributesByCode();
74+
$attributesByTable2 = $resource2->getAttributesByTable();
6275
$this->assertEquals($expectedNumOfAttributesByCode, count($attributesByCode2));
6376
$this->assertEquals($expectedNumOfAttributesByTable, count($attributesByTable2));
6477
}
6578

6679
public function loadAllAttributesDataProvider()
6780
{
81+
/** @var \Magento\Eav\Model\Entity\Type $entityType */
82+
$entityType = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Entity\Type::class)
83+
->loadByCode('order');
84+
$attributeSetId = $entityType->getDefaultAttributeSetId();
6885
return [
6986
[
70-
40,
71-
5,
87+
13,
88+
2,
7289
null
7390
],
7491
[
75-
39,
76-
5,
92+
10,
93+
1,
7794
new DataObject(
7895
[
79-
'attribute_set_id' => 3,
96+
'attribute_set_id' => $attributeSetId,
8097
'store_id' => 0
8198
]
8299
),
83100
],
84101
[
85-
39,
86-
5,
102+
10,
103+
1,
87104
new DataObject(
88105
[
89-
'attribute_set_id' => 3,
106+
'attribute_set_id' => $attributeSetId,
90107
'store_id' => 10
91108
]
92109
),

0 commit comments

Comments
 (0)