Exemplo n.º 1
0
 public function testGetCustomAttributes()
 {
     $nameAttributeCode = 'name';
     $descriptionAttributeCode = 'description';
     $interfaceAttribute = $this->getMock('\\Magento\\Framework\\Api\\MetadataObjectInterface');
     $interfaceAttribute->expects($this->once())->method('getAttributeCode')->willReturn($nameAttributeCode);
     $descriptionAttribute = $this->getMock('\\Magento\\Framework\\Api\\MetadataObjectInterface');
     $descriptionAttribute->expects($this->once())->method('getAttributeCode')->willReturn($descriptionAttributeCode);
     $customAttributesMetadata = [$interfaceAttribute, $descriptionAttribute];
     $this->metadataServiceMock->expects($this->once())->method('getCustomAttributesMetadata')->willReturn($customAttributesMetadata);
     $this->category->setData($nameAttributeCode, "sub");
     //The color attribute is not set, expect empty custom attribute array
     $this->assertEquals([], $this->category->getCustomAttributes());
     //Set the color attribute;
     $this->category->setData($descriptionAttributeCode, "description");
     $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());
     //Change the attribute value, should reflect in getCustomAttribute
     $this->category->setData($descriptionAttributeCode, "new description");
     $this->assertEquals(1, count($this->category->getCustomAttributes()));
     $this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode));
     $this->assertEquals("new description", $this->category->getCustomAttribute($descriptionAttributeCode)->getValue());
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getCustomAttributes()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getCustomAttributes');
     if (!$pluginInfo) {
         return parent::getCustomAttributes();
     } else {
         return $this->___callPlugins('getCustomAttributes', func_get_args(), $pluginInfo);
     }
 }