Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetTest.php
Go to the documentation of this file.
1 <?php
11 
12 class SetTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $_model;
18 
19  protected function setUp()
20  {
21  $resource = $this->createMock(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set::class);
22  $attrGroupFactory = $this->createMock(\Magento\Eav\Model\Entity\Attribute\GroupFactory::class);
23  $attrFactory = $this->createMock(\Magento\Eav\Model\Entity\AttributeFactory::class);
24  $arguments = [
25  'attrGroupFactory' => $attrGroupFactory,
26  'attributeFactory' => $attrFactory,
27  'resource' => $resource,
28  ];
29  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
30  $this->_model = $objectManagerHelper->getObject(\Magento\Eav\Model\Entity\Attribute\Set::class, $arguments);
31  }
32 
33  protected function tearDown()
34  {
35  $this->_model = null;
36  }
37 
43  public function testValidateWithExistingName($attributeSetName, $exceptionMessage)
44  {
45  $this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(false));
46 
47  $this->expectException(\Magento\Framework\Exception\LocalizedException::class);
48  $this->expectExceptionMessage($exceptionMessage);
49  $this->_model->setAttributeSetName($attributeSetName);
50  $this->_model->validate();
51  }
52 
54  {
55  $this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(true));
56 
57  $this->_model->setAttributeSetName('nonexistent_name');
58  $this->assertTrue($this->_model->validate());
59  }
60 
67  {
68  return [
69  ['', 'The attribute set name is empty. Enter the name and try again.'],
70  ['existing_name', 'A "existing_name" attribute set name already exists. Create a new name and try again.']
71  ];
72  }
73 }
testValidateWithExistingName($attributeSetName, $exceptionMessage)
Definition: SetTest.php:43
$resource
Definition: bulk.php:12
$arguments