/** * Get the field refill attributes. * * @param string $field * @param ItemEntity|null $item * * @return array */ protected function getRefillAttr($field, ItemEntity $item = null) { // item exists and can be refilled if ($item instanceof ItemEntity && $item->getName() && ($plugins = $this->chain->getPluginsThatCanFillItem($item, $field))) { /* @var $plugin RefillerInterface */ foreach ($plugins as $key => $plugin) { $plugins[$key] = ['name' => $plugin->getName(), 'title' => $plugin->getTitle(), 'can_refill' => $plugin->isCanRefill($item, $field)]; } return ['data-type' => 'refill', 'data-plugins' => $this->templating->render('AnimeDbCatalogBundle:Form:refillers.html.twig', ['item' => $item, 'field' => $field, 'plugins' => $plugins])]; } return []; }
/** * @dataProvider getPlugins * * @param bool $is_can_refill * @param bool $is_can_search */ public function testGetPluginsThatCanFillItem($is_can_refill, $is_can_search) { /* @var $item \PHPUnit_Framework_MockObject_MockObject|Item */ $item = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Item'); /* @var $plugin1 \PHPUnit_Framework_MockObject_MockObject|RefillerInterface */ $plugin1 = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Plugin\\Fill\\Refiller\\RefillerInterface'); $plugin1->expects($this->once())->method('isCanRefill')->with($item, 'foo')->will($this->returnValue($is_can_refill)); $plugin1->expects($is_can_refill ? $this->never() : $this->once())->method('isCanSearch')->with($item, 'foo')->will($this->returnValue($is_can_search)); $plugin1->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('plugin1')); /* @var $plugin2 \PHPUnit_Framework_MockObject_MockObject|RefillerInterface */ $plugin2 = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Plugin\\Fill\\Refiller\\RefillerInterface'); $plugin2->expects($this->once())->method('isCanRefill')->with($item, 'foo')->will($this->returnValue(true)); $plugin2->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('plugin2')); $chain = new Chain(); $chain->addPlugin($plugin1); $chain->addPlugin($plugin2); $actual = $chain->getPluginsThatCanFillItem($item, 'foo'); if ($is_can_refill || $is_can_search) { $this->assertEquals([$plugin1, $plugin2], $actual); } else { $this->assertEquals([$plugin2], $actual); } }