Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,33 +441,39 @@ public function testReindexFlatDisabled(

public function testGetCustomAttributes()
{
$nameAttributeCode = 'name';
$descriptionAttributeCode = 'description';
$interfaceAttributeCode = 'name';
$customAttributeCode = 'description';
$initialCustomAttributeValue = 'initial description';
$newCustomAttributeValue = 'new description';

$this->getCustomAttributeCodes->expects($this->exactly(3))
->method('execute')
->willReturn([$descriptionAttributeCode]);
$this->category->setData($nameAttributeCode, "sub");
->willReturn([$customAttributeCode]);
$this->category->setData($interfaceAttributeCode, "sub");

//The description attribute is not set, expect empty custom attribute array
$this->assertEquals([], $this->category->getCustomAttributes());

//Set the description attribute;
$this->category->setData($descriptionAttributeCode, "description");
$this->category->setData($customAttributeCode, $initialCustomAttributeValue);
$attributeValue = new \Magento\Framework\Api\AttributeValue();
$attributeValue2 = new \Magento\Framework\Api\AttributeValue();
$this->attributeValueFactory->expects($this->exactly(2))->method('create')
->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2);
$this->assertEquals(1, count($this->category->getCustomAttributes()));
$this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode));
$this->assertEquals("description", $this->category->getCustomAttribute($descriptionAttributeCode)->getValue());
$this->assertNotNull($this->category->getCustomAttribute($customAttributeCode));
$this->assertEquals(
$initialCustomAttributeValue,
$this->category->getCustomAttribute($customAttributeCode)->getValue()
);

//Change the attribute value, should reflect in getCustomAttribute
$this->category->setData($descriptionAttributeCode, "new description");
$this->category->setData($customAttributeCode, $newCustomAttributeValue);
$this->assertEquals(1, count($this->category->getCustomAttributes()));
$this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode));
$this->assertNotNull($this->category->getCustomAttribute($customAttributeCode));
$this->assertEquals(
"new description",
$this->category->getCustomAttribute($descriptionAttributeCode)->getValue()
$newCustomAttributeValue,
$this->category->getCustomAttribute($customAttributeCode)->getValue()
);
}

Expand Down
29 changes: 19 additions & 10 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,31 +1278,40 @@ public function testGetMediaGalleryImagesMerging()

public function testGetCustomAttributes()
{
$priceCode = 'price';
$colorAttributeCode = 'color';
$interfaceAttributeCode = 'price';
$customAttributeCode = 'color';
$initialCustomAttributeValue = 'red';
$newCustomAttributeValue = 'blue';

$this->getCustomAttributeCodes->expects($this->exactly(3))
->method('execute')
->willReturn([$colorAttributeCode]);
$this->model->setData($priceCode, 10);
->willReturn([$customAttributeCode]);
$this->model->setData($interfaceAttributeCode, 10);

//The color attribute is not set, expect empty custom attribute array
$this->assertEquals([], $this->model->getCustomAttributes());

//Set the color attribute;
$this->model->setData($colorAttributeCode, "red");
$this->model->setData($customAttributeCode, $initialCustomAttributeValue);
$attributeValue = new \Magento\Framework\Api\AttributeValue();
$attributeValue2 = new \Magento\Framework\Api\AttributeValue();
$this->attributeValueFactory->expects($this->exactly(2))->method('create')
->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2);
$this->assertEquals(1, count($this->model->getCustomAttributes()));
$this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
$this->assertEquals("red", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
$this->assertNotNull($this->model->getCustomAttribute($customAttributeCode));
$this->assertEquals(
$initialCustomAttributeValue,
$this->model->getCustomAttribute($customAttributeCode)->getValue()
);

//Change the attribute value, should reflect in getCustomAttribute
$this->model->setData($colorAttributeCode, "blue");
$this->model->setData($customAttributeCode, $newCustomAttributeValue);
$this->assertEquals(1, count($this->model->getCustomAttributes()));
$this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
$this->assertEquals("blue", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
$this->assertNotNull($this->model->getCustomAttribute($customAttributeCode));
$this->assertEquals(
$newCustomAttributeValue,
$this->model->getCustomAttribute($customAttributeCode)->getValue()
);
}

/**
Expand Down