Skip to content

Commit

Permalink
Merge pull request #7 from chirag-wagento/2.1-develop-PR-port-16937
Browse files Browse the repository at this point in the history
[Backport] Revert changing file permissions in magento#15144
  • Loading branch information
chirag-wagento authored Jul 25, 2018
2 parents 1dc671c + df5234b commit 0eac82d
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ public function execute()
$product->delete();
$productDeleted++;
}
$this->messageManager->addSuccess(
__('A total of %1 record(s) have been deleted.', $productDeleted)
);

if ($productDeleted) {
$this->messageManager->addSuccess(
__('A total of %1 record(s) have been deleted.', $productDeleted)
);
}

return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('catalog/*/index');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// @codingStandardsIgnoreFile

/** @var $block \Magento\Catalog\Block\Catalog\Product\View\Addto\Compare */
/** @var $block \Magento\Catalog\Block\Product\View\Addto\Compare */
?>

<a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getPostDataParams();?>'
Expand Down
6 changes: 0 additions & 6 deletions app/code/Magento/Tax/Block/Sales/Order/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,6 @@ protected function _initShipping()
*/
protected function _initDiscount()
{
// $store = $this->getStore();
// $parent = $this->getParentBlock();
// if ($this->_config->displaySales) {
//
// } elseif ($this->_config->displaySales) {
// }
}

/**
Expand Down
12 changes: 5 additions & 7 deletions app/code/Magento/Ui/Component/MassAction/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ public function getCollection(AbstractDb $collection)
throw new LocalizedException(__('Please select item(s).'));
}
}
$idsArray = $this->getFilterIds();
if (!empty($idsArray)) {
$collection->addFieldToFilter(
$collection->getIdFieldName(),
['in' => $idsArray]
);
}

$collection->addFieldToFilter(
$collection->getIdFieldName(),
['in' => $this->getFilterIds()]
);

return $collection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
border-bottom-left-radius: 0;
border-top-left-radius: 0;
margin-left: -1px;
white-space: nowrap;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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 = 'customer1@example.com';
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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ['customer1@example.com'],
'constraint' => self::equalTo(['A total of 1 record(s) were deleted.']),
'messageType' => MessageInterface::TYPE_SUCCESS,
],
[
'customerEmails' => ['customer2@example.com', 'customer3@example.com'],
'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);
}
}
Loading

0 comments on commit 0eac82d

Please sign in to comment.