/** * @dataProvider processDataProvider */ public function testProcess($schedule, $expectedSchedule) { foreach ($schedule['structure'] as $structureElement) { $this->scheduledStructure->setStructureElement($structureElement, []); } $moveMap = []; foreach ($schedule['move'] as $elementName => $move) { $this->scheduledStructure->setElementToMove($elementName, $move); list($destination, $sibling, $isAfter) = $move; $moveMap[] = [$destination, $elementName, $sibling, $isAfter]; } $invocation = $this->structureMock->expects($this->any())->method('reorderChildElement'); call_user_func_array([$invocation, 'withConsecutive'], $moveMap); foreach ($schedule['remove'] as $remove) { $this->scheduledStructure->setElementToRemoveList($remove); } $this->helperMock->expects($this->atLeastOnce())->method('scheduleElement')->with($this->scheduledStructure, $this->structureMock, $this->anything())->willReturnCallback(function ($scheduledStructure, $structure, $elementName) use($schedule) { /** @var $scheduledStructure ScheduledStructure */ /** @var $structure Data\Structure */ $this->assertContains($elementName, $schedule['structure']); $scheduledStructure->unsetStructureElement($elementName); $scheduledStructure->setElement($elementName, []); $structure->createStructuralElement($elementName, 'block', 'someClass'); }); $this->model->process($this->readerContextMock, $this->generatorContextMock); $this->assertEquals($expectedSchedule, $this->scheduledStructure->getElements()); }
/** * Move element in scheduled structure * * @param ScheduledStructure $scheduledStructure * @param Data\Structure $structure * @param string $element * @return $this */ protected function moveElementInStructure(ScheduledStructure $scheduledStructure, Data\Structure $structure, $element) { list($destination, $siblingName, $isAfter, $alias) = $scheduledStructure->getElementToMove($element); $childAlias = $structure->getChildAlias($structure->getParentId($element), $element); if (!$alias && false === $structure->getChildId($destination, $childAlias)) { $alias = $childAlias; } $structure->unsetChild($element, $alias); try { $structure->setAsChild($element, $destination, $alias); $structure->reorderChildElement($destination, $element, $siblingName, $isAfter); } catch (\OutOfBoundsException $e) { $this->logger->critical('Broken reference: ' . $e->getMessage()); } $scheduledStructure->unsetElementFromBrokenParentList($element); return $this; }