public function testPrepareDataSource()
 {
     $dataSource = ['data' => ['items' => [[AttributeSetText::NAME => self::ATTRIBUTE_SET_ID]]]];
     $expectedDataSource = ['data' => ['items' => [[AttributeSetText::NAME => self::ATTRIBUTE_SET_ID, '' => self::ATTRIBUTE_SET_NAME]]]];
     $this->attributeSetMock->expects($this->once())->method('getAttributeSetName')->willReturn(self::ATTRIBUTE_SET_NAME);
     $this->attributeSetRepositoryMock->expects($this->once())->method('get')->with(self::ATTRIBUTE_SET_ID)->willReturn($this->attributeSetMock);
     $this->assertEquals($expectedDataSource, $this->getModel()->prepareDataSource($dataSource));
 }
 /**
  * {@inheritdoc}
  */
 public function create($entityTypeCode, AttributeSetInterface $attributeSet, $skeletonId)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
     if ($attributeSet->getId() !== null) {
         throw InputException::invalidFieldValue('id', $attributeSet->getId());
     }
     if ($skeletonId == 0) {
         throw InputException::invalidFieldValue('skeletonId', $skeletonId);
     }
     // Make sure that skeleton attribute set is valid (try to load it)
     $this->repository->get($skeletonId);
     try {
         $attributeSet->setEntityTypeId($this->eavConfig->getEntityType($entityTypeCode)->getId());
         $attributeSet->validate();
     } catch (\Exception $exception) {
         throw new InputException(__($exception->getMessage()));
     }
     $this->repository->save($attributeSet);
     $attributeSet->initFromSkeleton($skeletonId);
     return $this->repository->save($attributeSet);
 }
 /**
  * Validate Frontend Input Type
  *
  * @param  \Magento\Eav\Api\Data\AttributeSetInterface $attributeSet
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function validate(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet)
 {
     $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
     if ($attributeSet->getEntityTypeId() != $productEntityId) {
         throw new \Magento\Framework\Exception\StateException(__('Provided Attribute set non product Attribute set.'));
     }
 }