File tree 2 files changed +28
-1
lines changed
app/code/Magento/Catalog/Model
dev/tests/integration/testsuite/Magento/Catalog/Model
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -1712,7 +1712,7 @@ public function isInStock()
1712
1712
* Get attribute text by its code
1713
1713
*
1714
1714
* @param string $attributeCode Code of the attribute
1715
- * @return string
1715
+ * @return string|array|null
1716
1716
*/
1717
1717
public function getAttributeText ($ attributeCode )
1718
1718
{
Original file line number Diff line number Diff line change 5
5
*/
6
6
namespace Magento \Catalog \Model ;
7
7
8
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
8
9
use Magento \Framework \App \Filesystem \DirectoryList ;
9
10
10
11
/**
@@ -25,11 +26,19 @@ class ProductGettersTest extends \PHPUnit\Framework\TestCase
25
26
*/
26
27
protected $ _model ;
27
28
29
+ /**
30
+ * @var ProductRepositoryInterface
31
+ */
32
+ private $ productRepository ;
33
+
28
34
protected function setUp ()
29
35
{
30
36
$ this ->_model = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
31
37
\Magento \Catalog \Model \Product::class
32
38
);
39
+ $ this ->productRepository = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
40
+ ProductRepositoryInterface::class
41
+ );
33
42
}
34
43
35
44
public function testGetResourceCollection ()
@@ -198,6 +207,24 @@ public function testGetAttributeText()
198
207
$ this ->assertEquals ('Enabled ' , $ this ->_model ->getAttributeText ('status ' ));
199
208
}
200
209
210
+ /**
211
+ * @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php
212
+ */
213
+ public function testGetAttributeTextArray ()
214
+ {
215
+ $ product = $ this ->productRepository ->get ('simple_ms_2 ' );
216
+ $ product ->getAttributeText ('multiselect_attribute ' );
217
+ $ expected = [
218
+ 'Option 2 ' ,
219
+ 'Option 3 ' ,
220
+ 'Option 4 "!@#$%^&* '
221
+ ];
222
+ self ::assertEquals (
223
+ $ expected ,
224
+ $ product ->getAttributeText ('multiselect_attribute ' )
225
+ );
226
+ }
227
+
201
228
public function testGetCustomDesignDate ()
202
229
{
203
230
$ this ->assertEquals (['from ' => null , 'to ' => null ], $ this ->_model ->getCustomDesignDate ());
You can’t perform that action at this time.
0 commit comments