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.
Merge pull request #7 from chirag-wagento/2.1-develop-PR-port-16937
[Backport] Revert changing file permissions in magento#15144
- Loading branch information
Showing
11 changed files
with
358 additions
and
80 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,17 @@ | |
*/ | ||
namespace Magento\Customer\Controller\Adminhtml\Index; | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use Magento\Customer\Api\Data\CustomerInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Message\MessageInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\AbstractBackendController; | ||
|
||
/** | ||
* @magentoAppArea adminhtml | ||
*/ | ||
class MassAssignGroupTest extends \Magento\TestFramework\TestCase\AbstractBackendController | ||
class MassAssignGroupTest extends AbstractBackendController | ||
{ | ||
/** | ||
* Base controller URL | ||
|
@@ -28,9 +32,7 @@ class MassAssignGroupTest extends \Magento\TestFramework\TestCase\AbstractBacken | |
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->customerRepository = Bootstrap::getObjectManager()->get( | ||
'Magento\Customer\Api\CustomerRepositoryInterface' | ||
); | ||
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); | ||
} | ||
|
||
protected function tearDown() | ||
|
@@ -47,39 +49,100 @@ protected function tearDown() | |
} | ||
|
||
/** | ||
* @magentoDataFixture Magento/Customer/_files/customer.php | ||
* Tests os update a single customer record. | ||
* | ||
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php | ||
* @magentoDbIsolation disabled | ||
*/ | ||
public function testMassAssignGroupAction() | ||
{ | ||
$customer = $this->customerRepository->getById(1); | ||
$this->assertEquals(1, $customer->getGroupId()); | ||
$customerEmail = '[email protected]'; | ||
try { | ||
/** @var CustomerInterface $customer */ | ||
$customer = $this->customerRepository->get($customerEmail); | ||
$this->assertEquals(1, $customer->getGroupId()); | ||
|
||
$params = [ | ||
'group' => 0, | ||
'namespace' => 'customer_listing', | ||
'selected' => [$customer->getId()] | ||
]; | ||
|
||
$this->getRequest()->setParams($params); | ||
$this->dispatch('backend/customer/index/massAssignGroup'); | ||
$this->assertSessionMessages( | ||
self::equalTo(['A total of 1 record(s) were updated.']), | ||
MessageInterface::TYPE_SUCCESS | ||
); | ||
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl)); | ||
|
||
$customer = $this->customerRepository->get($customerEmail); | ||
$this->assertEquals(0, $customer->getGroupId()); | ||
} catch (LocalizedException $e) { | ||
self::fail($e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Tests os update a multiple customer records. | ||
* | ||
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php | ||
* @magentoDbIsolation disabled | ||
*/ | ||
public function testLargeGroupMassAssignGroupAction() | ||
{ | ||
$ids = []; | ||
for ($i = 1; $i <= 5; $i++) { | ||
/** @var CustomerInterface $customer */ | ||
try { | ||
$customer = $this->customerRepository->get('customer'.$i.'@example.com'); | ||
$this->assertEquals(1, $customer->getGroupId()); | ||
$ids[] = $customer->getId(); | ||
} catch (\Exception $e) { | ||
self::fail($e->getMessage()); | ||
} | ||
} | ||
|
||
$params = [ | ||
'group' => 0, | ||
'namespace' => 'customer_listing', | ||
'selected' => $ids, | ||
]; | ||
|
||
$this->getRequest() | ||
->setParam('group', 0) | ||
->setPostValue('namespace', 'customer_listing') | ||
->setPostValue('selected', [1]); | ||
$this->getRequest()->setParams($params); | ||
$this->dispatch('backend/customer/index/massAssignGroup'); | ||
$this->assertSessionMessages( | ||
$this->equalTo(['A total of 1 record(s) were updated.']), | ||
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS | ||
self::equalTo(['A total of 5 record(s) were updated.']), | ||
MessageInterface::TYPE_SUCCESS | ||
); | ||
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl)); | ||
|
||
$customer = $this->customerRepository->getById(1); | ||
$this->assertEquals(0, $customer->getGroupId()); | ||
for ($i = 1; $i < 5; $i++) { | ||
try { | ||
/** @var CustomerInterface $customer */ | ||
$customer = $this->customerRepository->get('customer'.$i.'@example.com'); | ||
$this->assertEquals(0, $customer->getGroupId()); | ||
} catch (\Exception $e) { | ||
self::fail($e->getMessage()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Valid group Id but no customer Ids specified | ||
* | ||
* @magentoDbIsolation enabled | ||
*/ | ||
public function testMassAssignGroupActionNoCustomerIds() | ||
{ | ||
$this->getRequest()->setParam('group', 0)->setPostValue('namespace', 'customer_listing'); | ||
$params = [ | ||
'group' => 0, | ||
'namespace' => 'customer_listing', | ||
]; | ||
$this->getRequest()->setParams($params); | ||
$this->dispatch('backend/customer/index/massAssignGroup'); | ||
$this->assertSessionMessages( | ||
$this->equalTo(['Please select item(s).']), | ||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR | ||
MessageInterface::TYPE_ERROR | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,58 +5,162 @@ | |
*/ | ||
namespace Magento\Customer\Controller\Adminhtml\Index; | ||
|
||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use Magento\Customer\Api\Data\CustomerInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Message\MessageInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\AbstractBackendController; | ||
use PHPUnit_Framework_Constraint; | ||
|
||
/** | ||
* @magentoAppArea adminhtml | ||
*/ | ||
class MassDeleteTest extends \Magento\TestFramework\TestCase\AbstractBackendController | ||
class MassDeleteTest extends AbstractBackendController | ||
{ | ||
/** | ||
* @var CustomerRepositoryInterface | ||
*/ | ||
private $customerRepository; | ||
|
||
/** | ||
* Base controller URL | ||
* | ||
* @var string | ||
*/ | ||
protected $baseControllerUrl = 'http://localhost/index.php/backend/customer/index/index'; | ||
private $baseControllerUrl = 'http://localhost/index.php/backend/customer/index/index'; | ||
|
||
protected function tearDown() | ||
protected function setUp() | ||
{ | ||
/** | ||
* Unset customer data | ||
*/ | ||
Bootstrap::getObjectManager()->get('Magento\Backend\Model\Session')->setCustomerData(null); | ||
parent::setUp(); | ||
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); | ||
} | ||
|
||
/** | ||
* Unset messages | ||
*/ | ||
Bootstrap::getObjectManager()->get('Magento\Backend\Model\Session')->getMessages(true); | ||
/** | ||
* Validates failure attempts to delete customers from grid. | ||
* | ||
* @param array|null $ids | ||
* @param \PHPUnit_Framework_Constraint $constraint | ||
* @param string|null $messageType | ||
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php | ||
* @magentoDbIsolation disabled | ||
* @dataProvider failedRequestDataProvider | ||
*/ | ||
public function testFailedMassDeleteAction($ids, PHPUnit_Framework_Constraint $constraint, $messageType) | ||
{ | ||
$this->massDeleteAssertions($ids, $constraint, $messageType); | ||
} | ||
|
||
/** | ||
* @magentoDataFixture Magento/Customer/_files/customer.php | ||
* Validates success attempt to delete customer from grid. | ||
* | ||
* @param array $emails | ||
* @param PHPUnit_Framework_Constraint $constraint | ||
* @param string $messageType | ||
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php | ||
* @magentoDbIsolation disabled | ||
* @dataProvider successRequestDataProvider | ||
*/ | ||
public function testSuccessMassDeleteAction(array $emails, PHPUnit_Framework_Constraint $constraint, $messageType) | ||
{ | ||
try { | ||
$ids = []; | ||
foreach ($emails as $email) { | ||
/** @var CustomerInterface $customer */ | ||
$customer = $this->customerRepository->get($email); | ||
$ids[] = $customer->getId(); | ||
} | ||
|
||
$this->massDeleteAssertions( | ||
$ids, | ||
$constraint, | ||
$messageType | ||
); | ||
} catch (LocalizedException $e) { | ||
self::fail($e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Performs required request and assertions. | ||
* | ||
* @param array|null $ids | ||
* @param PHPUnit_Framework_Constraint $constraint | ||
* @param string|null $messageType | ||
*/ | ||
public function testMassDeleteAction() | ||
private function massDeleteAssertions($ids, PHPUnit_Framework_Constraint $constraint, $messageType) | ||
{ | ||
$this->getRequest()->setPostValue('selected', [1])->setPostValue('namespace', 'customer_listing'); | ||
$requestData = [ | ||
'selected' => $ids, | ||
'namespace' => 'customer_listing', | ||
]; | ||
|
||
$this->getRequest()->setParams($requestData); | ||
$this->dispatch('backend/customer/index/massDelete'); | ||
$this->assertSessionMessages( | ||
$this->equalTo(['A total of 1 record(s) were deleted.']), | ||
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS | ||
$constraint, | ||
$messageType | ||
); | ||
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl)); | ||
} | ||
|
||
/** | ||
* Valid group Id but no customer Ids specified | ||
* @magentoDbIsolation enabled | ||
* Provides sets of data for unsuccessful attempts. | ||
* | ||
* @return array | ||
*/ | ||
public function testMassDeleteActionNoCustomerIds() | ||
public function failedRequestDataProvider() | ||
{ | ||
$this->getRequest()->setPostValue('namespace', 'customer_listing'); | ||
$this->dispatch('backend/customer/index/massDelete'); | ||
$this->assertSessionMessages( | ||
$this->equalTo(['Please select item(s).']), | ||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR | ||
); | ||
return [ | ||
[ | ||
'ids' => [], | ||
'constraint' => self::equalTo(['Please select item(s).']), | ||
'messageType' => MessageInterface::TYPE_ERROR, | ||
], | ||
[ | ||
'ids' => [111], | ||
'constraint' => self::isEmpty(), | ||
'messageType' => null, | ||
], | ||
[ | ||
'ids' => null, | ||
'constraint' => self::equalTo(['Please select item(s).']), | ||
'messageType' => MessageInterface::TYPE_ERROR, | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Provides sets of data for successful attempts. | ||
* | ||
* @return array | ||
*/ | ||
public function successRequestDataProvider() | ||
{ | ||
return [ | ||
[ | ||
'customerEmails' => ['[email protected]'], | ||
'constraint' => self::equalTo(['A total of 1 record(s) were deleted.']), | ||
'messageType' => MessageInterface::TYPE_SUCCESS, | ||
], | ||
[ | ||
'customerEmails' => ['[email protected]', '[email protected]'], | ||
'constraint' => self::equalTo(['A total of 2 record(s) were deleted.']), | ||
'messageType' => MessageInterface::TYPE_SUCCESS, | ||
], | ||
]; | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
/** | ||
* Unset customer data | ||
*/ | ||
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->setCustomerData(null); | ||
|
||
/** | ||
* Unset messages | ||
*/ | ||
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->getMessages(true); | ||
} | ||
} |
Oops, something went wrong.