Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EavSetupTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Eav\Setup;
8 
13 class EavSetupTest extends \PHPUnit\Framework\TestCase
14 {
20  private $eavSetup;
21 
25  protected function setUp()
26  {
28  $this->eavSetup = $objectManager->create(\Magento\Eav\Setup\EavSetup::class);
29  }
30 
39  {
40  $attributeData = $this->getAttributeData();
41 
42  $this->eavSetup->addAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, $attributeData);
43 
44  $attribute = $this->eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
45 
46  $this->assertEmpty(array_diff($attributeData, $attribute));
47  }
48 
54  public function addAttributeDataProvider()
55  {
56  return [
57  ['eav_setup_test'],
58  ['_59_characters_59_characters_59_characters_59_characters_59'],
59  ];
60  }
61 
72  {
73  $attributeData = $this->getAttributeData();
74 
75  $this->eavSetup->addAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, $attributeData);
76  }
77 
84  {
85  return [
86  [null],
87  [''],
88  [' '],
89  ['more_than_60_characters_more_than_more_than_60_characters_more'],
90  ];
91  }
92 
96  private function getAttributeData()
97  {
98  $attributeData = [
99  'type' => 'varchar',
100  'backend' => '',
101  'frontend' => '',
102  'label' => 'Eav Setup Test',
103  'input' => 'text',
104  'class' => '',
105  'source' => '',
107  'visible' => 0,
108  'required' => 0,
109  'user_defined' => 1,
110  'default' => 'none',
111  'searchable' => 0,
112  'filterable' => 0,
113  'comparable' => 0,
114  'visible_on_front' => 0,
115  'unique' => 0,
116  'apply_to' => 'category',
117  ];
118 
119  return $attributeData;
120  }
121 }
testAddAttributeThrowException($attributeCode)
$objectManager
Definition: bootstrap.php:17
$attributeCode
Definition: extend.phtml:12
testAddAttribute($attributeCode)