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 testLuceneIndexing() { $this->dm->getConfiguration()->addDesignDocument('lucene_users', 'Doctrine\\Tests\\ODM\\CouchDB\\Functional\\LuceneQueryDesignDoc', array()); $query = $this->dm->createLuceneQuery('lucene_users', 'by_name'); $response = $query->createDesignDocument(); $user1 = new \Doctrine\Tests\Models\CMS\CmsUser(); $user1->username = "******"; $user1->status = "active"; $user1->name = "Benjamin"; $user2 = new \Doctrine\Tests\Models\CMS\CmsUser(); $user2->username = "******"; $user2->status = "active"; $user2->name = "Lukas"; $this->dm->persist($user1); $this->dm->persist($user2); $this->dm->flush(); $query->setQuery("Lukas"); try { $result = $query->execute(); } catch (\Doctrine\CouchDB\HTTP\HTTPException $e) { if ($e->getCode() == 404) { $this->markTestSkipped("Lucene is not integrated"); } else { throw $e; } } $this->assertEquals(1, count($result)); foreach ($result as $user) { $this->assertEquals($user2->id, $user['id']); $this->assertEquals(1, $user['score']); } $query->setIncludeDocs(true)->setDocumentName('Doctrine\\Tests\\Models\\CMS\\CmsUser'); $result = $query->execute(); $this->assertSame($user2, $result[0]['doc']); }
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); }
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()); }
public function testCreateFromFile() { $parent = new FixPHPCR1TestObj(); $parent->id = '/functional/filetest'; $this->dm->persist($parent); $parent->file = new File(); $parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt'); $this->dm->flush(); $this->dm->clear(); $this->assertTrue($this->node->getNode('filetest')->hasNode('file')); $this->assertTrue($this->node->getNode('filetest')->getNode('file')->hasNode('jcr:content')); $this->assertTrue($this->node->getNode('filetest')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data')); }
public function testMoveWithChild() { $this->dm->clear(); $user1 = $this->dm->find($this->type, '/functional/lsmith'); $this->assertNotNull($user1, 'User must exist'); $user2 = new CmsTeamUser(); $user2->username = '******'; $user2->parent = $user1; $user3 = new CmsTeamUser(); $user3->username = '******'; $user3->parent = $user2; $this->dm->persist($user3); $this->dm->flush(); $user1 = $this->dm->find($this->type, '/functional/lsmith'); $this->dm->move($user1, '/functional/user2'); $this->dm->flush(); $this->dm->clear(); $user1 = $this->dm->find($this->type, '/functional/user2'); $user = $this->dm->find($this->type, '/functional/user2'); $this->assertNotNull($user, 'User must exist'); $user = $this->dm->find($this->type, '/functional/user2/jwage'); $this->assertNotNull($user, 'User must exist'); $user = $this->dm->find($this->type, '/functional/user2/jwage/beberlei'); $this->assertNotNull($user, 'User must exist'); $this->dm->move($user1, '/functional/lsmith'); $this->dm->flush(); $user = $this->dm->find($this->type, '/functional/lsmith'); $this->assertNotNull($user, 'User must exist'); $user = $this->dm->find($this->type, '/functional/lsmith/jwage'); $this->assertNotNull($user, 'User must exist'); $user = $this->dm->find($this->type, '/functional/lsmith/jwage/beberlei'); $this->assertNotNull($user, 'User must exist'); }
/** * @expectedException \InvalidArgumentException */ public function testDetachWithPerist() { $user = $this->dm->find($this->type, '/functional/user'); $user->username = "******"; $this->dm->detach($user); $this->dm->persist($user); }
public function testCascadeRemoveSingleDocument() { $user = new \Doctrine\Tests\Models\CMS\CmsUser(); $user->username = "******"; $user->name = "Benjamin"; $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); $article->text = "foo"; $article->topic = "bar"; $article->user = $user; $this->dm->persist($article); $this->dm->persist($user); $this->dm->flush(); $this->dm->remove($article); $this->dm->flush(); $this->assertFalse($this->dm->contains($user)); $this->assertFalse($this->dm->contains($article)); }
public function testSecoundLevelOverwrite() { $localePrefs = array('en' => array('en', 'de'), 'de' => array('de', 'en')); $this->dm->setLocaleChooserStrategy(new LocaleChooser($localePrefs, 'en')); $secondTrans = new SecondLevelWithDuplicateOverwrite(); $secondTrans->id = '/functional/secondTrans'; $secondTrans->text = 'deutsch'; $this->dm->persist($secondTrans); $this->dm->bindTranslation($secondTrans, 'de'); $secondTrans->text = 'english'; $this->dm->bindTranslation($secondTrans, 'en'); $this->dm->flush(); $tmpDocDe = $this->dm->findTranslation(null, '/functional/secondTrans', 'de'); $this->assertEquals($tmpDocDe->text, 'deutsch'); $tmpDocEn = $this->dm->findTranslation(null, '/functional/secondTrans', 'en'); $this->assertEquals($tmpDocEn->text, 'english'); }
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); }
public function testCascadeRemoveReferrer() { $user = new \Doctrine\Tests\Models\CMS\CmsUser(); $user->username = '******'; $user->name = 'Benjamin'; $this->dm->persist($user); $this->dm->flush(); $this->dm->flush(); }
public function testCascadeRefresh() { $group1 = new \Doctrine\Tests\Models\CMS\CmsGroup(); $group1->name = "Test!"; $user = new \Doctrine\Tests\Models\CMS\CmsUser(); $user->username = "******"; $user->name = "Benjamin"; $user->addGroup($group1); $this->dm->persist($user); $this->dm->persist($group1); $this->dm->flush(); $this->assertEquals(1, count($user->groups)); $group1->name = "Test2"; $user->username = "******"; $this->dm->refresh($user); $this->assertEquals("beberlei", $user->username); $this->assertEquals("Test!", $group1->name); }
public function testCreateCascade() { $folder = new Folder(); $folder->setId('/functional/folder'); $file = new File(); $file->setFileContent('Lorem ipsum dolor sit amet'); $file->setNodename('file'); $folder->addChild($file); $this->dm->persist($folder); $this->dm->flush(); $this->dm->clear(); $this->assertTrue($this->node->hasNode('folder')); $this->assertTrue($this->node->getNode('folder')->hasNode('file')); $this->assertTrue($this->node->getNode('folder')->getNode('file')->hasNode('jcr:content')); $this->assertTrue($this->node->getNode('folder')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data')); $binaryStream = $this->node->getNode('folder')->getNode('file')->getNode('jcr:content')->getProperty('jcr:data')->getBinary(); $content = stream_get_contents($binaryStream); $this->assertEquals('Lorem ipsum dolor sit amet', $content); }
/** * @expectedException InvalidArgumentException */ public function testPersistVersionError() { $doc = $this->dm->find($this->type, '/functional/versionTestObj'); $this->dm->checkpoint($doc); $linearVersionHistory = $this->dm->getAllLinearVersions($doc); $lastVersion = end($linearVersionHistory); $lastVersionName = $lastVersion['name']; $frozenDocument = $this->dm->findVersionByName($this->type, '/functional/versionTestObj', $lastVersionName); $this->dm->persist($frozenDocument); }
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); }
public function save(AbstractEntity $entity) { if ($entity->getStorageStructure() == AbstractEntity::DOCUMENT) { $dm = new DocumentManager(); $document = $entity->toDocument(); $dm->persist($document); } if ($entity->getStorageStructure() == AbstractEntity::RELATIONAL) { $rm = new RecordManager(); $record = $entity->toRecord(); $rm->save($record); } }
public function testFindByManyConstraints() { for ($i = 0; $i < 10; $i++) { $user = new \Doctrine\Tests\Models\CMS\CmsUser(); $user->username = "******" . $i; $user->status = $i % 2 == 0 ? "active" : "inactive"; $user->name = "Benjamin" . $i; $this->dm->persist($user); } $this->dm->flush(); $users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findBy(array('username' => 'beberlei0')); $this->assertEquals(1, count($users)); $this->assertEquals('beberlei0', $users[0]->username); }
public function testFindByReusesIdentities() { $this->dm = $this->createDocumentManager(); $user = new \Doctrine\Tests\Models\CMS\CmsUser(); $user->username = "******"; $user->status = "active"; $user->name = "Benjamin"; $this->dm->persist($user); $this->dm->flush(); $this->dm->clear(); $user1 = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => 'beberlei')); $user2 = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => 'beberlei')); $this->assertSame($user1, $user2); }
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()); }
public function testProxyIsIgnored() { $user = new CmsUser(); $user->name = 'Dominik'; $user->username = '******'; $user->status = 'developer'; $this->dm->persist($user); $this->dm->flush(); $this->dm->clear(); $user = $this->dm->getReference(get_class($user), $user->id); $otherUser = new CmsUser(); $otherUser->name = 'Dominik2'; $otherUser->username = '******'; $otherUser->status = 'developer'; $this->dm->persist($otherUser); $this->dm->flush($user); $this->assertTrue($this->dm->contains($otherUser), "Other user is contained in DocumentManager"); $this->assertTrue($otherUser->id != null, "other user has no id"); }
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"); }
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()); }
public function testInsertGrandchildWithNewParent() { $parent = new NameDoc(); $parent->id = '/functional/parent'; $child = new NameDoc(); $child->parent = $parent; $child->nodename = 'child'; $parent->children = array($child); # the granchild document $grandchild = new NameDoc(); $grandchild->parent = $child; $grandchild->nodename = 'grandchild'; $child->children = array($grandchild); $this->dm->persist($child); $this->dm->flush(); $this->assertTrue($this->node->getNode('parent')->hasNode('child')); $this->assertEquals('/functional/parent/child', $child->id); $this->assertTrue($this->node->getNode('parent')->getNode('child')->hasNode('grandchild')); $this->assertEquals('/functional/parent/child/grandchild', $grandchild->id); }
public function testCreateChildren() { $children = array(); $child = new ChildrenTestObj(); $child->id = '/functional/parent/child-a/child-create-1'; $child->name = 'Child A'; $children[] = $child; $child = new ChildrenTestObj(); $child->id = '/functional/parent/child-a/child-create-2'; $child->name = 'Child B'; $children[] = $child; $parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent/child-a'); $this->assertCount(0, $parent->allChildren); $parent->allChildren = $children; $this->dm->persist($parent); $this->dm->flush(); $this->dm->clear(); $parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent/child-a'); $this->assertCount(2, $parent->allChildren); }
public function testInsertUpdateMultiple() { $user1 = $this->dm->find($this->type, 1); $user1->username = "******"; $user2 = new User(); $user2->id = "myuser-1111"; $user2->username = "******"; $user3 = new User(); $user3->id = "myuser-2222"; $user3->username = "******"; $this->dm->persist($user2); $this->dm->persist($user3); $this->dm->flush(); $this->dm->clear(); $pUser1 = $this->dm->find($this->type, 1); $pUser2 = $this->dm->find($this->type, 'myuser-1111'); $pUser3 = $this->dm->find($this->type, 'myuser-2222'); $this->assertEquals('new-name', $pUser1->username); $this->assertEquals('myuser-1111', $pUser2->id); $this->assertEquals('myuser-2222', $pUser3->id); }