forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[17] Read API :: Integration tests :: Customer* magento#55
- Loading branch information
Showing
6 changed files
with
293 additions
and
7 deletions.
There are no files selected for viewing
222 changes: 222 additions & 0 deletions
222
dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_disabled.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory; | ||
use Magento\Catalog\Api\Data\ProductExtensionInterfaceFactory; | ||
|
||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize(); | ||
|
||
/** @var \Magento\TestFramework\ObjectManager $objectManager */ | ||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
|
||
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */ | ||
$categoryLinkManagement = $objectManager->get(\Magento\Catalog\Api\CategoryLinkManagementInterface::class); | ||
|
||
$tierPrices = []; | ||
/** @var \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory */ | ||
$tierPriceFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory::class); | ||
/** @var $tpExtensionAttributes */ | ||
$tpExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class); | ||
/** @var $productExtensionAttributes */ | ||
$productExtensionAttributesFactory = $objectManager->get(ProductExtensionInterfaceFactory::class); | ||
|
||
$adminWebsite = $objectManager->get(\Magento\Store\Api\WebsiteRepositoryInterface::class)->get('admin'); | ||
$tierPriceExtensionAttributes1 = $tpExtensionAttributesFactory->create() | ||
->setWebsiteId($adminWebsite->getId()); | ||
$productExtensionAttributesWebsiteIds = $productExtensionAttributesFactory->create( | ||
['website_ids' => $adminWebsite->getId()] | ||
); | ||
|
||
$tierPrices[] = $tierPriceFactory->create( | ||
[ | ||
'data' => [ | ||
'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL, | ||
'qty' => 2, | ||
'value' => 8 | ||
] | ||
] | ||
)->setExtensionAttributes($tierPriceExtensionAttributes1); | ||
|
||
$tierPrices[] = $tierPriceFactory->create( | ||
[ | ||
'data' => [ | ||
'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL, | ||
'qty' => 5, | ||
'value' => 5 | ||
] | ||
] | ||
)->setExtensionAttributes($tierPriceExtensionAttributes1); | ||
|
||
$tierPrices[] = $tierPriceFactory->create( | ||
[ | ||
'data' => [ | ||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, | ||
'qty' => 3, | ||
'value' => 5 | ||
] | ||
] | ||
)->setExtensionAttributes($tierPriceExtensionAttributes1); | ||
|
||
$tierPrices[] = $tierPriceFactory->create( | ||
[ | ||
'data' => [ | ||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, | ||
'qty' => 3.2, | ||
'value' => 6, | ||
] | ||
] | ||
)->setExtensionAttributes($tierPriceExtensionAttributes1); | ||
|
||
$tierPriceExtensionAttributes2 = $tpExtensionAttributesFactory->create() | ||
->setWebsiteId($adminWebsite->getId()) | ||
->setPercentageValue(50); | ||
|
||
$tierPrices[] = $tierPriceFactory->create( | ||
[ | ||
'data' => [ | ||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, | ||
'qty' => 10 | ||
] | ||
] | ||
)->setExtensionAttributes($tierPriceExtensionAttributes2); | ||
|
||
/** @var $product \Magento\Catalog\Model\Product */ | ||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class); | ||
$product->isObjectNew(true); | ||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) | ||
->setId(1) | ||
->setAttributeSetId(4) | ||
->setWebsiteIds([1]) | ||
->setName('Simple Product') | ||
->setSku('simple') | ||
->setPrice(10) | ||
->setWeight(1) | ||
->setShortDescription("Short description") | ||
->setTaxClassId(0) | ||
->setTierPrices($tierPrices) | ||
->setDescription('Description with <b>html tag</b>') | ||
->setExtensionAttributes($productExtensionAttributesWebsiteIds) | ||
->setMetaTitle('meta title') | ||
->setMetaKeyword('meta keyword') | ||
->setMetaDescription('meta description') | ||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) | ||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED) | ||
->setStockData( | ||
[ | ||
'use_config_manage_stock' => 1, | ||
'qty' => 100, | ||
'is_qty_decimal' => 0, | ||
'is_in_stock' => 1, | ||
] | ||
)->setCanSaveCustomOptions(true) | ||
->setHasOptions(true); | ||
|
||
$oldOptions = [ | ||
[ | ||
'previous_group' => 'text', | ||
'title' => 'Test Field', | ||
'type' => 'field', | ||
'is_require' => 1, | ||
'sort_order' => 0, | ||
'price' => 1, | ||
'price_type' => 'fixed', | ||
'sku' => '1-text', | ||
'max_characters' => 100, | ||
], | ||
[ | ||
'previous_group' => 'date', | ||
'title' => 'Test Date and Time', | ||
'type' => 'date_time', | ||
'is_require' => 1, | ||
'sort_order' => 0, | ||
'price' => 2, | ||
'price_type' => 'fixed', | ||
'sku' => '2-date', | ||
], | ||
[ | ||
'previous_group' => 'select', | ||
'title' => 'Test Select', | ||
'type' => 'drop_down', | ||
'is_require' => 1, | ||
'sort_order' => 0, | ||
'values' => [ | ||
[ | ||
'option_type_id' => null, | ||
'title' => 'Option 1', | ||
'price' => 3, | ||
'price_type' => 'fixed', | ||
'sku' => '3-1-select', | ||
], | ||
[ | ||
'option_type_id' => null, | ||
'title' => 'Option 2', | ||
'price' => 3, | ||
'price_type' => 'fixed', | ||
'sku' => '3-2-select', | ||
], | ||
] | ||
], | ||
[ | ||
'previous_group' => 'select', | ||
'title' => 'Test Radio', | ||
'type' => 'radio', | ||
'is_require' => 1, | ||
'sort_order' => 0, | ||
'values' => [ | ||
[ | ||
'option_type_id' => null, | ||
'title' => 'Option 1', | ||
'price' => 3, | ||
'price_type' => 'fixed', | ||
'sku' => '4-1-radio', | ||
], | ||
[ | ||
'option_type_id' => null, | ||
'title' => 'Option 2', | ||
'price' => 3, | ||
'price_type' => 'fixed', | ||
'sku' => '4-2-radio', | ||
], | ||
] | ||
] | ||
]; | ||
|
||
$options = []; | ||
|
||
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory */ | ||
$customOptionFactory = $objectManager->create(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class); | ||
|
||
foreach ($oldOptions as $option) { | ||
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterface $option */ | ||
$option = $customOptionFactory->create(['data' => $option]); | ||
$option->setProductSku($product->getSku()); | ||
|
||
$options[] = $option; | ||
} | ||
|
||
$product->setOptions($options); | ||
|
||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ | ||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); | ||
$productRepository->save($product); | ||
|
||
$categoryLinkManagement->assignProductToCategories( | ||
$product->getSku(), | ||
[2] | ||
); | ||
|
||
/** | ||
* We need to remember that automatic reindexation is not working properly in integration tests | ||
* Reindexation is sitting on top of afterCommit callbacks: | ||
* \Magento\Catalog\Model\Product::priceReindexCallback | ||
* | ||
* However, callbacks are applied only when transaction_level = 0 (when transaction is commited), however | ||
* integration tests are not committing transactions, so we need to reindex data manually in order to reuse it in tests | ||
*/ | ||
/** @var \Magento\Indexer\Model\Indexer $indexer */ | ||
$indexer = $objectManager->create(\Magento\Indexer\Model\Indexer::class); | ||
$indexer->load('catalog_product_price'); | ||
$indexer->reindexRow($product->getId()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...s/integration/testsuite/Magento/Wishlist/_files/wishlist_with_disabled_simple_product.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Customer\Model\CustomerRegistry; | ||
use Magento\Framework\DataObject; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver; | ||
use Magento\Wishlist\Model\Wishlist; | ||
|
||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php'); | ||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_disabled.php'); | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var CustomerRegistry $customerRegistry */ | ||
$customerRegistry = Bootstrap::getObjectManager()->create(CustomerRegistry::class); | ||
$customer = $customerRegistry->retrieve(1); | ||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = $objectManager->create(ProductRepositoryInterface::class); | ||
$product = $productRepository->get('simple'); | ||
$wishlist = Bootstrap::getObjectManager()->create(Wishlist::class); | ||
$wishlist->loadByCustomerId($customer->getId(), true); | ||
$item = $wishlist->addNewItem($product, new DataObject([])); | ||
$wishlist->setSharingCode('fixture_unique_code')->save(); |