@@ -70,6 +70,8 @@ class AbstractAddressTest extends TestCase
7070 /** @var CompositeValidator|MockObject */
7171 private $ compositeValidatorMock ;
7272
73+ private $ addressHelperMock ;
74+
7375 protected function setUp (): void
7476 {
7577 $ this ->contextMock = $ this ->createMock (Context::class);
@@ -491,6 +493,89 @@ function ($data) {
491493 );
492494 }
493495
496+ public function testGetStreetWithTwoLines ()
497+ {
498+ // Create a partial mock for AddressHelper
499+ $ this ->addressHelperMock = $ this ->getMockBuilder (\Magento \Customer \Helper \Address::class)
500+ ->disableOriginalConstructor ()
501+ ->onlyMethods (['getStreetLines ' ]) // Mock only getStreetLines, keep the real convertStreetLines
502+ ->getMock ();
503+
504+ // Mock getStreetLines to return 2 by default
505+ $ this ->addressHelperMock ->method ('getStreetLines ' )->willReturn (2 );
506+
507+ // Use reflection to inject the partial mock into the model
508+ $ reflection = new \ReflectionClass ($ this ->model );
509+ $ property = $ reflection ->getProperty ('addressHelper ' );
510+ $ property ->setAccessible (true );
511+ $ property ->setValue ($ this ->model , $ this ->addressHelperMock );
512+
513+ $ this ->addressHelperMock ->method ('getStreetLines ' )->willReturn (2 );
514+ $ streetData = ["Street Line 1 " , "Street Line 2 " , "Street Line 3 " , "Street Line 4 " ];
515+ $ this ->model ->setData ('street ' , $ streetData );
516+
517+ // Call getStreet() which should internally call convertStreetLines()
518+ $ result = $ this ->model ->getStreet ();
519+
520+ // Assert that empty and whitespace-only lines are removed by convertStreetLines
521+ $ this ->assertEquals (["Street Line 1 Street Line 2 " , "Street Line 3 Street Line 4 " ], $ result );
522+ }
523+
524+ public function testGetStreetWithThreeLines ()
525+ {
526+ // Create a partial mock for AddressHelper
527+ $ this ->addressHelperMock = $ this ->getMockBuilder (\Magento \Customer \Helper \Address::class)
528+ ->disableOriginalConstructor ()
529+ ->onlyMethods (['getStreetLines ' ]) // Mock only getStreetLines, keep the real convertStreetLines
530+ ->getMock ();
531+
532+ // Mock getStreetLines to return 2 by default
533+ $ this ->addressHelperMock ->method ('getStreetLines ' )->willReturn (3 );
534+
535+ // Use reflection to inject the partial mock into the model
536+ $ reflection = new \ReflectionClass ($ this ->model );
537+ $ property = $ reflection ->getProperty ('addressHelper ' );
538+ $ property ->setAccessible (true );
539+ $ property ->setValue ($ this ->model , $ this ->addressHelperMock );
540+
541+ $ this ->addressHelperMock ->method ('getStreetLines ' )->willReturn (3 );
542+ $ streetData = ["Street Line 1 " , "Street Line 2 " , "Street Line 3 " , "Street Line 4 " ];
543+ $ this ->model ->setData ('street ' , $ streetData );
544+
545+ // Call getStreet() which should internally call convertStreetLines()
546+ $ result = $ this ->model ->getStreet ();
547+
548+ // Assert that empty and whitespace-only lines are removed by convertStreetLines
549+ $ this ->assertEquals (["Street Line 1 Street Line 2 " ,"Street Line 3 " ,"Street Line 4 " ], $ result );
550+ }
551+
552+ public function testGetStreetWithOneLine ()
553+ {
554+ // Create a partial mock for AddressHelper
555+ $ this ->addressHelperMock = $ this ->getMockBuilder (\Magento \Customer \Helper \Address::class)
556+ ->disableOriginalConstructor ()
557+ ->onlyMethods (['getStreetLines ' ]) // Mock only getStreetLines, keep the real convertStreetLines
558+ ->getMock ();
559+
560+ // Mock getStreetLines to return 2 by default
561+ $ this ->addressHelperMock ->method ('getStreetLines ' )->willReturn (1 );
562+
563+ // Use reflection to inject the partial mock into the model
564+ $ reflection = new \ReflectionClass ($ this ->model );
565+ $ property = $ reflection ->getProperty ('addressHelper ' );
566+ $ property ->setAccessible (true );
567+ $ property ->setValue ($ this ->model , $ this ->addressHelperMock );
568+
569+ $ streetData = ["Street Line 1 " , "Street Line 2 " , "Street Line 3 " , "Street Line 4 " ];
570+ $ this ->model ->setData ('street ' , $ streetData );
571+
572+ // Call getStreet() which should internally call convertStreetLines()
573+ $ result = $ this ->model ->getStreet ();
574+
575+ // Assert that empty and whitespace-only lines are removed by convertStreetLines
576+ $ this ->assertEquals (["Street Line 1 Street Line 2 Street Line 3 Street Line 4 " ], $ result );
577+ }
578+
494579 protected function tearDown (): void
495580 {
496581 $ this ->objectManager ->setBackwardCompatibleProperty (
0 commit comments