123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Weee\Test\Unit\Observer;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
- class GetPriceConfigurationObserverTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * Tests the methods that rely on the ScopeConfigInterface object to provide their return values
- * @dataProvider getPriceConfigurationProvider
- * @param bool $hasWeeeAttributes
- * @param array $testArray
- * @param array $expectedArray
- */
- public function testGetPriceConfiguration($hasWeeeAttributes, $testArray, $expectedArray)
- {
- $configObj = new \Magento\Framework\DataObject(
- [
- 'config' => $testArray,
- ]
- );
- $weeeObject1 = new \Magento\Framework\DataObject(
- [
- 'code' => 'fpt1',
- 'amount' => '15.0000',
- ]
- );
- $weeeObject2 = new \Magento\Framework\DataObject(
- [
- 'code' => 'fpt2',
- 'amount' => '16.0000',
- ]
- );
- $weeeHelper=$this->createMock(\Magento\Weee\Helper\Data::class);
- $weeeHelper->expects($this->any())
- ->method('isEnabled')
- ->will($this->returnValue(true));
- $observerObject=$this->createMock(\Magento\Framework\Event\Observer::class);
- $observerObject->expects($this->any())
- ->method('getData')
- ->with('configObj')
- ->will($this->returnValue($configObj));
- $productInstance=$this->createMock(\Magento\Catalog\Model\Product\Type\Simple::class);
- $product = $this->createPartialMock(
- \Magento\Bundle\Model\Product\Type::class,
- ['getTypeInstance', 'getTypeId', 'getStoreId']
- );
- $product->expects($this->any())
- ->method('getTypeInstance')
- ->will($this->returnValue($productInstance));
- $product->expects($this->any())
- ->method('getTypeId')
- ->will($this->returnValue('simple'));
- $product->expects($this->any())
- ->method('getStoreId')
- ->will($this->returnValue(null));
- $registry=$this->createMock(\Magento\Framework\Registry::class);
- $registry->expects($this->any())
- ->method('registry')
- ->with('current_product')
- ->will($this->returnValue($product));
- if ($hasWeeeAttributes) {
- $weeeHelper->expects($this->any())
- ->method('getWeeeAttributesForBundle')
- ->will($this->returnValue([
- 1 => ['fpt1' => $weeeObject1],
- 2 => [
- 'fpt1' => $weeeObject1,
- 'fpt2' => $weeeObject2
- ]
- ]));
- } else {
- $weeeHelper->expects($this->any())
- ->method('getWeeeAttributesForBundle')
- ->will($this->returnValue(null));
- }
- $objectManager = new ObjectManager($this);
- /** @var \Magento\Weee\Observer\GetPriceConfigurationObserver $weeeObserverObject */
- $weeeObserverObject = $objectManager->getObject(
- \Magento\Weee\Observer\GetPriceConfigurationObserver::class,
- [
- 'weeeData' => $weeeHelper,
- 'registry' => $registry,
- ]
- );
- $weeeObserverObject->execute($observerObject);
- $this->assertEquals($expectedArray, $configObj->getData('config'));
- }
- /**
- * @return array
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function getPriceConfigurationProvider()
- {
- return [
- "basic" => [
- 'hasWeeeAttributes' => true,
- 'testArray' => [
- [
- [
- 'optionId' => 1,
- 'prices' => [
- 'finalPrice' => ['amount' => 31.50],
- 'basePrice' => ['amount' => 33.50],
- ],
- ],
- [
- 'optionId' => 2,
- 'prices' => [
- 'finalPrice' =>['amount' => 331.50],
- 'basePrice' => ['amount' => 333.50],
- ],
- ],
- ],
- ],
- 'expectedArray' => [
- [
- [
- 'optionId' => 1,
- 'prices' => [
- 'finalPrice' => ['amount' => 31.50],
- 'basePrice' => ['amount' => 33.50],
- 'weeePrice' => ['amount' => 46.5],
- 'weeePricefpt1' => ['amount' => 15],
- ],
- ],
- [
- 'optionId' => 2,
- 'prices' => [
- 'finalPrice' =>['amount' => 331.50],
- 'basePrice' => ['amount' => 333.50],
- 'weeePrice' => ['amount' => 362.5],
- 'weeePricefpt1' => ['amount' => 15],
- 'weeePricefpt2' => ['amount' => 16],
- ],
- ],
- ],
- ],
- ],
- "layered, with extra keys" => [
- 'hasWeeeAttributes' => true,
- 'testArray' => [
- [
- [
- 'prices' => [
- 'finalPrice' => ['amount' => 31.50],
- ],
- 'somekey' => 0,
- ],
- [
- [
- [
- 'prices' => [
- 'finalPrice' =>['amount' => 321.50],
- ],
- ],
- 'otherkey' => [ 1, 2 , 3],
- ]
- ],
- ],
- ],
- 'expectedArray' => [
- [
- [
- 'prices' => [
- 'finalPrice' => ['amount' => 31.50],
- 'weeePrice' => ['amount' => 31.50],
- ],
- 'somekey' => 0,
- ],
- [
- [
- [
- 'prices' => [
- 'finalPrice' =>['amount' => 321.50],
- 'weeePrice' => ['amount' => 321.50],
- ],
- ],
- 'otherkey' => [ 1, 2 , 3],
- ]
- ],
- ],
- ],
- ],
- "no Weee attributes, expect WeeePrice to be same as FinalPrice" => [
- 'hasWeeeAttributes' => false,
- 'testArray' => [
- [
- [
- 'optionId' => 1,
- 'prices' => [
- 'basePrice' => ['amount' => 10],
- 'finalPrice' => ['amount' => 11],
- ],
- ],
- ],
- ],
- 'expectedArray' => [
- [
- [
- 'optionId' => 1,
- 'prices' => [
- 'basePrice' => ['amount' => 10],
- 'finalPrice' => ['amount' => 11],
- 'weeePrice' => ['amount' => 11],
- ],
- ],
- ],
- ],
- ],
- ];
- }
- }
|