Skip to content

Commit 5802635

Browse files
ENGCOM-6511: [Bundle] Covering the SetAttributeTabBlockObserver for Bundles by Unit Test #26148
2 parents a84b38c + f75f1f2 commit 5802635

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Test\Unit\Observer;
9+
10+
use Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes;
11+
use Magento\Bundle\Observer\SetAttributeTabBlockObserver;
12+
use Magento\Catalog\Helper\Catalog;
13+
use Magento\Catalog\Model\Product;
14+
use Magento\Catalog\Model\Product\Type;
15+
use Magento\Framework\Event;
16+
use Magento\Framework\Event\Observer;
17+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Class SetAttributeTabBlockObserverTest
23+
*
24+
* Test setting attribute tab block for bundle products
25+
*/
26+
class SetAttributeTabBlockObserverTest extends TestCase
27+
{
28+
/**
29+
* @var SetAttributeTabBlockObserver
30+
*/
31+
private $observer;
32+
33+
/**
34+
* @var Catalog|MockObject
35+
*/
36+
private $helperCatalogMock;
37+
38+
/**
39+
* @var Observer|MockObject
40+
*/
41+
private $observerMock;
42+
43+
/**
44+
* @var Event|MockObject
45+
*/
46+
private $eventMock;
47+
48+
/**
49+
* @var Product|MockObject
50+
*/
51+
private $productMock;
52+
53+
/**
54+
* Set Up
55+
*/
56+
public function setUp()
57+
{
58+
$objectManager = new ObjectManager($this);
59+
$this->helperCatalogMock = $this->createMock(Catalog::class);
60+
$this->observerMock = $this->createMock(Observer::class);
61+
$this->eventMock = $this->getMockBuilder(Event::class)
62+
->disableOriginalConstructor()
63+
->setMethods(['getProduct'])
64+
->getMock();
65+
$this->productMock = $this->getMockBuilder(Product::class)
66+
->disableOriginalConstructor()
67+
->getMock();
68+
69+
$this->observer = $objectManager->getObject(
70+
SetAttributeTabBlockObserver::class,
71+
[
72+
'helperCatalog' => $this->helperCatalogMock
73+
]
74+
);
75+
}
76+
77+
/**
78+
* Test setting attribute tab block for bundle product
79+
*/
80+
public function testAddingAttributeTabForBundleProduct()
81+
{
82+
$this->productMock->expects($this->any())
83+
->method('getTypeId')
84+
->willReturn(Type::TYPE_BUNDLE);
85+
$this->eventMock->expects($this->any())
86+
->method('getProduct')
87+
->willReturn($this->productMock);
88+
$this->observerMock->expects($this->any())
89+
->method('getEvent')
90+
->willReturn($this->eventMock);
91+
$this->helperCatalogMock->expects($this->once())
92+
->method('setAttributeTabBlock')
93+
->with(Attributes::class);
94+
95+
$this->observer->execute($this->observerMock);
96+
}
97+
98+
/**
99+
* Test setting attribute tab block for a non bundle product
100+
*/
101+
public function testAddingAttributeTabForNonBundleProduct()
102+
{
103+
$this->productMock->expects($this->any())
104+
->method('getTypeId')
105+
->willReturn(Type::TYPE_VIRTUAL);
106+
$this->eventMock->expects($this->any())
107+
->method('getProduct')
108+
->willReturn($this->productMock);
109+
$this->observerMock->expects($this->any())
110+
->method('getEvent')
111+
->willReturn($this->eventMock);
112+
$this->helperCatalogMock->expects($this->never())
113+
->method('setAttributeTabBlock');
114+
115+
$this->observer->execute($this->observerMock);
116+
}
117+
}

0 commit comments

Comments
 (0)