/** * @param string $type type * @param string $component component * @param string $actionComponentClass actionComponentClass * * @return void */ public function addComponent($type, $component, $actionComponentClass) { parent::addComponent($type, $component, $actionComponentClass); if ('subject' === $type && $component instanceof ComponentInterface) { // useful for actionManager->getSubjectActions() $this->subject = $this->getComponent('subject'); } }
/** * Test process() method in order to test that collection is well completed. */ public function testProcessMethod() { $action = new Action(); $action->setVerb('a.not.supported.verb'); $spread = $this->getMockBuilder('\\Sonata\\TimelineBundle\\Spread\\AdminSpread')->disableOriginalConstructor()->setMethods(array('getUsers'))->getMock(); $spread->expects($this->any())->method('getUsers')->will($this->returnValue($this->getFakeUsers())); $collection = new EntryCollection(); $spread->process($action, $collection); $this->assertCount(2, $collection->getIterator(), 'Should return 2'); $usersCount = 0; foreach ($collection->getIterator() as $users) { foreach ($users as $entry) { ++$usersCount; $this->assertInstanceOf('Spy\\Timeline\\Spread\\Entry\\EntryUnaware', $entry, 'Should return an instance of EntryUnaware'); } } $this->assertEquals(5, $usersCount / 2, 'Should return 5 users for 2 iterations'); }
/** * actionComponents and timelines has to be a doctrine common collection. */ public function __construct() { parent::__construct(); $this->actionComponents = new ArrayCollection(); $this->timelines = new ArrayCollection(); }
public function testGetSubject() { // this is almost the same test than getComponent $this->if($action = new TestedModel())->variable($action->getComponent('subject'))->isNull()->when($action->addComponent('subject', 'chuckNorris', '\\Spy\\Timeline\\Model\\ActionComponent'))->string($action->getComponent('subject'))->isEqualTo('chuckNorris')->if($this->mockClass('\\Spy\\Timeline\\Model\\ComponentInterface', '\\Mock'))->and($component = new \Mock\ComponentInterface())->when($action->addComponent('subject', $component, '\\Spy\\Timeline\\Model\\ActionComponent'))->object($action->getComponent('subject'))->isIdenticalTo($component); }