5
5
*/
6
6
namespace Magento \Sitemap \Test \Unit \Model ;
7
7
8
+ use Magento \Framework \App \Request \Http ;
8
9
use Magento \Framework \DataObject ;
9
10
use Magento \Framework \Filesystem ;
10
11
use Magento \Framework \Filesystem \Directory \Write as DirectoryWrite ;
@@ -86,6 +87,15 @@ class SitemapTest extends \PHPUnit\Framework\TestCase
86
87
*/
87
88
private $ configReaderMock ;
88
89
90
+ /**
91
+ * @var Http|\PHPUnit_Framework_MockObject_MockObject
92
+ */
93
+ private $ request ;
94
+ /**
95
+ * @var Store|\PHPUnit_Framework_MockObject_MockObject
96
+ */
97
+ private $ store ;
98
+
89
99
/**
90
100
* @inheritdoc
91
101
*/
@@ -143,6 +153,12 @@ protected function setUp()
143
153
144
154
$ this ->configReaderMock = $ this ->getMockForAbstractClass (SitemapConfigReaderInterface::class);
145
155
$ this ->itemProviderMock = $ this ->getMockForAbstractClass (ItemProviderInterface::class);
156
+ $ this ->request = $ this ->createMock (Http::class);
157
+ $ this ->store = $ this ->createPartialMock (Store::class, ['isFrontUrlSecure ' , 'getBaseUrl ' ]);
158
+ $ this ->storeManagerMock = $ this ->createMock (StoreManagerInterface::class);
159
+ $ this ->storeManagerMock ->expects ($ this ->any ())
160
+ ->method ('getStore ' )
161
+ ->willReturn ($ this ->store );
146
162
}
147
163
148
164
/**
@@ -476,25 +492,15 @@ function ($from, $to) {
476
492
477
493
$ model = $ this ->getModelMock (true );
478
494
479
- $ storeMock = $ this ->getMockBuilder (Store::class)
480
- ->setMethods (['isFrontUrlSecure ' , 'getBaseUrl ' ])
481
- ->disableOriginalConstructor ()
482
- ->getMock ();
483
-
484
- $ storeMock ->expects ($ this ->atLeastOnce ())
495
+ $ this ->store ->expects ($ this ->atLeastOnce ())
485
496
->method ('isFrontUrlSecure ' )
486
497
->willReturn (false );
487
498
488
- $ storeMock ->expects ($ this ->atLeastOnce ())
499
+ $ this -> store ->expects ($ this ->atLeastOnce ())
489
500
->method ('getBaseUrl ' )
490
501
->with ($ this ->isType ('string ' ), false )
491
502
->willReturn ('http://store.com/ ' );
492
503
493
- $ this ->storeManagerMock ->expects ($ this ->atLeastOnce ())
494
- ->method ('getStore ' )
495
- ->with (1 )
496
- ->willReturn ($ storeMock );
497
-
498
504
return $ model ;
499
505
}
500
506
@@ -599,10 +605,6 @@ private function getModelConstructorArgs()
599
605
->disableOriginalConstructor ()
600
606
->getMock ();
601
607
602
- $ this ->storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)
603
- ->setMethods (['getStore ' ])
604
- ->getMockForAbstractClass ();
605
-
606
608
$ objectManager = new ObjectManager ($ this );
607
609
$ escaper = $ objectManager ->getObject (\Magento \Framework \Escaper::class);
608
610
@@ -617,7 +619,8 @@ private function getModelConstructorArgs()
617
619
'filesystem ' => $ this ->filesystemMock ,
618
620
'itemProvider ' => $ this ->itemProviderMock ,
619
621
'configReader ' => $ this ->configReaderMock ,
620
- 'escaper ' => $ escaper
622
+ 'escaper ' => $ escaper ,
623
+ 'request ' => $ this ->request ,
621
624
]
622
625
);
623
626
$ constructArguments ['resource ' ] = null ;
@@ -732,4 +735,62 @@ public static function siteUrlDataProvider()
732
735
]
733
736
];
734
737
}
738
+
739
+ /**
740
+ * Check site URL getter
741
+ *
742
+ * @param string $storeBaseUrl
743
+ * @param string $baseDir
744
+ * @param string $documentRoot
745
+ * @dataProvider getDocumentRootFromBaseDirUrlDataProvider
746
+ */
747
+ public function testGetDocumentRootFromBaseDir (
748
+ string $ storeBaseUrl ,
749
+ string $ baseDir ,
750
+ ?string $ documentRoot
751
+ ) {
752
+ $ this ->store ->setCode ('store ' );
753
+ $ this ->store ->method ('getBaseUrl ' )->willReturn ($ storeBaseUrl );
754
+ $ this ->directoryMock ->method ('getAbsolutePath ' )->willReturn ($ baseDir );
755
+ /** @var $model Sitemap */
756
+ $ model = $ this ->getMockBuilder (Sitemap::class)
757
+ ->setMethods (['_construct ' ])
758
+ ->setConstructorArgs ($ this ->getModelConstructorArgs ())
759
+ ->getMock ();
760
+
761
+ $ method = new \ReflectionMethod ($ model , 'getDocumentRootFromBaseDir ' );
762
+ $ method ->setAccessible (true );
763
+ $ this ->assertSame ($ documentRoot , $ method ->invoke ($ model ));
764
+ }
765
+
766
+ /**
767
+ * Provides test cases for document root testing
768
+ *
769
+ * @return array
770
+ */
771
+ public function getDocumentRootFromBaseDirUrlDataProvider (): array
772
+ {
773
+ return [
774
+ [
775
+ 'http://magento.com/ ' ,
776
+ '/var/www ' ,
777
+ '/var/www ' ,
778
+ ],
779
+ [
780
+ 'http://magento.com/usa ' ,
781
+ '/var/www/usa ' ,
782
+ '/var/www ' ,
783
+ ],
784
+ [
785
+ 'http://magento.com/usa/tx ' ,
786
+ '/var/www/usa/tx ' ,
787
+ '/var/www ' ,
788
+ ],
789
+ 'symlink <document root>/usa/txt -> /var/www/html ' => [
790
+ 'http://magento.com/usa/tx ' ,
791
+ '/var/www/html ' ,
792
+ null ,
793
+ ],
794
+ ];
795
+ }
735
796
}
0 commit comments