SetTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Eav\Model\Entity\Attribute\Set
  8. */
  9. namespace Magento\Eav\Test\Unit\Model\Entity\Attribute;
  10. class SetTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Eav\Model\Entity\Attribute\Set
  14. */
  15. protected $_model;
  16. protected function setUp()
  17. {
  18. $resource = $this->createMock(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set::class);
  19. $attrGroupFactory = $this->createMock(\Magento\Eav\Model\Entity\Attribute\GroupFactory::class);
  20. $attrFactory = $this->createMock(\Magento\Eav\Model\Entity\AttributeFactory::class);
  21. $arguments = [
  22. 'attrGroupFactory' => $attrGroupFactory,
  23. 'attributeFactory' => $attrFactory,
  24. 'resource' => $resource,
  25. ];
  26. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  27. $this->_model = $objectManagerHelper->getObject(\Magento\Eav\Model\Entity\Attribute\Set::class, $arguments);
  28. }
  29. protected function tearDown()
  30. {
  31. $this->_model = null;
  32. }
  33. /**
  34. * @param string $attributeSetName
  35. * @param string $exceptionMessage
  36. * @dataProvider invalidAttributeSetDataProvider
  37. */
  38. public function testValidateWithExistingName($attributeSetName, $exceptionMessage)
  39. {
  40. $this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(false));
  41. $this->expectException(\Magento\Framework\Exception\LocalizedException::class);
  42. $this->expectExceptionMessage($exceptionMessage);
  43. $this->_model->setAttributeSetName($attributeSetName);
  44. $this->_model->validate();
  45. }
  46. public function testValidateWithNonexistentValidName()
  47. {
  48. $this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(true));
  49. $this->_model->setAttributeSetName('nonexistent_name');
  50. $this->assertTrue($this->_model->validate());
  51. }
  52. /**
  53. * Retrieve data for invalid
  54. *
  55. * @return array
  56. */
  57. public function invalidAttributeSetDataProvider()
  58. {
  59. return [
  60. ['', 'The attribute set name is empty. Enter the name and try again.'],
  61. ['existing_name', 'A "existing_name" attribute set name already exists. Create a new name and try again.']
  62. ];
  63. }
  64. }