Exemplo n.º 1
0
 public function testReferenceOneDifferentTargetDocuments()
 {
     $ref1 = new MODEL\RefType1TestObj();
     $ref1->id = '/functional/ref1';
     $ref1->name = 'Ref1';
     $ref2 = new MODEL\RefType2TestObj();
     $ref2->id = '/functional/ref2';
     $ref2->name = 'Ref2';
     $this->dm->persist($ref1);
     $this->dm->persist($ref2);
     $referer1 = new ReferenceOneObj();
     $referer1->id = '/functional/referer1';
     $referer1->reference = $ref1;
     $this->dm->persist($referer1);
     $referer2 = new ReferenceOneObj();
     $referer2->id = '/functional/referer2';
     $referer2->reference = $ref2;
     $this->dm->persist($referer2);
     $this->dm->flush();
     $this->dm->clear();
     $referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer1');
     $this->assertTrue($referer->reference instanceof MODEL\RefType1TestObj);
     $referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer2');
     $this->assertTrue($referer->reference instanceof MODEL\RefType2TestObj);
 }
 public function setUp()
 {
     $this->db('PHPCR')->loadFixtures(array('Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\DataFixtures\\PHPCR\\LoadData'));
     $this->dm = $this->db('PHPCR')->getOm();
     $this->document = $this->dm->find(null, '/test/doc');
     $this->assertNotNull($this->document, 'fixture loading not working');
     $this->referrer = $this->dm->find(null, '/test/ref');
     $this->assertNotNull($this->referrer, 'fixture loading not working');
 }
Exemplo n.º 3
0
 public function testFind()
 {
     $doc = $this->dm->find($this->type, '/functional/thename');
     $this->assertInstanceOf($this->type, $doc);
     $this->assertEquals('/functional/thename', $doc->id);
     $this->assertEquals('thename', $doc->nodename);
     $this->assertNotNull($doc->parent);
     $this->assertEquals('/functional', $doc->parent->getId());
     return $doc;
 }
Exemplo n.º 4
0
 public function testPropertyname()
 {
     $doc = new PropertyTestObj();
     $doc->id = '/functional/p';
     $doc->string = 'astring';
     $doc->long = 123;
     $doc->int = 321;
     $doc->decimal = '343';
     $doc->double = 3.14;
     $doc->float = 2.8;
     $date = new \DateTime();
     $doc->date = $date;
     $doc->boolean = true;
     $doc->name = 'aname';
     $doc->path = '../';
     $doc->uri = 'http://cmf.symfony.com:8080/about.html#there';
     $this->dm->persist($doc);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertTrue($this->node->getNode('p')->hasProperty('string'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('long'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('int'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('decimal'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('double'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('float'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('date'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('boolean'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('name'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('path'));
     $this->assertTrue($this->node->getNode('p')->hasProperty('uri'));
     $doc = $this->dm->find($this->type, '/functional/p');
     $this->assertNotNull($doc->string);
     $this->assertEquals('astring', $doc->string);
     $this->assertNotNull($doc->long);
     $this->assertEquals(123, $doc->long);
     $this->assertNotNull($doc->int);
     $this->assertEquals(321, $doc->int);
     $this->assertNotNull($doc->decimal);
     $this->assertEquals('343', $doc->decimal);
     $this->assertNotNull($doc->double);
     $this->assertEquals(3.14, $doc->double);
     $this->assertNotNull($doc->float);
     $this->assertEquals(2.8, $doc->float);
     $this->assertNotNull($doc->date);
     $this->assertEquals($date->getTimestamp(), $doc->date->getTimestamp());
     $this->assertNotNull($doc->boolean);
     $this->assertEquals(true, $doc->boolean);
     $this->assertNotNull($doc->name);
     $this->assertEquals('aname', $doc->name);
     $this->assertNotNull($doc->path);
     $this->assertEquals('../', $doc->path);
     $this->assertNotNull($doc->uri);
     $this->assertEquals('http://cmf.symfony.com:8080/about.html#there', $doc->uri);
 }
Exemplo n.º 5
0
 public function testCreatedDate()
 {
     $parent = new FileTestObj();
     $parent->file = new File();
     $parent->id = '/functional/filetest';
     $parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
     $this->dm->persist($parent);
     $this->dm->flush();
     $this->dm->clear();
     $file = $this->dm->find('Doctrine\\ODM\\PHPCR\\Document\\File', '/functional/filetest/file');
     $this->assertNotNull($file);
     $this->assertNotNull($file->getCreated());
 }
Exemplo n.º 6
0
 public function testReorderChildren()
 {
     $this->testModifyChildren();
     try {
         $parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
         $this->assertCount(2, $parent->allChildren);
         $data = array('child-g' => $parent->allChildren->last(), 'child-f' => $parent->allChildren->first());
         $parent->allChildren = new ArrayCollection($data);
         $this->dm->flush();
         $this->dm->clear();
         $parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
         $this->assertCount(count($data), $parent->allChildren);
         $this->assertEquals(array_keys($data), $parent->allChildren->getKeys());
         $child1 = new ChildrenTestObj();
         $child1->name = 'Child H';
         $child2 = new ChildrenTestObj();
         $child2->name = 'Child I';
         $child3 = new ChildrenTestObj();
         $child3->name = 'Child J';
         $data = array('child-i' => $child2, 'child-h' => $child1, 'child-f' => $parent->allChildren->last(), 'child-g' => $parent->allChildren->first(), 'child-j' => $child3);
         $parent->allChildren = new ArrayCollection($data);
         $this->dm->flush();
         $this->dm->clear();
         $parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
         $this->assertCount(count($data), $parent->allChildren);
         $this->assertEquals(array_keys($data), $parent->allChildren->getKeys());
     } catch (UnsupportedRepositoryOperationException $e) {
         $this->markTestSkipped('Reordering of children not supported');
     }
 }
Exemplo n.º 7
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testDetachWithRemove()
 {
     $user = $this->dm->find($this->type, '/functional/user');
     $user->username = "******";
     $this->dm->detach($user);
     $this->dm->remove($user);
 }
Exemplo n.º 8
0
 public function testAddRemoveAttachment()
 {
     $fh = fopen(__DIR__ . '/_files/logo.jpg', 'r');
     $user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'user_with_attachment');
     $user->attachments['logo.jpg'] = Attachment::createFromBinaryData($fh, 'image/jpeg');
     $this->dm->flush();
     $this->dm->clear();
     // dont re-use identity map
     $user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'user_with_attachment');
     unset($user->attachments['foo.txt']);
     $this->dm->flush();
     $this->dm->clear();
     // dont re-use identity map
     $user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'user_with_attachment');
     $this->assertArrayHasKey('logo.jpg', $user->attachments);
     $this->assertArrayNotHasKey('foo.txt', $user->attachments);
 }
Exemplo n.º 9
0
 public function testPropertyname()
 {
     $doc = new TestObj();
     $doc->id = '/functional/pn';
     $doc->name = 'Testname';
     $doc->othername = 'Testothername';
     $this->dm->persist($doc);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertTrue($this->node->getNode('pn')->hasProperty('name'));
     $this->assertTrue($this->node->getNode('pn')->hasProperty('myname'));
     $doc = $this->dm->find($this->type, '/functional/pn');
     $this->assertNotNull($doc->name);
     $this->assertEquals('Testname', $doc->name);
     $this->assertNotNull($doc->othername);
     $this->assertEquals('Testothername', $doc->othername);
 }
Exemplo n.º 10
0
 function testProxyForChildIsUsed()
 {
     $doc = $this->dm->find($this->type, '/functional/thename');
     $doc->child = new NameDoc();
     $this->dm->flush();
     $this->dm->clear();
     $doc = $this->dm->find($this->type, '/functional/thename');
     $this->assertTrue($doc->child instanceof Proxy);
 }
Exemplo n.º 11
0
 function testChildOfRoot()
 {
     $root = $this->dm->find(null, '/');
     $child = new NameDoc();
     $child->parent = $root;
     $child->nodename = 'childOfRoot';
     $this->dm->persist($child);
     $this->dm->flush();
     $this->assertEquals('/childOfRoot', $child->id);
 }
Exemplo n.º 12
0
 public function testRemoveChildParent()
 {
     $parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
     $this->assertCount(4, $parent->allChildren);
     $this->dm->remove($parent);
     $this->dm->flush();
     $this->dm->clear();
     $parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
     $this->assertNull($parent);
 }
Exemplo n.º 13
0
 public function testRemoveThenMove()
 {
     $this->dm->clear();
     $user = $this->dm->find($this->type, '/functional/lsmith');
     $this->assertNotNull($user, 'User must exist');
     $this->dm->remove($user);
     $this->dm->move($user, '/functional/user2');
     $this->dm->flush();
     $user = $this->dm->find($this->type, '/functional/user2');
     $this->assertNotNull($user, 'User must exist');
     $user = $this->dm->find($this->type, '/functional/lsmith');
     $this->assertNull($user, 'User must be null after deletion');
 }
Exemplo n.º 14
0
 public function testFlushSingleManagedDocument()
 {
     $user = new CmsUser();
     $user->name = 'Dominik';
     $user->username = '******';
     $user->status = 'developer';
     $this->dm->persist($user);
     $this->dm->flush();
     $user->status = 'administrator';
     $this->dm->flush($user);
     $this->dm->clear();
     $user = $this->dm->find(get_class($user), $user->id);
     $this->assertEquals('administrator', $user->status);
 }
Exemplo n.º 15
0
 public function testCascadeManagedDocumentReferenceDuringFlush()
 {
     $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
     $article->text = "foo";
     $article->topic = "bar";
     $this->dm->persist($article);
     $user = new \Doctrine\Tests\Models\CMS\CmsUser();
     $user->username = "******";
     $user->name = "Benjamin";
     $article->user = $user;
     $this->assertFalse($this->dm->contains($user));
     $this->dm->flush();
     $this->dm->clear();
     $article = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsArticle', $article->id);
     $this->assertEquals($user->id, $article->user->getId());
 }
Exemplo n.º 16
0
 public function testRemoveVersion()
 {
     $doc = $this->dm->find($this->type, '/functional/versionTestObj');
     $this->dm->checkpoint($doc);
     $linearVersionHistory = $this->dm->getAllLinearVersions($doc);
     $lastVersion = end($linearVersionHistory);
     $lastVersionName = $lastVersion['name'];
     // Create a new version so that we are not trying to remove the last version
     $this->dm->checkpoint($doc);
     // Remove the version
     $version = $this->dm->findVersionByName($this->type, '/functional/versionTestObj', $lastVersionName);
     $removedVersionPath = $version->id;
     $this->dm->removeVersion($version);
     // Check it's not in the history anymore
     $this->assertFalse($this->dm->getPhpcrSession()->nodeExists(dirname($removedVersionPath)));
     return $lastVersionName;
 }
Exemplo n.º 17
0
 public function testKeepTrackOfUnmappedData()
 {
     $httpClient = $this->dm->getHttpClient();
     $data = array('_id' => "2", 'username' => 'beberlei', 'email' => '*****@*****.**', 'address' => array('city' => 'Bonn', 'country' => 'DE'), 'type' => str_replace("\\", ".", $this->type));
     $resp = $httpClient->request('PUT', '/' . $this->dm->getDatabase() . '/2', json_encode($data));
     $this->assertEquals(201, $resp->status);
     $user = $this->dm->find($this->type, 2);
     $this->assertInstanceOf($this->type, $user);
     $this->assertEquals('beberlei', $user->username);
     $user->username = '******';
     $this->dm->flush();
     $resp = $httpClient->request('GET', '/' . $this->dm->getDatabase() . '/2');
     $this->assertEquals(200, $resp->status);
     $data['username'] = '******';
     ksort($resp->body);
     ksort($data);
     unset($resp->body['_rev']);
     $this->assertEquals($data, $resp->body);
 }
Exemplo n.º 18
0
 public function testChildOfReference()
 {
     $referrerTestObj = new ChildReferrerTestObj();
     $referrerTestObj->id = "/functional/referrerTestObj";
     $referrerTestObj->name = "referrerTestObj";
     $refererenceableTestObj = new ChildReferenceableTestObj();
     $refererenceableTestObj->id = "/functional/referenceableTestObj";
     $refererenceableTestObj->name = "referenceableTestObj";
     $referrerTestObj->reference = $refererenceableTestObj;
     $this->dm->persist($referrerTestObj);
     $ChildTestObj = new ChildTestObj();
     $ChildTestObj->id = "/functional/referenceableTestObj/test";
     $ChildTestObj->name = "childTestObj";
     $this->dm->persist($ChildTestObj);
     $this->dm->flush();
     $this->dm->clear();
     $referrer = $this->dm->find(null, "/functional/referrerTestObj");
     $this->assertEquals($referrer->reference->aChild->name, "childTestObj");
 }
Exemplo n.º 19
0
 public function testNoIdProperty()
 {
     $functional = $this->dm->find(null, '/functional');
     $user = new User5();
     $user->username = "******";
     $user->numbers = array(1, 2, 3);
     $user->nodename = 'test';
     $user->parent = $functional;
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $userNew = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\User4', '/functional/test');
     $userNew->username = "******";
     $this->dm->flush();
     $userNew = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\User4', '/functional/test');
     $this->assertNotNull($userNew, "Have to hydrate user object!");
     $this->assertEquals('test2', $userNew->username);
     $this->assertEquals($user->numbers->toArray(), $userNew->numbers->toArray());
 }