Skip to content

Commit 93f6264

Browse files
author
olysenko
committed
MAGETWO-64547: Bundle Products - The options you selected are not available.
1 parent 32058a0 commit 93f6264

File tree

2 files changed

+327
-0
lines changed

2 files changed

+327
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\BundleImportExport\Test\Unit\Model\Import\Product\Type\Bundle;
8+
9+
use Magento\BundleImportExport\Model\Import\Product\Type\Bundle\RelationsDataSaver;
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
13+
/**
14+
* Class RelationsDataSaverTest
15+
*/
16+
class RelationsDataSaverTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var RelationsDataSaver
20+
*/
21+
private $relationsDataSaver;
22+
23+
/**
24+
* @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $resourceMock;
27+
28+
/**
29+
* @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $connectionMock;
32+
33+
protected function setUp()
34+
{
35+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36+
$this->resourceMock = $this->getMockBuilder(ResourceConnection::class)
37+
->disableOriginalConstructor()
38+
->getMock();
39+
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$this->resourceMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
43+
44+
$this->relationsDataSaver = $helper->getObject(
45+
RelationsDataSaver::class,
46+
[
47+
'resource' => $this->resourceMock
48+
]
49+
);
50+
}
51+
52+
public function testSaveOptions()
53+
{
54+
$options = [1, 2];
55+
$table_name= 'catalog_product_bundle_option';
56+
57+
$this->resourceMock->expects($this->once())
58+
->method('getTableName')
59+
->with('catalog_product_bundle_option')
60+
->willReturn($table_name);
61+
$this->connectionMock->expects($this->once())
62+
->method('insertOnDuplicate')
63+
->with(
64+
$table_name,
65+
$options,
66+
[
67+
'required',
68+
'position',
69+
'type'
70+
]
71+
);
72+
73+
$this->relationsDataSaver->saveOptions($options);
74+
}
75+
76+
public function testSaveOptionValues()
77+
{
78+
$optionsValues = [1, 2];
79+
$table_name= 'catalog_product_bundle_option_value';
80+
81+
$this->resourceMock->expects($this->once())
82+
->method('getTableName')
83+
->with('catalog_product_bundle_option_value')
84+
->willReturn($table_name);
85+
$this->connectionMock->expects($this->once())
86+
->method('insertOnDuplicate')
87+
->with(
88+
$table_name,
89+
$optionsValues,
90+
['title']
91+
);
92+
93+
$this->relationsDataSaver->saveOptionValues($optionsValues);
94+
}
95+
96+
public function testSaveSelections()
97+
{
98+
$selections = [1, 2];
99+
$table_name= 'catalog_product_bundle_selection';
100+
101+
$this->resourceMock->expects($this->once())
102+
->method('getTableName')
103+
->with('catalog_product_bundle_selection')
104+
->willReturn($table_name);
105+
$this->connectionMock->expects($this->once())
106+
->method('insertOnDuplicate')
107+
->with(
108+
$table_name,
109+
$selections,
110+
[
111+
'selection_id',
112+
'product_id',
113+
'position',
114+
'is_default',
115+
'selection_price_type',
116+
'selection_price_value',
117+
'selection_qty',
118+
'selection_can_change_qty'
119+
]
120+
);
121+
122+
$this->relationsDataSaver->saveSelections($selections);
123+
}
124+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\EntityManager\Test\Unit\Sequence;
7+
8+
use Magento\Framework\EntityManager\HydratorPool;
9+
use Magento\Framework\EntityManager\MetadataPool;
10+
use Magento\Framework\EntityManager\Sequence\SequenceApplier;
11+
use Magento\Framework\EntityManager\Sequence\SequenceManager;
12+
use Magento\Framework\EntityManager\Sequence\SequenceRegistry;
13+
use Magento\Framework\EntityManager\TypeResolver;
14+
use Magento\Framework\DataObject;
15+
use Magento\Framework\EntityManager\HydratorInterface;
16+
use Magento\Framework\EntityManager\EntityMetadataInterface;
17+
use Magento\Framework\DB\Sequence\SequenceInterface;
18+
19+
class SequenceApplierTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $metadataPoolMock;
25+
26+
/**
27+
* @var TypeResolver|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $typeResolverMock;
30+
31+
/**
32+
* @var SequenceManager|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $sequenceManagerMock;
35+
36+
/**
37+
* @var SequenceRegistry|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $sequenceRegistryMock;
40+
41+
/**
42+
* @var HydratorPool|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $hydratorPoolMock;
45+
46+
/**
47+
* @var DataObject|\PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
private $entityMock;
50+
51+
/**
52+
* @var HydratorInterface|\PHPUnit_Framework_MockObject_MockObject
53+
*/
54+
private $hydratorMock;
55+
56+
/**
57+
* @var EntityMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
58+
*/
59+
private $metadataMock;
60+
61+
/**
62+
* @var SequenceInterface|\PHPUnit_Framework_MockObject_MockObject
63+
*/
64+
private $sequenceMock;
65+
66+
/**
67+
* @var SequenceApplier
68+
*/
69+
private $sequenceApplier;
70+
71+
public function setUp()
72+
{
73+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
74+
75+
$this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)
76+
->disableOriginalConstructor()
77+
->getMock();
78+
$this->typeResolverMock = $this->getMockBuilder(TypeResolver::class)
79+
->disableOriginalConstructor()
80+
->getMock();
81+
$this->sequenceManagerMock = $this->getMockBuilder(SequenceManager::class)
82+
->disableOriginalConstructor()
83+
->getMock();
84+
$this->sequenceRegistryMock = $this->getMockBuilder(SequenceRegistry::class)
85+
->disableOriginalConstructor()
86+
->getMock();
87+
$this->hydratorPoolMock = $this->getMockBuilder(HydratorPool::class)
88+
->disableOriginalConstructor()
89+
->getMock();
90+
$this->entityMock = $this->getMockBuilder(DataObject::class)
91+
->disableOriginalConstructor()
92+
->getMock();
93+
$this->hydratorMock = $this->getMockBuilder(HydratorInterface::class)
94+
->disableOriginalConstructor()
95+
->getMock();
96+
$this->metadataMock = $this->getMockBuilder(EntityMetadataInterface::class)
97+
->disableOriginalConstructor()
98+
->getMock();
99+
$this->sequenceMock = $this->getMockBuilder(SequenceInterface::class)
100+
->disableOriginalConstructor()
101+
->getMock();
102+
103+
$this->sequenceApplier = $helper->getObject(
104+
SequenceApplier::class,
105+
[
106+
'metadataPool' => $this->metadataPoolMock,
107+
'typeResolver' => $this->typeResolverMock,
108+
'sequenceManager' => $this->sequenceManagerMock,
109+
'sequenceRegistry' => $this->sequenceRegistryMock,
110+
'hydratorPool' => $this->hydratorPoolMock
111+
]
112+
);
113+
}
114+
115+
public function testApplySequenceIsNull()
116+
{
117+
$entityType = 'entity_type';
118+
$this->typeResolverMock->expects($this->once())
119+
->method('resolve')
120+
->with($this->entityMock)
121+
->willReturn($entityType);
122+
$this->sequenceRegistryMock->expects($this->once())->method('retrieve')->with($entityType)->willReturn(null);
123+
$this->assertEquals($this->entityMock, $this->sequenceApplier->apply($this->entityMock));
124+
}
125+
126+
public function testApplyEntityHasIdentifier()
127+
{
128+
$entityType = 'entity_type';
129+
$identifierField = 'identifier_field';
130+
$entityData = [$identifierField => 'data'];
131+
$sequenceInfo = ['sequence' => $this->sequenceMock];
132+
$this->typeResolverMock->expects($this->once())
133+
->method('resolve')
134+
->with($this->entityMock)
135+
->willReturn($entityType);
136+
$this->sequenceRegistryMock->expects($this->once())
137+
->method('retrieve')
138+
->with($entityType)
139+
->willReturn($sequenceInfo);
140+
$this->metadataPoolMock->expects($this->any())
141+
->method('getMetadata')
142+
->with($entityType)
143+
->willReturn($this->metadataMock);
144+
$this->hydratorPoolMock->expects($this->once())
145+
->method('getHydrator')
146+
->with($entityType)
147+
->willReturn($this->hydratorMock);
148+
$this->hydratorMock->expects($this->once())
149+
->method('extract')
150+
->with($this->entityMock)
151+
->willReturn($entityData);
152+
$this->metadataMock->expects($this->any())->method('getIdentifierField')->willReturn($identifierField);
153+
$this->sequenceManagerMock->expects($this->once())
154+
->method('force')
155+
->with(
156+
$entityType,
157+
$entityData[$identifierField]
158+
);
159+
160+
$this->assertEquals($this->entityMock, $this->sequenceApplier->apply($this->entityMock));
161+
}
162+
163+
public function testApplyEntityDoesNotHaveIdentifier()
164+
{
165+
$entityType = 'entity_type';
166+
$identifierField = 'identifier_field';
167+
$identifierFieldEmptyValue = '';
168+
$entityData = [$identifierField => $identifierFieldEmptyValue];
169+
$sequenceInfo = ['sequence' => $this->sequenceMock];
170+
$this->typeResolverMock->expects($this->once())
171+
->method('resolve')
172+
->with($this->entityMock)
173+
->willReturn($entityType);
174+
$this->sequenceRegistryMock->expects($this->once())
175+
->method('retrieve')
176+
->with($entityType)
177+
->willReturn($sequenceInfo);
178+
$this->metadataPoolMock->expects($this->any())
179+
->method('getMetadata')
180+
->with($entityType)
181+
->willReturn($this->metadataMock);
182+
$this->hydratorPoolMock->expects($this->once())
183+
->method('getHydrator')
184+
->with($entityType)
185+
->willReturn($this->hydratorMock);
186+
$this->hydratorMock->expects($this->once())
187+
->method('extract')
188+
->with($this->entityMock)
189+
->willReturn($entityData);
190+
$this->metadataMock->expects($this->any())
191+
->method('getIdentifierField')
192+
->willReturn($identifierFieldEmptyValue);
193+
$nextValue = 'next_value_data';
194+
$this->sequenceMock->expects($this->once())->method('getNextValue')->willReturn($nextValue);
195+
$entityData[''] = $nextValue;
196+
$this->hydratorMock->expects($this->once())
197+
->method('hydrate')
198+
->with($this->entityMock, $entityData)
199+
->willReturn($this->entityMock);
200+
201+
$this->assertEquals($this->entityMock, $this->sequenceApplier->apply($this->entityMock));
202+
}
203+
}

0 commit comments

Comments
 (0)