1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ namespace Magento \Sitemap \Test \Unit \Model \ItemProvider ;
8
+
9
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
+ use Magento \Sitemap \Model \ItemProvider \ConfigReaderInterface ;
11
+ use Magento \Sitemap \Model \ItemProvider \StoreUrl as StoreUrlItemResolver ;
12
+ use Magento \Sitemap \Model \SitemapItem ;
13
+ use Magento \Sitemap \Model \SitemapItemInterfaceFactory ;
14
+
15
+ class StoreUrlTest extends \PHPUnit \Framework \TestCase
16
+ {
17
+ /**
18
+ * test for getItems method
19
+ */
20
+ public function testGetItems ()
21
+ {
22
+ $ configReaderMock = $ this ->getConfigReaderMock ();
23
+ $ itemFactoryMock = $ this ->getItemFactoryMock ();
24
+ $ resolver = new StoreUrlItemResolver ($ configReaderMock , $ itemFactoryMock );
25
+ $ items = $ resolver ->getItems (1 );
26
+
27
+ $ this ->assertTrue (count ($ items ) == 1 );
28
+ foreach ($ items as $ index => $ item ) {
29
+ $ this ->assertSame ('daily ' , $ items [$ index ]->getChangeFrequency ());
30
+ $ this ->assertSame ('1.0 ' , $ items [$ index ]->getPriority ());
31
+ }
32
+ }
33
+
34
+ /**
35
+ * @return \PHPUnit_Framework_MockObject_MockObject
36
+ */
37
+ private function getItemFactoryMock ()
38
+ {
39
+ $ itemFactoryMock = $ this ->getMockBuilder (SitemapItemInterfaceFactory::class)
40
+ ->setMethods (['create ' ])
41
+ ->disableOriginalConstructor ()
42
+ ->getMock ();
43
+
44
+ $ itemFactoryMock ->expects ($ this ->any ())
45
+ ->method ('create ' )
46
+ ->willReturnCallback (function ($ data ) {
47
+ $ helper = new ObjectManager ($ this );
48
+
49
+ return $ helper ->getObject (SitemapItem::class, $ data );
50
+ });
51
+
52
+ return $ itemFactoryMock ;
53
+ }
54
+
55
+ /**
56
+ * @return \PHPUnit_Framework_MockObject_MockObject
57
+ */
58
+ private function getConfigReaderMock ()
59
+ {
60
+ $ configReaderMock = $ this ->getMockForAbstractClass (ConfigReaderInterface::class);
61
+ $ configReaderMock ->expects ($ this ->any ())
62
+ ->method ('getPriority ' )
63
+ ->willReturn ('1.0 ' );
64
+ $ configReaderMock ->expects ($ this ->any ())
65
+ ->method ('getChangeFrequency ' )
66
+ ->willReturn ('daily ' );
67
+
68
+ return $ configReaderMock ;
69
+ }
70
+ }
0 commit comments