77
88namespace Magento \Catalog \Test \Unit \Block \Category ;
99
10+ use Magento \Catalog \Block \Breadcrumbs ;
1011use Magento \Catalog \Block \Category \View ;
12+ use Magento \Catalog \Helper \Category as CategoryHelper ;
13+ use Magento \Catalog \Helper \Data as CatalogData ;
1114use Magento \Catalog \Model \Category ;
15+ use Magento \Catalog \Model \Layer \Resolver as LayerResolver ;
1216use Magento \Framework \App \Config \ScopeConfigInterface ;
13- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
17+ use Magento \Framework \Registry ;
18+ use Magento \Framework \View \Element \Template \Context ;
19+ use Magento \Framework \View \LayoutInterface ;
20+ use Magento \Framework \View \Page \Config ;
21+ use Magento \Framework \View \Page \Title ;
1422use PHPUnit \Framework \MockObject \MockObject ;
1523use PHPUnit \Framework \TestCase ;
1624
25+ /**
26+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+ */
1728class ViewTest extends TestCase
1829{
1930 /**
@@ -26,10 +37,40 @@ class ViewTest extends TestCase
2637 */
2738 protected $ scopeConfigMock ;
2839
40+ /**
41+ * @var Registry|MockObject
42+ */
43+ private $ registry ;
44+
45+ /**
46+ * @var Config|MockObject
47+ */
48+ private $ config ;
49+
50+ /**
51+ * @var CatalogData|MockObject
52+ */
53+ private $ catalogData ;
2954 protected function setUp (): void
3055 {
31- $ objectManager = new ObjectManager ($ this );
32- $ this ->block = $ objectManager ->getObject (View::class, []);
56+ parent ::setUp ();
57+ $ context = $ this ->createMock (Context::class);
58+ $ this ->config = $ this ->createMock (Config::class);
59+ $ context ->expects ($ this ->once ())->method ('getPageConfig ' )
60+ ->willReturn ($ this ->config );
61+ $ layerResolver = $ this ->createMock (LayerResolver::class);
62+ $ this ->registry = $ this ->createMock (Registry::class);
63+ $ categoryHelper = $ this ->createMock (CategoryHelper::class);
64+ $ this ->catalogData = $ this ->createMock (CatalogData::class);
65+
66+ $ this ->block = new View (
67+ $ context ,
68+ $ layerResolver ,
69+ $ this ->registry ,
70+ $ categoryHelper ,
71+ [],
72+ $ this ->catalogData
73+ );
3374 }
3475
3576 protected function tearDown (): void
@@ -45,4 +86,43 @@ public function testGetIdentities()
4586 $ this ->block ->setCurrentCategory ($ currentCategoryMock );
4687 $ this ->assertEquals ($ categoryTag , $ this ->block ->getIdentities ());
4788 }
89+
90+ public function testBreadcrumbs ()
91+ {
92+ $ layoutMock = $ this ->createMock (LayoutInterface::class);
93+ $ beadCrumbs = $ this ->createMock (Breadcrumbs::class);
94+ $ title = $ this ->createMock (Title::class);
95+ $ category = $ this ->getMockBuilder (Category::class)
96+ ->disableOriginalConstructor ()
97+ ->addMethods (['getMetaTitle ' ])
98+ ->getMock ();
99+
100+ $ beadCrumbs ->expects ($ this ->once ())
101+ ->method ('getTitleSeparator ' )
102+ ->willReturn (' - ' );
103+
104+ $ layoutMock ->expects ($ this ->once ())
105+ ->method ('createBlock ' )
106+ ->willReturn ($ beadCrumbs );
107+
108+ $ category ->expects ($ this ->once ())
109+ ->method ('getMetaTitle ' )
110+ ->willReturn (null );
111+ $ this ->registry ->expects ($ this ->once ())
112+ ->method ('registry ' )
113+ ->willReturn ($ category );
114+
115+ $ title ->expects ($ this ->once ())
116+ ->method ('set ' )
117+ ->willReturnSelf ();
118+ $ this ->config ->expects ($ this ->once ())
119+ ->method ('getTitle ' )
120+ ->willReturn ($ title );
121+
122+ $ this ->catalogData ->expects ($ this ->once ())
123+ ->method ('getBreadcrumbPath ' )
124+ ->willReturn ([['label ' => 'label1 ' ], ['label ' => 'label2 ' ]]);
125+
126+ $ this ->block ->setLayout ($ layoutMock );
127+ }
48128}
0 commit comments