/** * Tests that attaching an association to a query will trigger beforeFind * for the target table * * @return void */ public function testAttachToBeforeFindExtraOptions() { $query = $this->getMock('\\Cake\\ORM\\Query', ['join', 'select'], [null, null]); $config = ['sourceTable' => $this->author, 'targetTable' => $this->article]; $listener = $this->getMock('stdClass', ['__invoke']); $association = new HasMany('Articles', $config); $this->article->getEventManager()->attach($listener, 'Model.beforeFind'); $opts = ['something' => 'more']; $listener->expects($this->once())->method('__invoke')->with($this->isInstanceOf('\\Cake\\Event\\Event'), $this->isInstanceOf('\\Cake\\ORM\\Query'), $opts, false); $association->attachTo($query, ['queryBuilder' => function ($q) { return $q->applyOptions(['something' => 'more']); }]); }
/** * Test that plugin names are omitted from property() * * @return void */ public function testPropertyNoPlugin() { $mock = $this->getMock('Cake\\ORM\\Table', [], [], '', false); $config = ['sourceTable' => $this->author, 'targetTable' => $mock]; $association = new HasMany('Contacts.Addresses', $config); $this->assertEquals('addresses', $association->property()); }
/** * Test that plugin names are omitted from property() * * @return void */ public function testPropertyNoPlugin() { $mock = $this->getMockBuilder('Cake\\ORM\\Table')->disableOriginalConstructor()->getMock(); $config = ['sourceTable' => $this->author, 'targetTable' => $mock]; $association = new HasMany('Contacts.Addresses', $config); $this->assertEquals('addresses', $association->property()); }