/** * @param FormItem $form * @depends testGettersAndSetters */ public function testExchangeable(FormItem $form) { $conf = $form->toArray(); $newForm = new FormItem(); $newForm->fromArray($conf); $this->assertEquals($form, $newForm); $newConf = $newForm->toArray(); $this->assertEquals($conf, $newConf); }
public function testPrepare() { $expectedId = 'COL:EXAMPLEID'; $expectedName = 'EXAMPLENAME'; $subId = 'FRM:EXAMPLEID2'; $subType = FormItem::class; $subItem = new FormItem(); $subItem->setId($subId); $storage = $this->getMock(StorageInterface::class); $storage->expects($this->once())->method('get')->willReturn([CollectionItem::EXCHANGE_ID => $expectedId, CollectionItem::EXCHANGE_NAME => $expectedName, CollectionItemBuilderListener::ITEM_CONFIG_KEY => [[CollectionItemBuilderListener::SUB_ID => $subId, CollectionItemBuilderListener::SUB_TYPE => $subType]]]); $timetableManager = $this->getMock(TimetableManagerInterface::class); $timetableManager->method('getPointInTime')->willReturn(new \DateTime()); $itemFactory = $this->getMock(ItemFactoryInterface::class); $itemFactory->expects($this->once())->method('getItem')->with($this->equalTo($subItem))->willReturn($subItem); $collectionItem = new CollectionItem(); $collectionItem->setId($expectedId); $event = new ItemFactoryEvent(); $event->setItem($collectionItem)->setName(ItemFactoryEvents::PREPARE_ITEM); $listener = new CollectionItemBuilderListener($storage, $timetableManager, $itemFactory); $listener->prepareItem($event); $this->assertEquals([$subItem], $collectionItem->getAll()); $this->assertEquals($expectedId, $collectionItem->getId()); $this->assertEquals($expectedName, $collectionItem->getName()); }