|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Catalog\Test\Unit\Block\Category\Plugin; |
| 8 | + |
| 9 | +/** |
| 10 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 11 | + */ |
| 12 | +class PriceBoxTagsTest extends \PHPUnit_Framework_TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var \Magento\Framework\Pricing\PriceCurrencyInterface | \PHPUnit_Framework_MockObject_MockObject |
| 16 | + */ |
| 17 | + private $priceCurrencyInterface; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface | \PHPUnit_Framework_MockObject_MockObject |
| 21 | + */ |
| 22 | + private $timezoneInterface; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var \Magento\Framework\App\ScopeResolverInterface | \PHPUnit_Framework_MockObject_MockObject |
| 26 | + */ |
| 27 | + private $scopeResolverInterface; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var \Magento\Customer\Model\Session | \PHPUnit_Framework_MockObject_MockObject |
| 31 | + */ |
| 32 | + private $session; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var \Magento\Tax\Model\Calculation | \PHPUnit_Framework_MockObject_MockObject |
| 36 | + */ |
| 37 | + private $taxCalculation; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var \Magento\Catalog\Block\Category\Plugin\PriceBoxTags |
| 41 | + */ |
| 42 | + private $priceBoxTags; |
| 43 | + |
| 44 | + protected function setUp() |
| 45 | + { |
| 46 | + $this->priceCurrencyInterface = $this->getMockBuilder( |
| 47 | + \Magento\Framework\Pricing\PriceCurrencyInterface::class |
| 48 | + )->getMock(); |
| 49 | + $this->timezoneInterface = $this->getMockBuilder( |
| 50 | + \Magento\Framework\Stdlib\DateTime\TimezoneInterface::class |
| 51 | + )->getMock(); |
| 52 | + $this->scopeResolverInterface = $this->getMockBuilder( |
| 53 | + \Magento\Framework\App\ScopeResolverInterface::class |
| 54 | + ) |
| 55 | + ->getMockForAbstractClass(); |
| 56 | + $this->session = $this->getMockBuilder(\Magento\Customer\Model\Session::class)->disableOriginalConstructor() |
| 57 | + ->setMethods( |
| 58 | + [ |
| 59 | + 'getCustomerGroupId', |
| 60 | + 'getDefaultTaxBillingAddress', |
| 61 | + 'getDefaultTaxShippingAddress', |
| 62 | + 'getCustomerTaxClassId', |
| 63 | + 'getCustomerId' |
| 64 | + ] |
| 65 | + ) |
| 66 | + ->getMock(); |
| 67 | + $this->taxCalculation = $this->getMockBuilder(\Magento\Tax\Model\Calculation::class) |
| 68 | + ->disableOriginalConstructor()->getMock(); |
| 69 | + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 70 | + $this->priceBoxTags = $objectManager->getObject( |
| 71 | + \Magento\Catalog\Block\Category\Plugin\PriceBoxTags::class, |
| 72 | + [ |
| 73 | + 'priceCurrency' => $this->priceCurrencyInterface, |
| 74 | + 'dateTime' => $this->timezoneInterface, |
| 75 | + 'scopeResolver' => $this->scopeResolverInterface, |
| 76 | + 'customerSession' => $this->session, |
| 77 | + 'taxCalculation' => $this->taxCalculation |
| 78 | + ] |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + public function testAfterGetCacheKey() |
| 83 | + { |
| 84 | + $date = date('Ymd'); |
| 85 | + $currencySymbol = '$'; |
| 86 | + $result = 'result_string'; |
| 87 | + $billingAddress = ['billing_address']; |
| 88 | + $shippingAddress = ['shipping_address']; |
| 89 | + $scopeId = 1; |
| 90 | + $customerGroupId = 2; |
| 91 | + $customerTaxClassId = 3; |
| 92 | + $customerId = 4; |
| 93 | + $rateIds = [5,6]; |
| 94 | + $expected = implode( |
| 95 | + '-', |
| 96 | + [ |
| 97 | + $result, |
| 98 | + $currencySymbol, |
| 99 | + $date, |
| 100 | + $scopeId, |
| 101 | + $customerGroupId, |
| 102 | + implode('_', $rateIds) |
| 103 | + ] |
| 104 | + ); |
| 105 | + $priceBox = $this->getMockBuilder(\Magento\Framework\Pricing\Render\PriceBox::class) |
| 106 | + ->disableOriginalConstructor()->getMock(); |
| 107 | + $this->priceCurrencyInterface->expects($this->once())->method('getCurrencySymbol')->willReturn($currencySymbol); |
| 108 | + $scope = $this->getMockBuilder(\Magento\Framework\App\ScopeInterface::class)->getMock(); |
| 109 | + $this->scopeResolverInterface->expects($this->any())->method('getScope')->willReturn($scope); |
| 110 | + $scope->expects($this->any())->method('getId')->willReturn($scopeId); |
| 111 | + $dateTime = $this->getMockBuilder(\DateTime::class)->getMock(); |
| 112 | + $this->timezoneInterface->expects($this->any())->method('scopeDate')->with($scopeId)->willReturn($dateTime); |
| 113 | + $dateTime->expects($this->any())->method('format')->with('Ymd')->willReturn($date); |
| 114 | + $this->session->expects($this->once())->method('getCustomerGroupId')->willReturn($customerGroupId); |
| 115 | + $this->session->expects($this->once())->method('getDefaultTaxBillingAddress')->willReturn($billingAddress); |
| 116 | + $this->session->expects($this->once())->method('getDefaultTaxShippingAddress')->willReturn($shippingAddress); |
| 117 | + $this->session->expects($this->once())->method('getCustomerTaxClassId') |
| 118 | + ->willReturn($customerTaxClassId); |
| 119 | + $this->session->expects($this->once())->method('getCustomerId')->willReturn($customerId); |
| 120 | + $rateRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class)->getMock(); |
| 121 | + $this->taxCalculation->expects($this->once())->method('getRateRequest')->with( |
| 122 | + new \Magento\Framework\DataObject($billingAddress), |
| 123 | + new \Magento\Framework\DataObject($shippingAddress), |
| 124 | + $customerTaxClassId, |
| 125 | + $scopeId, |
| 126 | + $customerId |
| 127 | + )->willReturn($rateRequest); |
| 128 | + $salableInterface = $this->getMockBuilder(\Magento\Framework\Pricing\SaleableInterface::class) |
| 129 | + ->setMethods(['getTaxClassId']) |
| 130 | + ->getMockForAbstractClass(); |
| 131 | + $priceBox->expects($this->once())->method('getSaleableItem')->willReturn($salableInterface); |
| 132 | + $salableInterface->expects($this->once())->method('getTaxClassId')->willReturn($customerTaxClassId); |
| 133 | + $resource = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\AbstractResource::class) |
| 134 | + ->setMethods(['getRateIds']) |
| 135 | + ->getMockForAbstractClass(); |
| 136 | + $this->taxCalculation->expects($this->once())->method('getResource')->willReturn($resource); |
| 137 | + $resource->expects($this->once())->method('getRateIds')->with($rateRequest)->willReturn($rateIds); |
| 138 | + |
| 139 | + $this->assertEquals($expected, $this->priceBoxTags->afterGetCacheKey($priceBox, $result)); |
| 140 | + } |
| 141 | +} |
0 commit comments