-
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 pull request #7578 from magento-gl/Hammer_Quality_Backlog_Graph…
…Ql_13042022 Hammer quality backlog graph ql 13042022
- Loading branch information
Showing
21 changed files
with
527 additions
and
63 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
152 changes: 152 additions & 0 deletions
152
app/code/Magento/CatalogGraphQl/Test/Unit/DataProvider/Product/SearchCriteriaBuilderTest.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,152 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Test\Unit\DataProvider\Product; | ||
|
||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\Catalog\Model\ResourceModel\Eav\Attribute; | ||
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder; | ||
use Magento\Eav\Model\Config; | ||
use Magento\Framework\Api\Filter; | ||
use Magento\Framework\Api\FilterBuilder; | ||
use Magento\Framework\Api\Search\FilterGroupBuilder; | ||
use Magento\Framework\Api\Search\SearchCriteriaInterface; | ||
use Magento\Framework\Api\SortOrderBuilder; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Build search criteria | ||
*/ | ||
class SearchCriteriaBuilderTest extends TestCase | ||
{ | ||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private ScopeConfigInterface $scopeConfig; | ||
|
||
/** | ||
* @var FilterBuilder | ||
*/ | ||
private FilterBuilder $filterBuilder; | ||
|
||
/** | ||
* @var FilterGroupBuilder | ||
*/ | ||
private FilterGroupBuilder $filterGroupBuilder; | ||
|
||
/** | ||
* @var Builder | ||
*/ | ||
private Builder $builder; | ||
|
||
/** | ||
* @var Visibility | ||
*/ | ||
private Visibility $visibility; | ||
|
||
/** | ||
* @var SortOrderBuilder | ||
*/ | ||
private SortOrderBuilder $sortOrderBuilder; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private SearchCriteriaBuilder $model; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private Config $eavConfig; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->builder = $this->createMock(Builder::class); | ||
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class); | ||
$this->filterBuilder = $this->createMock(FilterBuilder::class); | ||
$this->filterGroupBuilder = $this->createMock(FilterGroupBuilder::class); | ||
$this->sortOrderBuilder = $this->createMock(SortOrderBuilder::class); | ||
$this->visibility = $this->createMock(Visibility::class); | ||
$this->eavConfig = $this->createMock(Config::class); | ||
$this->model = new SearchCriteriaBuilder( | ||
$this->builder, | ||
$this->scopeConfig, | ||
$this->filterBuilder, | ||
$this->filterGroupBuilder, | ||
$this->visibility, | ||
$this->sortOrderBuilder, | ||
$this->eavConfig | ||
); | ||
} | ||
|
||
public function testBuild(): void | ||
{ | ||
$args = ['search' => '', 'pageSize' => 20, 'currentPage' => 1]; | ||
|
||
$filter = $this->createMock(Filter::class); | ||
|
||
$searchCriteria = $this->getMockBuilder(SearchCriteriaInterface::class) | ||
->disableOriginalConstructor() | ||
->getMockForAbstractClass(); | ||
$attributeInterface = $this->getMockBuilder(Attribute::class) | ||
->disableOriginalConstructor() | ||
->getMockForAbstractClass(); | ||
|
||
$attributeInterface->setData(['is_filterable' => 0]); | ||
|
||
$this->builder->expects($this->any()) | ||
->method('build') | ||
->with('products', $args) | ||
->willReturn($searchCriteria); | ||
$searchCriteria->expects($this->any())->method('getFilterGroups')->willReturn([]); | ||
$this->eavConfig->expects($this->any()) | ||
->method('getAttribute') | ||
->with(Product::ENTITY, 'price') | ||
->willReturn($attributeInterface); | ||
|
||
$this->sortOrderBuilder->expects($this->once()) | ||
->method('setField') | ||
->with('_id') | ||
->willReturnSelf(); | ||
$this->sortOrderBuilder->expects($this->once()) | ||
->method('setDirection') | ||
->with('DESC') | ||
->willReturnSelf(); | ||
$this->sortOrderBuilder->expects($this->any()) | ||
->method('create') | ||
->willReturn([]); | ||
|
||
$this->filterBuilder->expects($this->once()) | ||
->method('setField') | ||
->with('visibility') | ||
->willReturnSelf(); | ||
$this->filterBuilder->expects($this->once()) | ||
->method('setValue') | ||
->with("") | ||
->willReturnSelf(); | ||
$this->filterBuilder->expects($this->once()) | ||
->method('setConditionType') | ||
->with('in') | ||
->willReturnSelf(); | ||
|
||
$this->filterBuilder->expects($this->once())->method('create')->willReturn($filter); | ||
|
||
$this->filterGroupBuilder->expects($this->any()) | ||
->method('addFilter') | ||
->with($filter) | ||
->willReturnSelf(); | ||
|
||
$this->model->build($args, true); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.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,90 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogInventory\Test\Fixture; | ||
|
||
use Magento\Framework\DataObject; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryApi\Api\SourceItemsDeleteInterface; | ||
use Magento\InventoryApi\Api\SourceItemsSaveInterface; | ||
use Magento\TestFramework\Fixture\Api\DataMerger; | ||
use Magento\TestFramework\Fixture\Api\ServiceFactory; | ||
use Magento\TestFramework\Fixture\Data\ProcessorInterface; | ||
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface; | ||
|
||
class SourceItem implements RevertibleDataFixtureInterface | ||
{ | ||
private const DEFAULT_DATA = [ | ||
'sku' => 'SKU-%uniqid%', | ||
'source_code' => 'Source%uniqid%', | ||
'quantity' => 5, | ||
'status' => SourceItemInterface::STATUS_IN_STOCK, | ||
]; | ||
|
||
/** | ||
* @var ServiceFactory | ||
*/ | ||
private ServiceFactory $serviceFactory; | ||
|
||
/** | ||
* @var ProcessorInterface | ||
*/ | ||
private ProcessorInterface $dataProcessor; | ||
|
||
/** | ||
* @var DataMerger | ||
*/ | ||
private DataMerger $dataMerger; | ||
|
||
/** | ||
* @param ServiceFactory $serviceFactory | ||
* @param ProcessorInterface $dataProcessor | ||
* @param DataMerger $dataMerger | ||
*/ | ||
public function __construct( | ||
ServiceFactory $serviceFactory, | ||
ProcessorInterface $dataProcessor, | ||
DataMerger $dataMerger | ||
) { | ||
$this->serviceFactory = $serviceFactory; | ||
$this->dataProcessor = $dataProcessor; | ||
$this->dataMerger = $dataMerger; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @return DataObject|null | ||
*/ | ||
public function apply(array $data = []): ?DataObject | ||
{ | ||
$service = $this->serviceFactory->create(SourceItemsSaveInterface::class, 'execute'); | ||
|
||
return $service->execute(['sourceItems' => [$this->prepareData($data)]]); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function revert(DataObject $data): void | ||
{ | ||
$service = $this->serviceFactory->create(SourceItemsDeleteInterface::class, 'execute'); | ||
$service->execute(['sourceItems' => [$this->prepareData($data->getData())]]); | ||
} | ||
|
||
/** | ||
* Prepare product data | ||
* | ||
* @param array $data | ||
* @return array | ||
*/ | ||
private function prepareData(array $data): array | ||
{ | ||
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data, false); | ||
|
||
return $this->dataProcessor->process($this, $data); | ||
} | ||
} |
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.