-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'mainline/2.2-develop' into pr-2.2-develop
- Loading branch information
Showing
366 changed files
with
7,639 additions
and
2,099 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
73 changes: 73 additions & 0 deletions
73
app/code/Magento/Backend/Model/GlobalSearch/SearchEntity.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,73 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Backend\Model\GlobalSearch; | ||
|
||
/** | ||
* Entity for global search in backend | ||
*/ | ||
class SearchEntity extends \Magento\Framework\DataObject | ||
{ | ||
/** | ||
* Get id. | ||
* | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->getData('id'); | ||
} | ||
|
||
/** | ||
* Get url. | ||
* | ||
* @return string | ||
*/ | ||
public function getUrl() | ||
{ | ||
return $this->getData('url'); | ||
} | ||
|
||
/** | ||
* Get title. | ||
* | ||
* @return string | ||
*/ | ||
public function getTitle() | ||
{ | ||
return $this->getData('title'); | ||
} | ||
|
||
/** | ||
* Set Id. | ||
* | ||
* @param string $value | ||
*/ | ||
public function setId(string $value) | ||
{ | ||
$this->setData('id', $value); | ||
} | ||
|
||
/** | ||
* Set url. | ||
* | ||
* @param string $value | ||
*/ | ||
public function setUrl(string $value) | ||
{ | ||
$this->setData('url', $value); | ||
} | ||
|
||
/** | ||
* Set title. | ||
* | ||
* @param string $value | ||
*/ | ||
public function setTitle(string $value) | ||
{ | ||
$this->setData('title', $value); | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
app/code/Magento/Backend/Test/Unit/Block/GlobalSearchTest.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,123 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Backend\Test\Unit\Block; | ||
|
||
use Magento\Backend\Block\GlobalSearch; | ||
use Magento\Backend\Model\GlobalSearch\SearchEntity; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
|
||
/** | ||
* Test for @see GlobalSearch. | ||
*/ | ||
class GlobalSearchTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var GlobalSearch | ||
*/ | ||
private $globalSearch; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\AuthorizationInterface | ||
*/ | ||
private $authorization; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\UrlInterface | ||
*/ | ||
private $urlBuilder; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\GlobalSearch\SearchEntityFactory | ||
*/ | ||
private $searchEntityFactory; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $entityResources = [ | ||
'Products' => \Magento\Catalog\Controller\Adminhtml\Product::ADMIN_RESOURCE, | ||
'Orders' => \Magento\Sales\Controller\Adminhtml\Order::ADMIN_RESOURCE, | ||
'Customers' => \Magento\Customer\Controller\Adminhtml\Index::ADMIN_RESOURCE, | ||
'Pages' => \Magento\Cms\Controller\Adminhtml\Page\Index::ADMIN_RESOURCE, | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $entityPaths = [ | ||
'Products' => 'catalog/product/index/', | ||
'Orders' => 'sales/order/index/', | ||
'Customers' => 'customer/index/index', | ||
'Pages' => 'cms/page/index/', | ||
]; | ||
|
||
protected function setUp() | ||
{ | ||
$objectManager = new ObjectManager($this); | ||
|
||
$this->authorization = $this->createMock(\Magento\Framework\AuthorizationInterface::class); | ||
$this->urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class); | ||
$context = $this->createMock(\Magento\Backend\Block\Template\Context::class); | ||
|
||
$context->expects($this->atLeastOnce())->method('getAuthorization')->willReturn($this->authorization); | ||
$context->expects($this->atLeastOnce())->method('getUrlBuilder')->willReturn($this->urlBuilder); | ||
|
||
$this->searchEntityFactory = $this->createMock(\Magento\Backend\Model\GlobalSearch\SearchEntityFactory::class); | ||
|
||
$this->globalSearch = $objectManager->getObject( | ||
GlobalSearch::class, | ||
[ | ||
'context' => $context, | ||
'searchEntityFactory' => $this->searchEntityFactory, | ||
'entityResources' => $this->entityResources, | ||
'entityPaths' => $this->entityPaths, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @param array $results | ||
* @param int $expectedEntitiesQty | ||
* | ||
* @dataProvider getEntitiesToShowDataProvider | ||
*/ | ||
public function testGetEntitiesToShow(array $results, int $expectedEntitiesQty) | ||
{ | ||
$searchEntity = $this->createMock(SearchEntity::class); | ||
|
||
$this->authorization->expects($this->exactly(count($results)))->method('isAllowed') | ||
->willReturnOnConsecutiveCalls($results[0], $results[1], $results[2], $results[3]); | ||
$this->urlBuilder->expects($this->exactly($expectedEntitiesQty)) | ||
->method('getUrl')->willReturn('some/url/is/here'); | ||
$this->searchEntityFactory->expects($this->exactly($expectedEntitiesQty)) | ||
->method('create')->willReturn($searchEntity); | ||
|
||
$searchEntity->expects($this->exactly($expectedEntitiesQty))->method('setId'); | ||
$searchEntity->expects($this->exactly($expectedEntitiesQty))->method('setTitle'); | ||
$searchEntity->expects($this->exactly($expectedEntitiesQty))->method('setUrl'); | ||
|
||
$this->assertSame($expectedEntitiesQty, count($this->globalSearch->getEntitiesToShow())); | ||
} | ||
|
||
public function getEntitiesToShowDataProvider() | ||
{ | ||
return [ | ||
[ | ||
[true, false, true, false], | ||
2, | ||
], | ||
[ | ||
[true, true, true, true], | ||
4, | ||
], | ||
[ | ||
[false, false, false, false], | ||
0, | ||
], | ||
]; | ||
} | ||
} |
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
Oops, something went wrong.