5
5
*/
6
6
namespace Magento \Eav \Model ;
7
7
8
+ use Magento \Framework \App \Config \MutableScopeConfigInterface ;
8
9
use Magento \Framework \DataObject ;
9
10
use Magento \TestFramework \Helper \Bootstrap ;
10
11
use Magento \TestFramework \Helper \CacheCleaner ;
11
12
12
13
/**
13
14
* @magentoAppIsolation enabled
14
15
* @magentoDbIsolation enabled
15
- * @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
16
16
*/
17
17
class ConfigTest extends \PHPUnit \Framework \TestCase
18
18
{
@@ -27,6 +27,9 @@ protected function setUp()
27
27
$ this ->config = $ objectManager ->get (Config::class);
28
28
}
29
29
30
+ /**
31
+ * @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
32
+ */
30
33
public function testGetEntityAttributeCodes ()
31
34
{
32
35
$ entityType = 'test ' ;
@@ -47,6 +50,9 @@ public function testGetEntityAttributeCodes()
47
50
$ this ->assertEquals ($ entityAttributeCodes1 , $ entityAttributeCodes2 );
48
51
}
49
52
53
+ /**
54
+ * @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
55
+ */
50
56
public function testGetEntityAttributeCodesWithObject ()
51
57
{
52
58
$ entityType = 'test ' ;
@@ -74,6 +80,9 @@ public function testGetEntityAttributeCodesWithObject()
74
80
$ this ->assertEquals ($ entityAttributeCodes1 , $ entityAttributeCodes2 );
75
81
}
76
82
83
+ /**
84
+ * @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
85
+ */
77
86
public function testGetAttributes ()
78
87
{
79
88
$ entityType = 'test ' ;
@@ -96,6 +105,9 @@ public function testGetAttributes()
96
105
$ this ->assertEquals ($ attributes1 , $ attributes2 );
97
106
}
98
107
108
+ /**
109
+ * @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
110
+ */
99
111
public function testGetAttribute ()
100
112
{
101
113
$ entityType = 'test ' ;
@@ -109,4 +121,77 @@ public function testGetAttribute()
109
121
$ attribute2 = $ this ->config ->getAttribute ($ entityType , 'attribute_for_search_1 ' );
110
122
$ this ->assertEquals ($ attribute1 , $ attribute2 );
111
123
}
124
+
125
+ /**
126
+ * @magentoDataFixture Magento/Eav/_files/attribute_for_caching.php
127
+ */
128
+ public function testGetAttributeWithCacheUserDefinedAttribute ()
129
+ {
130
+ /** @var MutableScopeConfigInterface $mutableScopeConfig */
131
+ $ mutableScopeConfig = Bootstrap::getObjectManager ()->get (MutableScopeConfigInterface::class);
132
+ $ mutableScopeConfig ->setValue ('dev/caching/cache_user_defined_attributes ' , 1 );
133
+ $ entityType = 'catalog_product ' ;
134
+ $ attribute = $ this ->config ->getAttribute ($ entityType , 'foo ' );
135
+ $ this ->assertEquals ('foo ' , $ attribute ->getAttributeCode ());
136
+ $ this ->assertEquals ('foo ' , $ attribute ->getFrontendLabel ());
137
+ $ this ->assertEquals ('varchar ' , $ attribute ->getBackendType ());
138
+ $ this ->assertEquals (1 , $ attribute ->getIsRequired ());
139
+ $ this ->assertEquals (1 , $ attribute ->getIsUserDefined ());
140
+ $ this ->assertEquals (0 , $ attribute ->getIsUnique ());
141
+ // Update attribute
142
+ $ eavSetupFactory = Bootstrap::getObjectManager ()->create (\Magento \Eav \Setup \EavSetupFactory::class);
143
+ /** @var \Magento\Eav\Setup\EavSetup $eavSetup */
144
+ $ eavSetup = $ eavSetupFactory ->create ();
145
+ $ eavSetup ->updateAttribute (
146
+ \Magento \Catalog \Model \Product::ENTITY ,
147
+ 'foo ' ,
148
+ [
149
+ 'frontend_label ' => 'bar ' ,
150
+ ]
151
+ );
152
+ // Check that attribute data has not changed
153
+ $ config = Bootstrap::getObjectManager ()->create (\Magento \Eav \Model \Config::class);
154
+ $ updatedAttribute = $ config ->getAttribute ($ entityType , 'foo ' );
155
+ $ this ->assertEquals ('foo ' , $ updatedAttribute ->getFrontendLabel ());
156
+ // Clean cache
157
+ CacheCleaner::cleanAll ();
158
+ $ config = Bootstrap::getObjectManager ()->create (\Magento \Eav \Model \Config::class);
159
+ // Check that attribute data has changed
160
+ $ updatedAttributeAfterCacheClean = $ config ->getAttribute ($ entityType , 'foo ' );
161
+ $ this ->assertEquals ('bar ' , $ updatedAttributeAfterCacheClean ->getFrontendLabel ());
162
+ $ mutableScopeConfig ->setValue ('dev/caching/cache_user_defined_attributes ' , 0 );
163
+ }
164
+
165
+ /**
166
+ * @magentoDataFixture Magento/Eav/_files/attribute_for_caching.php
167
+ */
168
+ public function testGetAttributeWithInitUserDefinedAttribute ()
169
+ {
170
+ /** @var MutableScopeConfigInterface $mutableScopeConfig */
171
+ $ mutableScopeConfig = Bootstrap::getObjectManager ()->get (MutableScopeConfigInterface::class);
172
+ $ mutableScopeConfig ->setValue ('dev/caching/cache_user_defined_attributes ' , 0 );
173
+ $ entityType = 'catalog_product ' ;
174
+ $ attribute = $ this ->config ->getAttribute ($ entityType , 'foo ' );
175
+ $ this ->assertEquals ('foo ' , $ attribute ->getAttributeCode ());
176
+ $ this ->assertEquals ('foo ' , $ attribute ->getFrontendLabel ());
177
+ $ this ->assertEquals ('varchar ' , $ attribute ->getBackendType ());
178
+ $ this ->assertEquals (1 , $ attribute ->getIsRequired ());
179
+ $ this ->assertEquals (1 , $ attribute ->getIsUserDefined ());
180
+ $ this ->assertEquals (0 , $ attribute ->getIsUnique ());
181
+ // Update attribute
182
+ $ eavSetupFactory = Bootstrap::getObjectManager ()->create (\Magento \Eav \Setup \EavSetupFactory::class);
183
+ /** @var \Magento\Eav\Setup\EavSetup $eavSetup */
184
+ $ eavSetup = $ eavSetupFactory ->create ();
185
+ $ eavSetup ->updateAttribute (
186
+ \Magento \Catalog \Model \Product::ENTITY ,
187
+ 'foo ' ,
188
+ [
189
+ 'frontend_label ' => 'bar ' ,
190
+ ]
191
+ );
192
+ // Check that attribute data has changed
193
+ $ config = Bootstrap::getObjectManager ()->create (\Magento \Eav \Model \Config::class);
194
+ $ updatedAttributeAfterCacheClean = $ config ->getAttribute ($ entityType , 'foo ' );
195
+ $ this ->assertEquals ('bar ' , $ updatedAttributeAfterCacheClean ->getFrontendLabel ());
196
+ }
112
197
}
0 commit comments