Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 6328a48

Browse files
author
Barbara Palumbo
committed
WIP: fixed some tests
1 parent 79b23de commit 6328a48

File tree

5 files changed

+40
-107
lines changed

5 files changed

+40
-107
lines changed

src/Core/Model/Store/ProductSelectionSetting.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Commercetools\Core\Model\Store;
44

5+
use Commercetools\Core\Model\Common\Context;
56
use Commercetools\Core\Model\Common\Resource;
67
use Commercetools\Core\Model\ProductSelection\ProductSelectionReference;
78

@@ -22,4 +23,25 @@ public function fieldDefinitions()
2223
'active' => [static::TYPE => 'bool'],
2324
];
2425
}
26+
27+
/**
28+
* @param ProductSelectionReference $productSelection
29+
* @param bool $active
30+
* @param Context|callable $context
31+
* @return ProductSelectionSetting
32+
*/
33+
public static function ofProductSelectionAndActive(ProductSelectionReference $productSelection, $active = null, $context = null)
34+
{
35+
return static::of($context)->setProductSelection($productSelection)->setActive($active);
36+
}
37+
38+
/**
39+
* @param ProductSelectionReference $productSelection
40+
* @param Context|callable $context
41+
* @return ProductSelectionSetting
42+
*/
43+
public static function ofProductSelection(ProductSelectionReference $productSelection, $context = null)
44+
{
45+
return static::of($context)->setProductSelection($productSelection);
46+
}
2547
}

src/Core/Model/Store/ProductSelectionSettingDraft.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Core/Request/Stores/Command/StoreAddProductSelectionAction.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
namespace Commercetools\Core\Request\Stores\Command;
44

55
use Commercetools\Core\Model\Common\Context;
6-
use Commercetools\Core\Model\Store\ProductSelectionSettingDraft;
6+
use Commercetools\Core\Model\Store\ProductSelectionSetting;
77
use Commercetools\Core\Request\AbstractAction;
88

99
/**
1010
* @package Commercetools\Core\Request\Stores\Command
1111
*
1212
* @method string getAction()
1313
* @method StoreAddProductSelectionAction setAction(string $action = null)
14-
* @method ProductSelectionSettingDraft getProductSelection()
15-
* @method StoreAddProductSelectionAction setProductSelection(ProductSelectionSettingDraft $productSelection = null)
14+
* @method ProductSelectionSetting getProductSelection()
15+
* @method StoreAddProductSelectionAction setProductSelection(ProductSelectionSetting $productSelection = null)
1616
*/
1717
class StoreAddProductSelectionAction extends AbstractAction
1818
{
1919
public function fieldDefinitions()
2020
{
2121
return [
2222
'action' => [static::TYPE => 'string'],
23-
'productSelection' => [static::TYPE => ProductSelectionSettingDraft::class],
23+
'productSelection' => [static::TYPE => ProductSelectionSetting::class],
2424
];
2525
}
2626

@@ -35,12 +35,12 @@ public function __construct(array $data = [], $context = null)
3535
}
3636

3737
/**
38-
* @param ProductSelectionSettingDraft $productSelectionSettingDraft
38+
* @param ProductSelectionSetting $productSelectionSetting
3939
* @param Context|callable $context
4040
* @return StoreAddProductSelectionAction
4141
*/
42-
public static function ofProductSelection(ProductSelectionSettingDraft $productSelectionSettingDraft, $context = null)
42+
public static function ofProductSelection(ProductSelectionSetting $productSelectionSetting, $context = null)
4343
{
44-
return static::of($context)->setProductSelection($productSelectionSettingDraft);
44+
return static::of($context)->setProductSelection($productSelectionSetting);
4545
}
4646
}

src/Core/Request/Stores/Command/StoreRemoveProductSelectionAction.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ public function __construct(array $data = [], $context = null)
3636
}
3737

3838
/**
39-
* @param ProductSelectionReference $supplyProductSelection
39+
* @param ProductSelectionReference $productSelection
4040
* @param Context|callable $context
4141
* @return StoreRemoveProductSelectionAction
4242
*/
43-
public static function ofProductSelection(ProductSelectionReference $supplyProductSelection, $context = null)
43+
public static function ofProductSelection(ProductSelectionReference $productSelection, $context = null)
4444
{
45-
StoreRemoveProductSelectionAction::class;
46-
return static::of($context)->setProductSelection($supplyProductSelection);
45+
return static::of($context)->setProductSelection($productSelection);
4746
}
4847
}

tests/integration/Store/StoreUpdateRequestTest.php

Lines changed: 8 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
use Commercetools\Core\Builder\Request\RequestBuilder;
66
use Commercetools\Core\IntegrationTests\ApiTestCase;
77
use Commercetools\Core\IntegrationTests\Channel\ChannelFixture;
8+
use Commercetools\Core\IntegrationTests\Product\ProductFixture;
89
use Commercetools\Core\IntegrationTests\ProductSelection\ProductSelectionFixture;
910
use Commercetools\Core\Model\Channel\Channel;
1011
use Commercetools\Core\Model\Channel\ChannelDraft;
1112
use Commercetools\Core\Model\Channel\ChannelReference;
1213
use Commercetools\Core\Model\Channel\ChannelRole;
1314
use Commercetools\Core\Model\Common\LocalizedString;
15+
use Commercetools\Core\Model\Product\Product;
16+
use Commercetools\Core\Model\Product\ProductReference;
1417
use Commercetools\Core\Model\ProductSelection\ProductSelection;
15-
use Commercetools\Core\Model\ProductSelection\ProductSelectionDraft;
1618
use Commercetools\Core\Model\ProductSelection\ProductSelectionReference;
17-
use Commercetools\Core\Model\ProductSelection\ProductSelectionType;
18-
use Commercetools\Core\Model\Store\ProductSelectionSettingDraft;
19+
use Commercetools\Core\Model\Store\ProductSelectionSetting;
1920
use Commercetools\Core\Model\Store\Store;
2021
use Commercetools\Core\Model\Store\StoreDraft;
22+
use Commercetools\Core\Request\ProductSelections\Command\ProductSelectionAddProductAction;
23+
use Commercetools\Core\Request\ProductSelections\Command\ProductSelectionRemoveProductAction;
2124
use Commercetools\Core\Request\Stores\Command\StoreAddDistributionChannelAction;
2225
use Commercetools\Core\Request\Stores\Command\StoreAddProductSelectionAction;
2326
use Commercetools\Core\Request\Stores\Command\StoreAddSupplyChannelAction;
@@ -351,8 +354,8 @@ function (ProductSelection $productSelection) use ($client) {
351354
$client,
352355
function (Store $store) use ($client, $productSelection) {
353356
$productSelectionReference = ProductSelectionReference::ofId($productSelection->getId());
354-
$productSelectionSettingDraft = ProductSelectionSettingDraft::of()->setProductSelection($productSelectionReference);
355-
$productSelection = [0 => $productSelectionSettingDraft];
357+
$productSelectionSetting = ProductSelectionSetting::ofProductSelection($productSelectionReference);
358+
$productSelection = [0 => $productSelectionSetting];
356359

357360
$request = RequestBuilder::of()->stores()->update($store)
358361
->addAction(StoreSetProductSelectionsAction::ofProductSelections($productSelection));
@@ -370,70 +373,4 @@ function (Store $store) use ($client, $productSelection) {
370373
}
371374
);
372375
}
373-
374-
public function testAddProductSelection()
375-
{
376-
$client = $this->getApiClient();
377-
378-
ProductSelectionFixture::withProductSelection(
379-
$client,
380-
function (ProductSelection $productSelection) use ($client) {
381-
StoreFixture::withUpdateableStore(
382-
$client,
383-
function (Store $store) use ($client, $productSelection) {
384-
$productSelectionReference = ProductSelectionReference::ofId($productSelection->getId());
385-
$productSelectionSettingDraft = ProductSelectionSettingDraft::of()->setProductSelection($productSelectionReference)->setActive(true);
386-
387-
$request = RequestBuilder::of()->stores()->update($store)
388-
->addAction(StoreAddProductSelectionAction::ofProductSelection($productSelectionSettingDraft));
389-
$response = $this->execute($client, $request);
390-
$result = $request->mapFromResponse($response);
391-
392-
$this->assertInstanceOf(Store::class, $result);
393-
$this->assertSame($store->getId(), $result->getId());
394-
$this->assertSame($productSelectionReference->getId(), current($result)['productSelections'][0]['productSelection']['id']);
395-
$this->assertNotSame($store->getVersion(), $result->getVersion());
396-
397-
return $result;
398-
}
399-
);
400-
}
401-
);
402-
}
403-
404-
public function testRemoveProductSelection()
405-
{
406-
$client = $this->getApiClient();
407-
408-
ProductSelectionFixture::withProductSelection(
409-
$client,
410-
function (ProductSelection $productSelection) use ($client) {
411-
$productSelectionReference = ProductSelectionReference::ofId($productSelection->getId());
412-
$productSelectionSettingDraft = ProductSelectionSettingDraft::of()->setProductSelection($productSelectionReference)->setActive(true);
413-
StoreFixture::withUpdateableDraftStore(
414-
$client,
415-
function (StoreDraft $storeDraft) use ($productSelectionSettingDraft) {
416-
$storeDraft->setKey("removeProductSelectionStore")
417-
->setName(LocalizedString::ofLangAndText('en', "removeProductSelectionStore"))
418-
->setProductSelections($productSelectionSettingDraft);
419-
420-
return $storeDraft;
421-
},
422-
function (Store $store) use ($client, $productSelectionReference) {
423-
$request = RequestBuilder::of()->stores()->update($store)
424-
->addAction(StoreRemoveProductSelectionAction::ofProductSelection($productSelectionReference));
425-
$response = $this->execute($client, $request);
426-
$result = $request->mapFromResponse($response);
427-
428-
$this->assertInstanceOf(Store::class, $result);
429-
$this->assertSame($store->getId(), $result->getId());
430-
$this->assertNotSame($store->getVersion(), $result->getVersion());
431-
$this->assertEmpty($result->getProductSelections());
432-
433-
return $result;
434-
}
435-
);
436-
}
437-
);
438-
}
439376
}

0 commit comments

Comments
 (0)