Beispiel #1
0
 /**
  * Test liking entities having a non persited target entity
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Cannot link not persisted entities
  * @return void
  */
 public function testUnlinkWithNotPersistedTarget()
 {
     $config = ['sourceTable' => $this->article, 'targetTable' => $this->tag, 'joinTable' => 'tags_articles'];
     $assoc = new BelongsToMany('Test', $config);
     $entity = new Entity(['id' => 1], ['markNew' => false]);
     $tags = [new Entity(['id' => 2]), new Entity(['id' => 3])];
     $assoc->unlink($entity, $tags);
 }
 /**
  * Tests that unlinking with last parameter set to false
  * will not remove entities from the association property
  *
  * @return void
  */
 public function testUnlinkWithoutPropertyClean()
 {
     $connection = ConnectionManager::get('test');
     $joint = $this->getMock('\\Cake\\ORM\\Table', ['delete', 'find'], [['alias' => 'ArticlesTags', 'connection' => $connection]]);
     $config = ['sourceTable' => $this->article, 'targetTable' => $this->tag, 'through' => $joint, 'joinTable' => 'tags_articles'];
     $assoc = new BelongsToMany('Test', $config);
     $assoc->junction()->association('tags')->conditions(['foo' => 1]);
     $joint->expects($this->never())->method('find');
     $opts = ['markNew' => false];
     $jointEntities = [new Entity(['article_id' => 1, 'tag_id' => 2]), new Entity(['article_id' => 1, 'tag_id' => 3])];
     $tags = [new Entity(['id' => 2, '_joinData' => $jointEntities[0]], $opts), new Entity(['id' => 3, '_joinData' => $jointEntities[1]], $opts)];
     $entity = new Entity(['id' => 1, 'test' => $tags], $opts);
     $joint->expects($this->at(0))->method('delete')->with($jointEntities[0]);
     $joint->expects($this->at(1))->method('delete')->with($jointEntities[1]);
     $assoc->unlink($entity, $tags, false);
     $this->assertEquals($tags, $entity->get('test'));
 }