Skip to content

Commit 27f2363

Browse files
authored
Merge pull request #5586 from magento-tsg/2.3-develop-com-pr19
[TSG-Commerce] Tests for 2.3 (pr19)
2 parents 12ac8a1 + 1320b95 commit 27f2363

29 files changed

+2164
-87
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\TestFramework\Customer\Model;
9+
10+
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\Registry;
13+
14+
/**
15+
* Delete customer by email or id
16+
*/
17+
class DeleteCustomer
18+
{
19+
/** @var CustomerRepositoryInterface */
20+
private $customerRepository;
21+
22+
/** @var Registry */
23+
private $registry;
24+
25+
/**
26+
* @param CustomerRepositoryInterface $customerRepository
27+
* @param Registry $registry
28+
*/
29+
public function __construct(CustomerRepositoryInterface $customerRepository, Registry $registry)
30+
{
31+
$this->customerRepository = $customerRepository;
32+
$this->registry = $registry;
33+
}
34+
35+
/**
36+
* Delete customer by id or email
37+
*
38+
* @param int|string $id
39+
* @return void
40+
*/
41+
public function execute($id): void
42+
{
43+
$isSecure = $this->registry->registry('isSecureArea');
44+
45+
$this->registry->unregister('isSecureArea');
46+
$this->registry->register('isSecureArea', true);
47+
48+
try {
49+
$customer = is_numeric($id) ? $this->customerRepository->getById($id) : $this->customerRepository->get($id);
50+
$this->customerRepository->delete($customer);
51+
} catch (NoSuchEntityException $e) {
52+
//customer already deleted
53+
}
54+
55+
$this->registry->unregister('isSecureArea');
56+
$this->registry->register('isSecureArea', $isSecure);
57+
}
58+
}

dev/tests/integration/testsuite/Magento/Catalog/_files/products_for_search.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1212
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\Catalog\Api\ProductRepositoryInterface;
15+
16+
$objectManager = Bootstrap::getObjectManager();
17+
/** @var ProductRepositoryInterface $productRepository */
18+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
1319

1420
$products = [
1521
[
@@ -90,14 +96,13 @@
9096
];
9197

9298
/** @var CategoryLinkManagementInterface $categoryLinkManagement */
93-
$categoryLinkManagement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
94-
->create(CategoryLinkManagementInterface::class);
99+
$categoryLinkManagement = $objectManager->create(CategoryLinkManagementInterface::class);
95100

96101
$categoriesToAssign = [];
97102

98103
foreach ($products as $data) {
99104
/** @var $product Product */
100-
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(Product::class);
105+
$product = $objectManager->create(Product::class);
101106
$product
102107
->setTypeId($data['type'])
103108
->setId($data['id'])
@@ -111,8 +116,8 @@
111116
->setMetaDescription($data['meta_keyword'])
112117
->setVisibility($data['visibility'])
113118
->setStatus($data['status'])
114-
->setStockData(['use_config_manage_stock' => 0])
115-
->save();
119+
->setStockData(['use_config_manage_stock' => 0]);
120+
$productRepository->save($product);
116121

117122
$categoriesToAssign[$data['sku']][] = $data['category_id'];
118123
}

dev/tests/integration/testsuite/Magento/Catalog/_files/products_for_search_rollback.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
use Magento\TestFramework\Helper\Bootstrap;
1111

1212
Bootstrap::getInstance()->getInstance()->reinitialize();
13+
$objectManager = Bootstrap::getObjectManager();
1314

1415
/** @var Registry $registry */
15-
$registry = Bootstrap::getObjectManager()->get(Registry::class);
16+
$registry = $objectManager->get(Registry::class);
1617

1718
$registry->unregister('isSecureArea');
1819
$registry->register('isSecureArea', true);
1920

2021
/** @var ProductRepositoryInterface $productRepository */
21-
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
22+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
2223

2324
$productSkus = ['search_product_1', 'search_product_2', 'search_product_3', 'search_product_4', 'search_product_5'];
2425
foreach ($productSkus as $sku) {

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/** @var ProductRepositoryInterface $productRepository */
2323
$productRepository = Bootstrap::getObjectManager()
24-
->create(ProductRepositoryInterface::class);
24+
->get(ProductRepositoryInterface::class);
2525

2626
/** @var $installer CategorySetup */
2727
$installer = Bootstrap::getObjectManager()->create(CategorySetup::class);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_12345.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/** @var ProductRepositoryInterface $productRepository */
2323
$productRepository = Bootstrap::getObjectManager()
24-
->create(ProductRepositoryInterface::class);
24+
->get(ProductRepositoryInterface::class);
2525

2626
/** @var $installer CategorySetup */
2727
$installer = Bootstrap::getObjectManager()->create(CategorySetup::class);
@@ -105,7 +105,7 @@
105105
$registry->unregister('isSecureArea');
106106
$registry->register('isSecureArea', true);
107107
try {
108-
$productToDelete = $productRepository->getById(11);
108+
$productToDelete = $productRepository->getById(111);
109109
$productRepository->delete($productToDelete);
110110

111111
/** @var \Magento\Quote\Model\ResourceModel\Quote\Item $itemResource */
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Customer\Block\Account;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\View\LayoutInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Tests for authentication popup block.
17+
*
18+
* @see \Magento\Customer\Block\Account\AuthenticationPopup
19+
* @magentoAppArea frontend
20+
*/
21+
class AuthenticationPopupTest extends TestCase
22+
{
23+
/** @var ObjectManagerInterface */
24+
private $objectManager;
25+
26+
/** @var AuthenticationPopup */
27+
private $block;
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
protected function setUp()
33+
{
34+
parent::setUp();
35+
36+
$this->objectManager = Bootstrap::getObjectManager();
37+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(AuthenticationPopup::class);
38+
}
39+
40+
/**
41+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
42+
*
43+
* @return void
44+
*/
45+
public function testAutocompletePasswordEnabled(): void
46+
{
47+
$this->assertEquals('on', $this->block->getConfig()['autocomplete']);
48+
}
49+
50+
/**
51+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
52+
*
53+
* @return void
54+
*/
55+
public function testAutocompletePasswordDisabled(): void
56+
{
57+
$this->assertEquals('off', $this->block->getConfig()['autocomplete']);
58+
}
59+
}

dev/tests/integration/testsuite/Magento/Customer/Block/Account/ResetPasswordTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,24 @@ public function testResetPasswordForm(): void
8383
'Set password button was not found on the page'
8484
);
8585
}
86+
87+
/**
88+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
89+
*
90+
* @return void
91+
*/
92+
public function testAutocompletePasswordEnabled(): void
93+
{
94+
$this->assertFalse($this->block->isAutocompleteDisabled());
95+
}
96+
97+
/**
98+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
99+
*
100+
* @return void
101+
*/
102+
public function testAutocompletePasswordDisabled(): void
103+
{
104+
$this->assertTrue($this->block->isAutocompleteDisabled());
105+
}
86106
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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\Customer\Block\Adminhtml\Edit\Tab\View;
9+
10+
use Magento\Customer\Controller\RegistryConstants;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\Registry;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Tests for customer wish list tab.
19+
*
20+
* @magentoAppArea adminhtml
21+
* @magentoDbIsolation enabled
22+
*/
23+
class WishlistTest extends TestCase
24+
{
25+
/** @var ObjectManagerInterface */
26+
private $objectManager;
27+
28+
/** @var Registry */
29+
private $registry;
30+
31+
/** @var Wishlist */
32+
private $block;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp()
38+
{
39+
parent::setUp();
40+
41+
$this->objectManager = Bootstrap::getObjectManager();
42+
$this->registry = $this->objectManager->get(Registry::class);
43+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Wishlist::class);
44+
}
45+
46+
/**
47+
* @inheritdoc
48+
*/
49+
protected function tearDown()
50+
{
51+
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
52+
53+
parent::tearDown();
54+
}
55+
56+
/**
57+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
58+
*
59+
* @return void
60+
*/
61+
public function testWishListGrid(): void
62+
{
63+
$this->registerCustomerId(1);
64+
$this->assertCount(1, $this->block->getPreparedCollection());
65+
}
66+
67+
/**
68+
* Add customer id to registry.
69+
*
70+
* @param int $customerId
71+
* @return void
72+
*/
73+
private function registerCustomerId(int $customerId): void
74+
{
75+
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
76+
$this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
77+
}
78+
}

dev/tests/integration/testsuite/Magento/Customer/Block/Form/LoginTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,24 @@ public function testLoginForm(): void
8989
'Forgot password link does not exist on the page'
9090
);
9191
}
92+
93+
/**
94+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
95+
*
96+
* @return void
97+
*/
98+
public function testAutocompletePasswordEnabled(): void
99+
{
100+
$this->assertFalse($this->block->isAutocompleteDisabled());
101+
}
102+
103+
/**
104+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
105+
*
106+
* @return void
107+
*/
108+
public function testAutocompletePasswordDisabled(): void
109+
{
110+
$this->assertTrue($this->block->isAutocompleteDisabled());
111+
}
92112
}

0 commit comments

Comments
 (0)