Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DDC-1545 #229

Merged
merged 2 commits into from over 2 years ago

2 participants

Bernhard Schussek Alexander
Alexander
Collaborator

Fix was already provided here a8478d5.

Alexander asm89 merged commit 108cb53 into from December 19, 2011
Alexander asm89 closed this December 19, 2011
elHornair elHornair referenced this pull request from a commit February 22, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Dec 18, 2011
Bernhard Schussek Added test case for DDC-1545 9b87749
Dec 19, 2011
Bernhard Schussek Fixed class name of test for DDC-1545 e035fe7
This page is out of date. Refresh to see the latest.
203  tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php
... ...
@@ -0,0 +1,203 @@
  1
+<?php
  2
+
  3
+namespace Doctrine\Tests\ORM\Functional\Ticket;
  4
+
  5
+use Doctrine\Tests\Models\Qelista\User;
  6
+
  7
+use Doctrine\Tests\Models\Qelista\ShoppingList;
  8
+
  9
+use Doctrine\Common\Collections\ArrayCollection;
  10
+use Doctrine\Tests\Models\CMS\CmsComment;
  11
+use Doctrine\Tests\Models\CMS\CmsArticle;
  12
+use Doctrine\Tests\Models\CMS\CmsUser;
  13
+require_once __DIR__ . '/../../../TestInit.php';
  14
+
  15
+/**
  16
+ * @group DDC-1545
  17
+ */
  18
+class DDC1545Test extends \Doctrine\Tests\OrmFunctionalTestCase
  19
+{
  20
+    private $articleId;
  21
+
  22
+    private $userId;
  23
+
  24
+    private $user2Id;
  25
+
  26
+    public function setUp()
  27
+    {
  28
+        $this->useModelSet('cms');
  29
+        parent::setUp();
  30
+    }
  31
+
  32
+    private function initDb($link)
  33
+    {
  34
+        $article = new CmsArticle();
  35
+        $article->topic = 'foo';
  36
+        $article->text = 'foo';
  37
+
  38
+        $user = new CmsUser();
  39
+        $user->status = 'foo';
  40
+        $user->username = 'foo';
  41
+        $user->name = 'foo';
  42
+
  43
+        $user2 = new CmsUser();
  44
+        $user2->status = 'bar';
  45
+        $user2->username = 'bar';
  46
+        $user2->name = 'bar';
  47
+
  48
+        if ($link) {
  49
+            $article->user = $user;
  50
+        }
  51
+
  52
+        $this->_em->persist($article);
  53
+        $this->_em->persist($user);
  54
+        $this->_em->persist($user2);
  55
+        $this->_em->flush();
  56
+        $this->_em->clear();
  57
+
  58
+        $this->articleId = $article->id;
  59
+        $this->userId = $user->id;
  60
+        $this->user2Id = $user2->id;
  61
+    }
  62
+
  63
+    public function testLinkObjects()
  64
+    {
  65
+        $this->initDb(false);
  66
+
  67
+        // don't join association
  68
+        $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId);
  69
+
  70
+        $user = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->userId);
  71
+
  72
+        $article->user = $user;
  73
+
  74
+        $this->_em->flush();
  75
+        $this->_em->clear();
  76
+
  77
+        $article = $this->_em
  78
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  79
+            ->setParameter('id', $this->articleId)
  80
+            ->getOneOrNullResult();
  81
+
  82
+        $this->assertNotNull($article->user);
  83
+        $this->assertEquals($user->id, $article->user->id);
  84
+    }
  85
+
  86
+    public function testLinkObjectsWithAssociationLoaded()
  87
+    {
  88
+        $this->initDb(false);
  89
+
  90
+        // join association
  91
+        $article = $this->_em
  92
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  93
+            ->setParameter('id', $this->articleId)
  94
+            ->getOneOrNullResult();
  95
+
  96
+        $user = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->userId);
  97
+
  98
+        $article->user = $user;
  99
+
  100
+        $this->_em->flush();
  101
+        $this->_em->clear();
  102
+
  103
+        $article = $this->_em
  104
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  105
+            ->setParameter('id', $this->articleId)
  106
+            ->getOneOrNullResult();
  107
+
  108
+        $this->assertNotNull($article->user);
  109
+        $this->assertEquals($user->id, $article->user->id);
  110
+    }
  111
+
  112
+    public function testUnlinkObjects()
  113
+    {
  114
+        $this->initDb(true);
  115
+
  116
+        // don't join association
  117
+        $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId);
  118
+
  119
+        $article->user = null;
  120
+
  121
+        $this->_em->flush();
  122
+        $this->_em->clear();
  123
+
  124
+        $article = $this->_em
  125
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  126
+            ->setParameter('id', $this->articleId)
  127
+            ->getOneOrNullResult();
  128
+
  129
+        $this->assertNull($article->user);
  130
+    }
  131
+
  132
+    public function testUnlinkObjectsWithAssociationLoaded()
  133
+    {
  134
+        $this->initDb(true);
  135
+
  136
+        // join association
  137
+        $article = $this->_em
  138
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  139
+            ->setParameter('id', $this->articleId)
  140
+            ->getOneOrNullResult();
  141
+
  142
+        $article->user = null;
  143
+
  144
+        $this->_em->flush();
  145
+        $this->_em->clear();
  146
+
  147
+        $article = $this->_em
  148
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  149
+            ->setParameter('id', $this->articleId)
  150
+            ->getOneOrNullResult();
  151
+
  152
+        $this->assertNull($article->user);
  153
+    }
  154
+
  155
+    public function testChangeLink()
  156
+    {
  157
+        $this->initDb(false);
  158
+
  159
+        // don't join association
  160
+        $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId);
  161
+
  162
+        $user2 = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->user2Id);
  163
+
  164
+        $article->user = $user2;
  165
+
  166
+        $this->_em->flush();
  167
+        $this->_em->clear();
  168
+
  169
+        $article = $this->_em
  170
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  171
+            ->setParameter('id', $this->articleId)
  172
+            ->getOneOrNullResult();
  173
+
  174
+        $this->assertNotNull($article->user);
  175
+        $this->assertEquals($user2->id, $article->user->id);
  176
+    }
  177
+
  178
+    public function testChangeLinkWithAssociationLoaded()
  179
+    {
  180
+        $this->initDb(false);
  181
+
  182
+        // join association
  183
+        $article = $this->_em
  184
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  185
+            ->setParameter('id', $this->articleId)
  186
+            ->getOneOrNullResult();
  187
+
  188
+        $user2 = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->user2Id);
  189
+
  190
+        $article->user = $user2;
  191
+
  192
+        $this->_em->flush();
  193
+        $this->_em->clear();
  194
+
  195
+        $article = $this->_em
  196
+            ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id')
  197
+            ->setParameter('id', $this->articleId)
  198
+            ->getOneOrNullResult();
  199
+
  200
+        $this->assertNotNull($article->user);
  201
+        $this->assertEquals($user2->id, $article->user->id);
  202
+    }
  203
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.