|
| 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\Ui\DataProvider\Product\Form\Modifier; |
| 9 | + |
| 10 | +use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePrice; |
| 11 | +use Magento\Catalog\Api\Data\ProductAttributeInterface; |
| 12 | +use Magento\Framework\Stdlib\ArrayManager; |
| 13 | + |
| 14 | +class BundlePriceTest extends AbstractModifierTest |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @return BundlePrice |
| 18 | + */ |
| 19 | + protected function createModel() |
| 20 | + { |
| 21 | + return $this->objectManager->getObject( |
| 22 | + BundlePrice::class, |
| 23 | + [ |
| 24 | + 'locator' => $this->locatorMock, |
| 25 | + 'arrayManager' => $this->arrayManagerMock |
| 26 | + ] |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 32 | + */ |
| 33 | + public function testModifyMeta() |
| 34 | + { |
| 35 | + $this->productMock->expects($this->any()) |
| 36 | + ->method('getId') |
| 37 | + ->willReturn(true); |
| 38 | + $this->productMock->expects($this->any()) |
| 39 | + ->method('getPriceType') |
| 40 | + ->willReturn(0); |
| 41 | + $priceTypePath = 'bundle-items/children/' . BundlePrice::CODE_PRICE_TYPE; |
| 42 | + $priceTypeConfigPath = $priceTypePath . BundlePrice::META_CONFIG_PATH; |
| 43 | + $pricePath = 'product-details/children/' . ProductAttributeInterface::CODE_PRICE; |
| 44 | + $priceConfigPath = $pricePath . BundlePrice::META_CONFIG_PATH; |
| 45 | + $sourceMeta = [ |
| 46 | + 'bundle-items' => [ |
| 47 | + 'children' => [ |
| 48 | + BundlePrice::CODE_PRICE_TYPE => [] |
| 49 | + ] |
| 50 | + ] |
| 51 | + ]; |
| 52 | + $priceTypeParams = [ |
| 53 | + 'disabled' => true, |
| 54 | + 'valueMap' => [ |
| 55 | + 'false' => '1', |
| 56 | + 'true' => '0' |
| 57 | + ], |
| 58 | + 'validation' => [ |
| 59 | + 'required-entry' => false |
| 60 | + ] |
| 61 | + ]; |
| 62 | + $priceTypeMeta = [ |
| 63 | + 'bundle-items' => [ |
| 64 | + 'children' => [ |
| 65 | + BundlePrice::CODE_PRICE_TYPE => $priceTypeParams |
| 66 | + ] |
| 67 | + ] |
| 68 | + ]; |
| 69 | + $priceParams = [ |
| 70 | + 'imports' => [ |
| 71 | + 'disabled' => 'ns = ${ $.ns }, index = ' . BundlePrice::CODE_PRICE_TYPE . ':checked' |
| 72 | + ] |
| 73 | + ]; |
| 74 | + $priceMeta = [ |
| 75 | + 'product-details' => [ |
| 76 | + 'children' => [ |
| 77 | + BundlePrice::CODE_PRICE_TYPE => [] |
| 78 | + ] |
| 79 | + ], |
| 80 | + 'bundle-items' => [ |
| 81 | + 'children' => [ |
| 82 | + ProductAttributeInterface::CODE_PRICE => $priceParams |
| 83 | + ] |
| 84 | + ] |
| 85 | + ]; |
| 86 | + $taxParams = [ |
| 87 | + 'service' => [ |
| 88 | + 'template' => '' |
| 89 | + ] |
| 90 | + ]; |
| 91 | + |
| 92 | + $this->arrayManagerMock->expects($this->any()) |
| 93 | + ->method('findPath') |
| 94 | + ->willReturnMap( |
| 95 | + [ |
| 96 | + [ |
| 97 | + BundlePrice::CODE_PRICE_TYPE, |
| 98 | + $sourceMeta, |
| 99 | + null, |
| 100 | + 'children', |
| 101 | + ArrayManager::DEFAULT_PATH_DELIMITER, |
| 102 | + $priceTypePath |
| 103 | + ], |
| 104 | + [ |
| 105 | + ProductAttributeInterface::CODE_PRICE, |
| 106 | + $priceTypeMeta, |
| 107 | + BundlePrice::DEFAULT_GENERAL_PANEL . '/children', |
| 108 | + 'children', |
| 109 | + ArrayManager::DEFAULT_PATH_DELIMITER, |
| 110 | + $pricePath |
| 111 | + ], |
| 112 | + [ |
| 113 | + BundlePrice::CODE_TAX_CLASS_ID, |
| 114 | + $priceMeta, |
| 115 | + null, |
| 116 | + 'children', |
| 117 | + ArrayManager::DEFAULT_PATH_DELIMITER, |
| 118 | + $pricePath |
| 119 | + ], |
| 120 | + [ |
| 121 | + BundlePrice::CODE_TAX_CLASS_ID, |
| 122 | + $priceMeta, |
| 123 | + null, |
| 124 | + 'children', |
| 125 | + ArrayManager::DEFAULT_PATH_DELIMITER, |
| 126 | + $pricePath |
| 127 | + ] |
| 128 | + ] |
| 129 | + ); |
| 130 | + $this->arrayManagerMock->expects($this->exactly(4)) |
| 131 | + ->method('merge') |
| 132 | + ->willReturnMap( |
| 133 | + [ |
| 134 | + [ |
| 135 | + $priceTypeConfigPath, |
| 136 | + $sourceMeta, |
| 137 | + $priceTypeParams, |
| 138 | + ArrayManager::DEFAULT_PATH_DELIMITER, |
| 139 | + $priceTypeMeta |
| 140 | + ], |
| 141 | + [ |
| 142 | + $priceConfigPath, |
| 143 | + $priceTypeMeta, |
| 144 | + $priceParams, |
| 145 | + ArrayManager::DEFAULT_PATH_DELIMITER, |
| 146 | + $priceMeta |
| 147 | + ], |
| 148 | + [ |
| 149 | + $priceConfigPath, |
| 150 | + $priceMeta, |
| 151 | + $priceParams, |
| 152 | + ArrayManager::DEFAULT_PATH_DELIMITER, |
| 153 | + $priceMeta |
| 154 | + ], |
| 155 | + [ |
| 156 | + $priceConfigPath, |
| 157 | + $priceMeta, |
| 158 | + $taxParams, |
| 159 | + ArrayManager::DEFAULT_PATH_DELIMITER, |
| 160 | + $priceMeta |
| 161 | + ] |
| 162 | + ] |
| 163 | + ); |
| 164 | + |
| 165 | + $this->assertSame($priceMeta, $this->getModel()->modifyMeta($sourceMeta)); |
| 166 | + } |
| 167 | + |
| 168 | + public function testModifyData() |
| 169 | + { |
| 170 | + $expectedData = []; |
| 171 | + $this->assertEquals($expectedData, $this->getModel()->modifyData($expectedData)); |
| 172 | + } |
| 173 | +} |
0 commit comments