/** * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testGetSetAttributes() { $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product'); $product->load(1); // fixture $attributes = $this->_model->getSetAttributes($product); $this->assertArrayHasKey('sku', $attributes); $this->assertArrayHasKey('name', $attributes); foreach ($attributes as $attribute) { $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', $attribute); } /* possibility of fatal error if passing null instead of product */ }
/** * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testGetSetAttributes() { $repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\ProductRepository'); $product = $repository->get('simple'); // fixture $this->assertArrayNotHasKey('_cache_instance_product_set_attributes', $product->getData()); $attributes = $this->_model->getSetAttributes($product); $this->assertArrayHasKey('_cache_instance_product_set_attributes', $product->getData()); $this->assertArrayHasKey('sku', $attributes); $this->assertArrayHasKey('name', $attributes); $isTypeExists = false; foreach ($attributes as $attribute) { $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', $attribute); $applyTo = $attribute->getApplyTo(); if (count($applyTo) > 0 && !in_array('simple', $applyTo)) { $isTypeExists = true; } } /* possibility of fatal error if passing null instead of product */ $this->assertTrue($isTypeExists); }