Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
use Magento\Ui\Component\Filters\FilterModifier;
use Magento\Ui\Component\Filters\Type\Input;
use Magento\Ui\Model\ColorPicker\ColorModesProvider;
use Magento\Ui\View\Element\BookmarkContextInterface;
use Magento\Ui\View\Element\BookmarkContextProviderInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* ColorTest test.
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)=
*/
class ColorTest extends TestCase
{
Expand Down Expand Up @@ -87,37 +89,49 @@ class ColorTest extends TestCase
*
* @param array $data
* @param ContextInterface $context
* @param array $filterData
* @return Color
*/
private function createObject(array $data, ContextInterface $context): Color
private function createObject(array $data, ContextInterface $context, array $filterData): Color
{
$this->uiComponentFactory = $this->createMock(UiComponentFactory::class);
$this->filterBuilder = $this->createMock(FilterBuilder::class);
$this->filterModifier = $this->createMock(FilterModifier::class);
$this->colorModesProvider = $this->createMock(ColorModesProvider::class);

$bookmarkContextProviderMock = $this->getMockForAbstractClass(
BookmarkContextProviderInterface::class
);
$bookmarkContextMock = $this->getMockForAbstractClass(
BookmarkContextInterface::class
);
$bookmarkContextMock->expects($this->once())
->method('getFilterData')
->willReturn($filterData);
$bookmarkContextProviderMock->expects($this->once())
->method('getByUiContext')
->willReturn($bookmarkContextMock);

return new Color(
$context,
$this->uiComponentFactory,
$this->filterBuilder,
$this->filterModifier,
$this->colorModesProvider,
[],
$data
$data,
$bookmarkContextProviderMock
);
}

/**
* Get context
*
* @param array $filterParams
* @return ContextInterface
* @return MockObject|ContextInterface
*/
private function getContext(array $filterParams): ContextInterface
private function getContext(): MockObject
{
$context = $this->createMock(ContextInterface::class);
$context->expects($this->once())
->method('getFiltersParams')
->willReturn($filterParams);
$context->expects($this->any())
->method('getNamespace');

Expand All @@ -143,11 +157,7 @@ private function getContext(array $filterParams): ContextInterface
public function testPrepare(?string $colorPickerMode, string $appliedValue): void
{
$filter = $this->createMock(Filter::class);
$context = $this->getContext(
[
self::FILTER_NAME => $appliedValue
]
);
$context = $this->getContext();

$color = $this->createObject(
[
Expand All @@ -156,7 +166,10 @@ public function testPrepare(?string $colorPickerMode, string $appliedValue): voi
],
'name' => self::FILTER_NAME
],
$context
$context,
[
self::FILTER_NAME => $appliedValue
]
);

$this->uiComponentFactory->expects($this->once())
Expand Down Expand Up @@ -230,10 +243,12 @@ public function colorPickerModeProvider(): array
{
return [
[
'full', '#21ffff'
'full',
'#21ffff'
],
[
null, '#ffffff'
null,
'#ffffff'
]
];
}
Expand Down
9 changes: 6 additions & 3 deletions AdobeStockImageAdminUi/Ui/Component/Listing/Filter/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Magento\Ui\Component\Filters\Type\AbstractFilter;
use Magento\Ui\Component\Filters\Type\Input;
use Magento\Ui\Component\Form\Element\ColorPicker;
use Magento\Ui\Component\Form\Element\Input as ElementInput;
use Magento\Ui\Model\ColorPicker\ColorModesProvider;
use Magento\Ui\View\Element\BookmarkContextProviderInterface;

/**
* Color grid filter
Expand All @@ -42,6 +42,7 @@ class Color extends AbstractFilter
* @param ColorModesProvider $modesProvider
* @param array $components
* @param array $data
* @param BookmarkContextProviderInterface|null $bookmarkContextProvider
*/
public function __construct(
ContextInterface $context,
Expand All @@ -50,7 +51,8 @@ public function __construct(
FilterModifier $filterModifier,
ColorModesProvider $modesProvider,
array $components = [],
array $data = []
array $data = [],
BookmarkContextProviderInterface $bookmarkContextProvider = null
) {
$this->modesProvider = $modesProvider;
parent::__construct(
Expand All @@ -59,7 +61,8 @@ public function __construct(
$filterBuilder,
$filterModifier,
$components,
$data
$data,
$bookmarkContextProvider
);
}

Expand Down