|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Bundle\Test\Unit\Model\ResourceModel; |
| 7 | + |
| 8 | +use Codeception\PHPUnit\TestCase; |
| 9 | +use Magento\Bundle\Model\ResourceModel\Selection as ResourceSelection; |
| 10 | +use Magento\Bundle\Model\Selection; |
| 11 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 12 | + |
| 13 | +/** |
| 14 | + * Class to test Selection Resource Model |
| 15 | + */ |
| 16 | +class SelectionTest extends TestCase |
| 17 | +{ |
| 18 | + public function testSaveSelectionPrice() |
| 19 | + { |
| 20 | + $item = $this->getMockBuilder(Selection::class) |
| 21 | + ->disableOriginalConstructor() |
| 22 | + ->addMethods(['getSelectionId', 'getWebsiteId', 'getSelectionPriceType', 'getSelectionPriceValue', 'getParentProductId', 'getDefaultPriceScope']) |
| 23 | + ->getMock(); |
| 24 | + $values = [ |
| 25 | + 'selection_id' => 1, |
| 26 | + 'website_id' => 1, |
| 27 | + 'selection_price_type' => null, |
| 28 | + 'selection_price_value' => null, |
| 29 | + 'parent_product_id' => 1, |
| 30 | + ]; |
| 31 | + $item->expects($this->once())->method('getDefaultPriceScope')->willReturn(false); |
| 32 | + $item->expects($this->once())->method('getSelectionId')->willReturn($values['selection_id']); |
| 33 | + $item->expects($this->once())->method('getWebsiteId')->willReturn($values['website_id']); |
| 34 | + $item->expects($this->once())->method('getSelectionPriceType')->willReturn($values['selection_price_type']); |
| 35 | + $item->expects($this->once())->method('getSelectionPriceValue')->willReturn($values['selection_price_value']); |
| 36 | + $item->expects($this->once())->method('getParentProductId')->willReturn($values['parent_product_id']); |
| 37 | + |
| 38 | + $selection = $this->getMockBuilder(ResourceSelection::class) |
| 39 | + ->disableOriginalConstructor() |
| 40 | + ->onlyMethods(['getConnection', 'getTable']) |
| 41 | + ->getMock(); |
| 42 | + $selection->expects($this->any()) |
| 43 | + ->method('getTable') |
| 44 | + ->with('catalog_product_bundle_selection_price') |
| 45 | + ->willReturn('catalog_product_bundle_selection_price'); |
| 46 | + |
| 47 | + $connection = $this->createMock(AdapterInterface::class); |
| 48 | + $connection->expects($this->once()) |
| 49 | + ->method('insertOnDuplicate') |
| 50 | + ->with( |
| 51 | + $selection->getTable('catalog_product_bundle_selection_price'), |
| 52 | + $this->callback(function ($insertValues) { |
| 53 | + return $insertValues['selection_price_type'] === 0 && $insertValues['selection_price_value'] === 0; |
| 54 | + }), |
| 55 | + ['selection_price_type', 'selection_price_value'] |
| 56 | + ); |
| 57 | + |
| 58 | + $selection->expects($this->once())->method('getConnection')->willReturn($connection); |
| 59 | + $selection->saveSelectionPrice($item); |
| 60 | + } |
| 61 | +} |
0 commit comments