2010-08-07 21:33:54 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117ArticleDetails;
|
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117Article;
|
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117Reference;
|
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117Translation;
|
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117ApproveChanges;
|
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117Editor;
|
2013-04-29 12:29:58 +04:00
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117Link;
|
2011-01-01 20:17:19 +03:00
|
|
|
|
2010-08-07 21:33:54 +04:00
|
|
|
require_once __DIR__ . '/../../../TestInit.php';
|
|
|
|
|
|
|
|
class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
2010-08-08 12:46:01 +04:00
|
|
|
private $article1;
|
|
|
|
private $article2;
|
|
|
|
private $reference;
|
|
|
|
private $translation;
|
|
|
|
private $articleDetails;
|
|
|
|
|
2010-08-07 21:33:54 +04:00
|
|
|
protected function setUp() {
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->useModelSet('ddc117');
|
2010-08-07 21:33:54 +04:00
|
|
|
parent::setUp();
|
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->article1 = new DDC117Article("Foo");
|
|
|
|
$this->article2 = new DDC117Article("Bar");
|
|
|
|
|
|
|
|
$this->_em->persist($this->article1);
|
|
|
|
$this->_em->persist($this->article2);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
2013-04-29 12:29:58 +04:00
|
|
|
$link = new DDC117Link($this->article1, $this->article2, "Link-Description");
|
|
|
|
$this->_em->persist($link);
|
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->reference = new DDC117Reference($this->article1, $this->article2, "Test-Description");
|
|
|
|
$this->_em->persist($this->reference);
|
|
|
|
|
|
|
|
$this->translation = new DDC117Translation($this->article1, "en", "Bar");
|
|
|
|
$this->_em->persist($this->translation);
|
|
|
|
|
|
|
|
$this->articleDetails = new DDC117ArticleDetails($this->article1, "Very long text");
|
|
|
|
$this->_em->persist($this->articleDetails);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$this->_em->clear();
|
2010-08-07 21:33:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testAssociationOnlyCompositeKey()
|
|
|
|
{
|
2010-08-08 12:46:01 +04:00
|
|
|
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$mapRef = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria);
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $mapRef);
|
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $mapRef->target());
|
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $mapRef->source());
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->assertSame($mapRef, $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria));
|
2010-08-07 21:33:54 +04:00
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = "SELECT r, s FROM "."Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE r.source = ?1";
|
2010-08-08 21:46:45 +04:00
|
|
|
$dqlRef = $this->_em->createQuery($dql)->setParameter(1, 1)->getSingleResult();
|
|
|
|
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $mapRef);
|
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $mapRef->target());
|
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $mapRef->source());
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->assertSame($dqlRef, $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria));
|
2010-08-08 21:46:45 +04:00
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = "SELECT r, s FROM "."Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1";
|
2010-08-08 21:46:45 +04:00
|
|
|
$dqlRef = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getSingleResult();
|
|
|
|
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $dqlRef);
|
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $dqlRef->target());
|
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $dqlRef->source());
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->assertSame($dqlRef, $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria));
|
2010-08-15 16:40:06 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = "SELECT r, s FROM "."Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1";
|
2010-08-15 20:58:25 +04:00
|
|
|
$dqlRef = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getSingleResult();
|
|
|
|
|
|
|
|
$this->_em->contains($dqlRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
2013-03-11 04:08:58 +04:00
|
|
|
public function testUpdateAssociationEntity()
|
2010-08-15 20:58:25 +04:00
|
|
|
{
|
|
|
|
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$mapRef = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria);
|
2010-08-15 21:15:34 +04:00
|
|
|
$this->assertNotNull($mapRef);
|
2010-08-15 20:58:25 +04:00
|
|
|
$mapRef->setDescription("New Description!!");
|
2010-08-15 16:40:06 +04:00
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$mapRef = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria);
|
2010-08-15 20:58:25 +04:00
|
|
|
|
|
|
|
$this->assertEquals('New Description!!', $mapRef->getDescription());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testFetchDql()
|
|
|
|
{
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = "SELECT r, s FROM "."Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1";
|
2010-08-15 20:58:25 +04:00
|
|
|
$refs = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getResult();
|
2010-08-15 16:40:06 +04:00
|
|
|
|
2010-08-15 20:58:25 +04:00
|
|
|
$this->assertTrue(count($refs) > 0, "Has to contain at least one Reference.");
|
2011-02-20 00:50:58 +03:00
|
|
|
|
2010-08-15 20:58:25 +04:00
|
|
|
foreach ($refs AS $ref) {
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $ref, "Contains only Reference instances.");
|
2010-08-15 20:58:25 +04:00
|
|
|
$this->assertTrue($this->_em->contains($ref), "Contains Reference in the IdentityMap.");
|
|
|
|
}
|
2010-08-08 12:46:01 +04:00
|
|
|
}
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testRemoveCompositeElement()
|
|
|
|
{
|
|
|
|
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$refRep = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria);
|
2010-08-07 23:09:19 +04:00
|
|
|
|
|
|
|
$this->_em->remove($refRep);
|
|
|
|
$this->_em->flush();
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->_em->clear();
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->assertNull($this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria));
|
2010-08-07 21:33:54 +04:00
|
|
|
}
|
|
|
|
|
2010-08-07 22:07:10 +04:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
2010-08-08 12:46:01 +04:00
|
|
|
public function testDqlRemoveCompositeElement()
|
2010-08-07 22:07:10 +04:00
|
|
|
{
|
2010-08-08 12:46:01 +04:00
|
|
|
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
|
2010-08-07 22:07:10 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = "DELETE "."Doctrine\Tests\Models\DDC117\DDC117Reference r WHERE r.source = ?1 AND r.target = ?2";
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->_em->createQuery($dql)
|
|
|
|
->setParameter(1, $this->article1->id())
|
|
|
|
->setParameter(2, $this->article2->id())
|
|
|
|
->execute();
|
2010-08-07 22:07:10 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->assertNull($this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria));
|
2010-08-08 12:46:01 +04:00
|
|
|
}
|
2010-08-07 22:07:10 +04:00
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testInverseSideAccess()
|
|
|
|
{
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->article1 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id());
|
2010-08-07 22:07:10 +04:00
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->assertEquals(1, count($this->article1->references()));
|
2011-02-20 00:50:58 +03:00
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
foreach ($this->article1->references() AS $this->reference) {
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $this->reference);
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->assertSame($this->article1, $this->reference->source());
|
2010-08-07 22:07:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = 'SELECT a, r FROM '. 'Doctrine\Tests\Models\DDC117\DDC117Article a INNER JOIN a.references r WHERE a.id = ?1';
|
2010-08-07 22:07:10 +04:00
|
|
|
$articleDql = $this->_em->createQuery($dql)
|
2010-08-08 12:46:01 +04:00
|
|
|
->setParameter(1, $this->article1->id())
|
2010-08-07 22:07:10 +04:00
|
|
|
->getSingleResult();
|
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->assertEquals(1, count($this->article1->references()));
|
2011-02-20 00:50:58 +03:00
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
foreach ($this->article1->references() AS $this->reference) {
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $this->reference);
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->assertSame($this->article1, $this->reference->source());
|
2010-08-07 22:07:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-07 21:33:54 +04:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testMixedCompositeKey()
|
|
|
|
{
|
2010-08-08 12:46:01 +04:00
|
|
|
$idCriteria = array('article' => $this->article1->id(), 'language' => 'en');
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->translation = $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Translation', $idCriteria);
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $this->translation);
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->assertSame($this->translation, $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Translation', $idCriteria));
|
2010-08-07 21:33:54 +04:00
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = 'SELECT t, a FROM ' . 'Doctrine\Tests\Models\DDC117\DDC117Translation t JOIN t.article a WHERE t.article = ?1 AND t.language = ?2';
|
2010-08-07 21:33:54 +04:00
|
|
|
$dqlTrans = $this->_em->createQuery($dql)
|
2010-08-08 12:46:01 +04:00
|
|
|
->setParameter(1, $this->article1->id())
|
2010-08-07 21:33:54 +04:00
|
|
|
->setParameter(2, 'en')
|
|
|
|
->getSingleResult();
|
|
|
|
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $this->translation);
|
2010-08-08 12:46:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testMixedCompositeKeyViolateUniqueness()
|
|
|
|
{
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->article1 = $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Article', $this->article1->id());
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->article1->addTranslation('en', 'Bar');
|
|
|
|
$this->article1->addTranslation('en', 'Baz');
|
|
|
|
|
2011-11-09 11:17:46 +04:00
|
|
|
$exceptionThrown = false;
|
|
|
|
try {
|
2013-03-11 04:08:58 +04:00
|
|
|
// exception depending on the underlying Database Driver
|
2011-11-09 11:17:46 +04:00
|
|
|
$this->_em->flush();
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
$exceptionThrown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue($exceptionThrown, "The underlying database driver throws an exception.");
|
2010-08-07 21:33:54 +04:00
|
|
|
}
|
2010-08-07 22:07:10 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testOneToOneForeignObjectId()
|
|
|
|
{
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->article1 = new DDC117Article("Foo");
|
|
|
|
$this->_em->persist($this->article1);
|
2010-08-07 22:07:10 +04:00
|
|
|
$this->_em->flush();
|
|
|
|
|
2010-08-08 12:46:01 +04:00
|
|
|
$this->articleDetails = new DDC117ArticleDetails($this->article1, "Very long text");
|
|
|
|
$this->_em->persist($this->articleDetails);
|
2010-08-07 22:07:10 +04:00
|
|
|
$this->_em->flush();
|
2010-08-15 16:40:06 +04:00
|
|
|
|
|
|
|
$this->articleDetails->update("not so very long text!");
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
/* @var $article DDC117Article */
|
|
|
|
$article = $this->_em->find(get_class($this->article1), $this->article1->id());
|
|
|
|
$this->assertEquals('not so very long text!', $article->getText());
|
2010-08-07 22:07:10 +04:00
|
|
|
}
|
2010-12-28 21:05:46 +03:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testOneToOneCascadeRemove()
|
|
|
|
{
|
|
|
|
$article = $this->_em->find(get_class($this->article1), $this->article1->id());
|
|
|
|
$this->_em->remove($article);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$this->assertFalse($this->_em->contains($article->getDetails()));
|
|
|
|
}
|
|
|
|
|
2010-12-28 21:05:46 +03:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testOneToOneCascadePersist()
|
|
|
|
{
|
|
|
|
if (!$this->_em->getConnection()->getDatabasePlatform()->prefersSequences()) {
|
|
|
|
$this->markTestSkipped('Test only works with databases that prefer sequences as ID strategy.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->article1 = new DDC117Article("Foo");
|
|
|
|
|
|
|
|
$this->articleDetails = new DDC117ArticleDetails($this->article1, "Very long text");
|
|
|
|
|
|
|
|
$this->_em->persist($this->article1);
|
|
|
|
$this->_em->flush();
|
|
|
|
}
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2010-08-07 22:07:10 +04:00
|
|
|
/**
|
2011-01-01 20:17:19 +03:00
|
|
|
* @group DDC-117
|
2010-08-08 12:46:01 +04:00
|
|
|
*/
|
2011-01-01 20:17:19 +03:00
|
|
|
public function testReferencesToForeignKeyEntities()
|
2010-08-07 21:33:54 +04:00
|
|
|
{
|
2011-01-01 20:17:19 +03:00
|
|
|
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
|
|
|
|
$reference = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria);
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$idCriteria = array('article' => $this->article1->id(), 'language' => 'en');
|
|
|
|
$translation = $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Translation', $idCriteria);
|
2010-08-07 22:07:10 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$approveChanges = new DDC117ApproveChanges($reference->source()->getDetails(), $reference, $translation);
|
|
|
|
$this->_em->persist($approveChanges);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$approveChanges = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117ApproveChanges", $approveChanges->getId());
|
2010-08-07 22:07:10 +04:00
|
|
|
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', $approveChanges->getArticleDetails());
|
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Reference', $approveChanges->getReference());
|
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $approveChanges->getTranslation());
|
2010-08-07 22:07:10 +04:00
|
|
|
}
|
2010-08-08 12:46:01 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testLoadOneToManyCollectionOfForeignKeyEntities()
|
2010-08-08 12:46:01 +04:00
|
|
|
{
|
2011-01-01 20:17:19 +03:00
|
|
|
/* @var $article DDC117Article */
|
|
|
|
$article = $this->_em->find(get_class($this->article1), $this->article1->id());
|
2010-08-15 16:40:06 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$translations = $article->getTranslations();
|
|
|
|
$this->assertFalse($translations->isInitialized());
|
|
|
|
$this->assertContainsOnly('Doctrine\Tests\Models\DDC117\DDC117Translation', $translations);
|
|
|
|
$this->assertTrue($translations->isInitialized());
|
2010-08-15 16:40:06 +04:00
|
|
|
}
|
2010-08-07 22:07:10 +04:00
|
|
|
|
|
|
|
/**
|
2011-01-01 20:17:19 +03:00
|
|
|
* @group DDC-117
|
2010-08-07 22:07:10 +04:00
|
|
|
*/
|
2011-01-01 20:17:19 +03:00
|
|
|
public function testLoadManyToManyCollectionOfForeignKeyEntities()
|
2010-08-07 22:07:10 +04:00
|
|
|
{
|
2011-01-01 20:17:19 +03:00
|
|
|
$editor = $this->loadEditorFixture();
|
2010-08-07 22:07:10 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->assertFalse($editor->reviewingTranslations->isInitialized());
|
|
|
|
$this->assertContainsOnly("Doctrine\Tests\Models\DDC117\DDC117Translation", $editor->reviewingTranslations);
|
|
|
|
$this->assertTrue($editor->reviewingTranslations->isInitialized());
|
2010-08-15 16:40:06 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->_em->clear();
|
2010-08-15 16:40:06 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = "SELECT e, t FROM Doctrine\Tests\Models\DDC117\DDC117Editor e JOIN e.reviewingTranslations t WHERE e.id = ?1";
|
|
|
|
$editor = $this->_em->createQuery($dql)->setParameter(1, $editor->id)->getSingleResult();
|
|
|
|
$this->assertTrue($editor->reviewingTranslations->isInitialized());
|
|
|
|
$this->assertContainsOnly("Doctrine\Tests\Models\DDC117\DDC117Translation", $editor->reviewingTranslations);
|
2010-08-15 16:40:06 +04:00
|
|
|
}
|
2010-08-07 21:33:54 +04:00
|
|
|
|
|
|
|
/**
|
2011-01-01 20:17:19 +03:00
|
|
|
* @group DDC-117
|
2010-08-07 21:33:54 +04:00
|
|
|
*/
|
2011-01-01 20:17:19 +03:00
|
|
|
public function testClearManyToManyCollectionOfForeignKeyEntities()
|
|
|
|
{
|
|
|
|
$editor = $this->loadEditorFixture();
|
|
|
|
$this->assertEquals(3, count($editor->reviewingTranslations));
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$editor->reviewingTranslations->clear();
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$editor = $this->_em->find(get_class($editor), $editor->id);
|
|
|
|
$this->assertEquals(0, count($editor->reviewingTranslations));
|
|
|
|
}
|
2010-08-07 21:33:54 +04:00
|
|
|
|
|
|
|
/**
|
2011-01-01 20:17:19 +03:00
|
|
|
* @group DDC-117
|
2010-08-07 21:33:54 +04:00
|
|
|
*/
|
2011-01-01 20:17:19 +03:00
|
|
|
public function testLoadInverseManyToManyCollection()
|
2010-08-07 21:33:54 +04:00
|
|
|
{
|
2011-01-01 20:17:19 +03:00
|
|
|
$editor = $this->loadEditorFixture();
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $editor->reviewingTranslations[0]);
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$reviewedBy = $editor->reviewingTranslations[0]->getReviewedByEditors();
|
|
|
|
$this->assertEquals(1, count($reviewedBy));
|
|
|
|
$this->assertSame($editor, $reviewedBy[0]);
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->_em->clear();
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
$dql = "SELECT t, e FROM Doctrine\Tests\Models\DDC117\DDC117Translation t ".
|
|
|
|
"JOIN t.reviewedByEditors e WHERE t.article = ?1 AND t.language = ?2";
|
|
|
|
$trans = $this->_em->createQuery($dql)
|
|
|
|
->setParameter(1, $this->translation->getArticleId())
|
|
|
|
->setParameter(2, $this->translation->getLanguage())
|
|
|
|
->getSingleResult();
|
2010-08-15 16:40:06 +04:00
|
|
|
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $trans);
|
2011-01-01 20:17:19 +03:00
|
|
|
$this->assertContainsOnly('Doctrine\Tests\Models\DDC117\DDC117Editor', $trans->reviewedByEditors);
|
|
|
|
$this->assertEquals(1, count($trans->reviewedByEditors));
|
2010-08-15 16:40:06 +04:00
|
|
|
}
|
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testLoadOneToManyOfSourceEntityWithAssociationIdentifier()
|
2010-08-15 16:40:06 +04:00
|
|
|
{
|
2011-01-01 20:17:19 +03:00
|
|
|
$editor = $this->loadEditorFixture();
|
|
|
|
|
|
|
|
$editor->addLastTranslation($editor->reviewingTranslations[0]);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
$editor = $this->_em->find(get_class($editor), $editor->id);
|
|
|
|
$lastTranslatedBy = $editor->reviewingTranslations[0]->getLastTranslatedBy();
|
|
|
|
$lastTranslatedBy->count();
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($lastTranslatedBy));
|
2010-08-15 16:40:06 +04:00
|
|
|
}
|
2010-08-07 21:33:54 +04:00
|
|
|
|
|
|
|
/**
|
2011-01-01 20:17:19 +03:00
|
|
|
* @return DDC117Editor
|
2010-08-07 21:33:54 +04:00
|
|
|
*/
|
2011-01-01 20:17:19 +03:00
|
|
|
private function loadEditorFixture()
|
|
|
|
{
|
|
|
|
$editor = new DDC117Editor("beberlei");
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
/* @var $article1 DDC117Article */
|
|
|
|
$article1 = $this->_em->find(get_class($this->article1), $this->article1->id());
|
|
|
|
foreach ($article1->getTranslations() AS $translation) {
|
|
|
|
$editor->reviewingTranslations[] = $translation;
|
|
|
|
}
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
/* @var $article2 DDC117Article */
|
|
|
|
$article2 = $this->_em->find(get_class($this->article2), $this->article2->id());
|
|
|
|
$article2->addTranslation("de", "Vanille-Krapferl"); // omnomnom
|
|
|
|
$article2->addTranslation("fr", "Sorry can't speak french!");
|
2010-08-07 21:33:54 +04:00
|
|
|
|
2011-01-01 20:17:19 +03:00
|
|
|
foreach ($article2->getTranslations() AS $translation) {
|
|
|
|
$this->_em->persist($translation); // otherwise persisting the editor won't work, reachability!
|
|
|
|
$editor->reviewingTranslations[] = $translation;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_em->persist($editor);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
return $this->_em->find(get_class($editor), $editor->id);
|
2010-08-07 21:33:54 +04:00
|
|
|
}
|
2011-12-15 23:49:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-1519
|
|
|
|
*/
|
|
|
|
public function testMergeForeignKeyIdentifierEntity()
|
|
|
|
{
|
|
|
|
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
|
|
|
|
|
|
|
|
$refRep = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria);
|
|
|
|
|
|
|
|
$this->_em->detach($refRep);
|
|
|
|
$refRep = $this->_em->merge($refRep);
|
|
|
|
|
|
|
|
$this->assertEquals($this->article1->id(), $refRep->source()->id());
|
|
|
|
$this->assertEquals($this->article2->id(), $refRep->target()->id());
|
|
|
|
}
|
2012-02-20 20:48:34 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-1652
|
|
|
|
*/
|
|
|
|
public function testArrayHydrationWithCompositeKey()
|
|
|
|
{
|
|
|
|
$dql = "SELECT r,s,t FROM Doctrine\Tests\Models\DDC117\DDC117Reference r INNER JOIN r.source s INNER JOIN r.target t";
|
|
|
|
$before = count($this->_em->createQuery($dql)->getResult());
|
|
|
|
|
|
|
|
$this->article1 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id());
|
|
|
|
$this->article2 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article2->id());
|
|
|
|
|
|
|
|
$this->reference = new DDC117Reference($this->article2, $this->article1, "Test-Description");
|
|
|
|
$this->_em->persist($this->reference);
|
|
|
|
|
|
|
|
$this->reference = new DDC117Reference($this->article1, $this->article1, "Test-Description");
|
|
|
|
$this->_em->persist($this->reference);
|
|
|
|
|
|
|
|
$this->reference = new DDC117Reference($this->article2, $this->article2, "Test-Description");
|
|
|
|
$this->_em->persist($this->reference);
|
|
|
|
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$dql = "SELECT r,s,t FROM Doctrine\Tests\Models\DDC117\DDC117Reference r INNER JOIN r.source s INNER JOIN r.target t";
|
|
|
|
$data = $this->_em->createQuery($dql)->getArrayResult();
|
|
|
|
|
|
|
|
$this->assertEquals($before + 3, count($data));
|
|
|
|
}
|
2013-01-20 23:11:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-2246
|
|
|
|
*/
|
|
|
|
public function testGetEntityState()
|
|
|
|
{
|
|
|
|
$this->article1 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id());
|
|
|
|
$this->article2 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article2->id());
|
|
|
|
|
|
|
|
$this->reference = new DDC117Reference($this->article2, $this->article1, "Test-Description");
|
|
|
|
|
|
|
|
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($this->reference));
|
|
|
|
|
|
|
|
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
|
|
|
|
$reference = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria);
|
|
|
|
|
|
|
|
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($reference));
|
|
|
|
}
|
2013-04-29 12:29:58 +04:00
|
|
|
/**
|
|
|
|
* @group DDC-117
|
|
|
|
*/
|
|
|
|
public function testIndexByOnCompositeKeyField()
|
|
|
|
{
|
|
|
|
$article = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id());
|
|
|
|
|
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Article', $article);
|
|
|
|
$this->assertEquals(1, count($article->getLinks()));
|
|
|
|
$this->assertTrue($article->getLinks()->offsetExists($this->article2->id()));
|
|
|
|
}
|
2011-01-01 20:17:19 +03:00
|
|
|
}
|