33 * Copyright 2011 Adobe
44 * All Rights Reserved.
55 */
6- declare (strict_types=1 );
76
87namespace Magento \Customer \Model ;
98
10- use Magento \Customer \Api \Data \GroupInterfaceFactory ;
11- use Magento \Framework \Exception \LocalizedException ;
12- use Magento \TestFramework \Helper \Bootstrap ;
13- use PHPUnit \Framework \TestCase ;
14-
15- class GroupTest extends TestCase
9+ class GroupTest extends \PHPUnit \Framework \TestCase
1610{
1711 /**
18- * @var Group
12+ * @var \Magento\Customer\Model\ Group
1913 */
2014 protected $ groupModel ;
2115
2216 /**
23- * @var GroupInterfaceFactory
17+ * @var \Magento\Customer\Api\Data\ GroupInterfaceFactory
2418 */
2519 protected $ groupFactory ;
2620
2721 protected function setUp (): void
2822 {
29- $ this ->groupModel = Bootstrap::getObjectManager ()->create (Group::class);
30- $ this ->groupFactory = Bootstrap::getObjectManager ()->create (GroupInterfaceFactory::class);
23+ $ this ->groupModel = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
24+ \Magento \Customer \Model \Group::class
25+ );
26+ $ this ->groupFactory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
27+ \Magento \Customer \Api \Data \GroupInterfaceFactory::class
28+ );
3129 }
3230
3331 public function testCRUD ()
@@ -38,74 +36,43 @@ public function testCRUD()
3836 }
3937
4038 /**
41- * Test that customer group correctly handles multibyte and normal characters when saving
39+ * Test that customer group correctly handles multibyte characters when saving
4240 *
4341 * This verifies that the fix for multibyte character truncation works correctly.
4442 * Previously, substr() was used which counted bytes instead of characters,
4543 * causing multibyte characters to be truncated incorrectly.
4644 *
4745 * @magentoDbIsolation enabled
48- * @dataProvider customerGroupCodeDataProvider
49- * @param string $code
50- * @param string $expectedCode
51- * @param int $charLength
5246 * @return void
53- * @throws LocalizedException
5447 */
55- public function testMultibyteAndNormalCharacterHandling ( string $ code , string $ expectedCode , int $ charLength ): void
48+ public function testMultibyteCharacterHandling ( ): void
5649 {
57- $ this ->groupModel ->setCode ($ code );
58- $ this ->groupModel ->setTaxClassId (3 );
59- $ group = $ this ->groupModel ->save ();
50+ // Test with multibyte characters (ö = 2 bytes in UTF-8)
51+ $ multibyteString = str_repeat ('ö ' , 31 ); // 31 characters, 62 bytes
52+
53+ $ group = $ this ->groupFactory ->create ();
54+ $ group ->setCode ($ multibyteString );
55+ $ group ->setTaxClassId (3 );
56+ $ group ->save ();
6057
6158 // Reload from database
62- $ reloadedGroup = $ this ->groupModel ->load ($ group ->getId ());
59+ $ reloadedGroup = $ this ->groupFactory ->create ();
60+ $ reloadedGroup ->load ($ group ->getId ());
6361
64- // Verify all 32 characters are preserved
62+ // Verify all 31 multibyte characters are preserved
6563 $ this ->assertEquals (
66- $ expectedCode ,
64+ $ multibyteString ,
6765 $ reloadedGroup ->getCode (),
68- 'Group code with multibyte and normal characters should be saved correctly '
66+ 'Group code with multibyte characters should be saved correctly '
6967 );
7068
7169 $ this ->assertEquals (
72- $ charLength ,
70+ 31 ,
7371 mb_strlen ($ reloadedGroup ->getCode ()),
74- 'Group code should have maximum 32 characters '
72+ 'Group code should have exactly 31 characters '
7573 );
7674
7775 // Cleanup
7876 $ reloadedGroup ->delete ();
7977 }
80-
81- /**
82- * Customer group code data provider
83- *
84- * @return array[]
85- */
86- public static function customerGroupCodeDataProvider (): array
87- {
88- // Test with multibyte characters (ö = 2 bytes in UTF-8)
89- $ multibyteString = str_repeat ('ö ' , 32 ); // 31 characters, 62 bytes
90- $ normalString = str_repeat ('a ' , 50 ); // 40 characters, will be truncated
91- $ normalTruncatedString = str_repeat ('a ' , 32 ); // 31 characters, truncated code after saving
92- $ mixedString = str_repeat ('a ' , 10 ).str_repeat ('ö ' , 10 );
93- return [
94- 'multibyte characters ' => [
95- $ multibyteString ,
96- $ multibyteString ,
97- 32
98- ],
99- 'normal characters ' => [
100- $ normalString ,
101- $ normalTruncatedString ,
102- 32
103- ],
104- 'mixed characters ' => [
105- $ mixedString ,
106- $ mixedString ,
107- 20
108- ]
109- ];
110- }
11178}
0 commit comments