10 use Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\CollectionFactory;
20 private $isAllowedGuestCheckoutObserver;
40 private $observerMock;
53 $this->scopeConfig = $this->getMockBuilder(\
Magento\Framework\
App\Config::class)
54 ->disableOriginalConstructor()
55 ->setMethods([
'isSetFlag',
'getValue'])
58 $this->resultMock = $this->getMockBuilder(\
Magento\Framework\DataObject::class)
59 ->disableOriginalConstructor()
60 ->setMethods([
'setIsAllowed'])
63 $this->eventMock = $this->getMockBuilder(\
Magento\Framework\Event::class)
64 ->disableOriginalConstructor()
65 ->setMethods([
'getStore',
'getResult',
'getQuote',
'getOrder'])
68 $this->observerMock = $this->getMockBuilder(\
Magento\Framework\Event\Observer::class)
69 ->disableOriginalConstructor()
70 ->setMethods([
'getEvent'])
73 $this->storeMock = $this->getMockBuilder(\
Magento\Framework\DataObject::class)
74 ->disableOriginalConstructor()
77 $this->isAllowedGuestCheckoutObserver = (
new ObjectManagerHelper($this))->getObject(
78 \
Magento\Downloadable\Observer\IsAllowedGuestCheckoutObserver::class,
80 'scopeConfig' => $this->scopeConfig,
95 $this->resultMock->expects($this->at(0))
96 ->method(
'setIsAllowed')
100 $product = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
101 ->disableOriginalConstructor()
102 ->setMethods([
'getTypeId'])
106 ->method(
'getTypeId')
107 ->willReturn($productType);
109 $item = $this->getMockBuilder(\
Magento\Quote\Model\Quote\Item::class)
110 ->disableOriginalConstructor()
111 ->setMethods([
'getProduct'])
114 $item->expects($this->once())
115 ->method(
'getProduct')
118 $quote = $this->getMockBuilder(\
Magento\Quote\Model\Quote::class)
119 ->disableOriginalConstructor()
120 ->setMethods([
'getAllItems'])
123 $quote->expects($this->once())
124 ->method(
'getAllItems')
125 ->willReturn([
$item]);
127 $this->eventMock->expects($this->once())
129 ->will($this->returnValue($this->storeMock));
131 $this->eventMock->expects($this->once())
132 ->method(
'getResult')
133 ->will($this->returnValue($this->resultMock));
135 $this->eventMock->expects($this->once())
137 ->will($this->returnValue(
$quote));
139 $this->scopeConfig->expects($this->once())
140 ->method(
'isSetFlag')
148 $this->observerMock->expects($this->exactly(3))
150 ->will($this->returnValue($this->eventMock));
152 $this->assertInstanceOf(
153 \
Magento\Downloadable\Observer\IsAllowedGuestCheckoutObserver::class,
154 $this->isAllowedGuestCheckoutObserver->execute($this->observerMock)
165 2 => [
'unknown',
false],
171 $this->eventMock->expects($this->once())
173 ->will($this->returnValue($this->storeMock));
175 $this->eventMock->expects($this->once())
176 ->method(
'getResult')
177 ->will($this->returnValue($this->resultMock));
179 $this->scopeConfig->expects($this->once())
180 ->method(
'isSetFlag')
188 $this->observerMock->expects($this->exactly(2))
190 ->will($this->returnValue($this->eventMock));
192 $this->assertInstanceOf(
193 \
Magento\Downloadable\Observer\IsAllowedGuestCheckoutObserver::class,
194 $this->isAllowedGuestCheckoutObserver->execute($this->observerMock)
const XML_PATH_DISABLE_GUEST_CHECKOUT
testIsAllowedGuestCheckoutConfigSetToTrue($productType, $isAllowed)
testIsAllowedGuestCheckoutConfigSetToFalse()
dataProviderForTestisAllowedGuestCheckoutConfigSetToTrue()