/**
  * Register product save processors.
  *
  * @param CompositeHelper $compositeHelper
  * @param array $saveProcessors Array of the processors which should be registered in the following format:
  * <pre>
  * [
  *      ['type' => $firstProcessorObject, 'sortOrder' => 15],
  *      ['type' => $secondProcessorObject, 'sortOrder' => 10],
  *      ...
  * ]
  * </pre>
  */
 public function __construct(CompositeHelper $compositeHelper, $saveProcessors = [])
 {
     $saveProcessors = $compositeHelper->filterAndSortDeclaredComponents($saveProcessors);
     foreach ($saveProcessors as $saveProcessor) {
         $this->productSaveProcessors[] = $saveProcessor['type'];
     }
 }
Пример #2
0
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->compositeHelperMock = $this->getMockBuilder('Magento\\Framework\\ObjectManager\\Helper\\Composite')->disableOriginalConstructor()->setMethods(['filterAndSortDeclaredComponents'])->getMock();
     $this->compositeHelperMock->expects($this->any())->method('filterAndSortDeclaredComponents')->will($this->returnArgument(0));
     $this->userContext = $this->objectManager->getObject('Magento\\Authorization\\Model\\CompositeUserContext', ['compositeHelper' => $this->compositeHelperMock]);
 }
 /**
  * Register user contexts.
  *
  * @param CompositeHelper $compositeHelper
  * @param UserContextInterface[] $userContexts
  */
 public function __construct(CompositeHelper $compositeHelper, $userContexts = [])
 {
     $userContexts = $compositeHelper->filterAndSortDeclaredComponents($userContexts);
     foreach ($userContexts as $userContext) {
         $this->add($userContext['type']);
     }
 }
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->compositeHelperMock = $this->getMockBuilder('Magento\\Framework\\ObjectManager\\Helper\\Composite')->disableOriginalConstructor()->setMethods(['filterAndSortDeclaredComponents'])->getMock();
     $this->compositeHelperMock->expects($this->any())->method('filterAndSortDeclaredComponents')->will($this->returnArgument(0));
     $this->loadProcessorMock = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Product\\ProductLoadProcessorComposite')->disableOriginalConstructor()->setMethods(['load'])->getMock();
     $this->processors = [['sortOrder' => 10, 'type' => $this->loadProcessorMock]];
     $this->loadProcessor = $this->objectManager->getObject('Magento\\Catalog\\Service\\V1\\Product\\ProductLoadProcessorComposite', ['compositeHelper' => $this->compositeHelperMock, 'loadProcessors' => $this->processors]);
 }
Пример #5
0
 public function testFilterAndSortDeclaredComponents()
 {
     $firstComponent = new \Magento\Framework\Object();
     $secondComponent = new \Magento\Framework\Object();
     $thirdComponent = new \Magento\Framework\Object();
     $contexts = [['type' => new \Magento\Framework\Object()], ['sortOrder' => 50], ['sortOrder' => 20, 'type' => $firstComponent], ['sortOrder' => 30, 'type' => $secondComponent], ['sortOrder' => 10, 'type' => $thirdComponent]];
     $result = $this->compositeHelper->filterAndSortDeclaredComponents($contexts);
     /** Ensure that misconfigured components were filtered out correctly */
     $this->assertCount(3, $result, 'Misconfigured components filtration does not work as expected.');
     /** Verify that components were ordered according to the defined sort order */
     $incorrectSortingMessage = "Registered components were sorted incorrectly";
     $this->assertSame($thirdComponent, $result[0]['type'], $incorrectSortingMessage);
     $this->assertSame($firstComponent, $result[1]['type'], $incorrectSortingMessage);
     $this->assertSame($secondComponent, $result[2]['type'], $incorrectSortingMessage);
 }