Пример #1
0
 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'));
 }
Пример #2
0
 /**
  * Test that children are retrieved in the parent locale
  */
 public function testFindTranslationWithUntranslatedChildren()
 {
     $this->dm->persist($this->doc);
     $this->dm->bindTranslation($this->doc, 'en');
     $this->doc->topic = 'Un autre sujet';
     $this->dm->bindTranslation($this->doc, 'fr');
     $this->dm->flush();
     $testNode = $this->node->getNode($this->testNodeName);
     $testNode->addNode('new-comment');
     $this->session->save();
     $this->dm->clear();
     $this->doc = $this->dm->findTranslation($this->class, '/functional/' . $this->testNodeName, 'fr');
     $this->assertEquals('fr', $this->doc->locale);
     $children = $this->doc->getChildren();
     $this->assertCount(1, $children);
     foreach ($children as $comment) {
         $this->assertInstanceOf('Doctrine\\ODM\\PHPCR\\Document\\Generic', $comment);
         $this->assertNull($this->dm->getUnitOfWork()->getCurrentLocale($comment));
     }
     $this->dm->clear();
     $this->doc = $this->dm->findTranslation($this->class, '/functional/' . $this->testNodeName, 'en');
     $children = $this->dm->getChildren($this->doc);
     $this->assertCount(1, $children);
     foreach ($children as $comment) {
         $this->assertInstanceOf('Doctrine\\ODM\\PHPCR\\Document\\Generic', $comment);
         $this->assertNull($this->dm->getUnitOfWork()->getCurrentLocale($comment));
     }
 }
Пример #3
0
 /**
  * Remove the parent node of multiple child level
  */
 public function testRemove3()
 {
     $parent = new ChildTestObj();
     $parent->name = 'Parent';
     $parent->id = '/functional/childtest';
     // Lv1
     $childLv1 = new ChildReferenceableTestObj();
     $childLv1->name = 'Child-Lv1';
     $parent->child = $childLv1;
     // Lv2
     $childLv2 = new ChildChildTestObj();
     $childLv2->name = 'Child-Lv2';
     $childLv1->aChild = $childLv2;
     $this->dm->persist($parent);
     $this->dm->flush();
     $this->dm->clear();
     $parent = $this->dm->find($this->type, '/functional/childtest');
     $this->assertTrue($this->node->hasNode('childtest'));
     $this->assertTrue($this->node->getNode('childtest')->hasNode('test'));
     $this->assertTrue($this->node->getNode('childtest')->getNode('test')->hasNode('test'));
     $this->dm->remove($parent);
     $this->dm->flush();
     $this->dm->clear();
     $parent = $this->dm->find($this->type, '/functional/childtest');
     $this->assertNull($parent);
 }
Пример #4
0
    /**
     * Gets a relative filesystem path based on the repository path, AND
     * creates the file on the filesystem if it's in the repository
     * and not yet on the filesystem.
     * The repository path points to a nt-resource node, whose title
     * should be the filename, and which has a child+property
     * jcr:content/jcr:data where the file data is stored.
     *
     * @param string $path path to the nt-resource node.
     * @return string with a path to the file, relative to the web directory.
     */
    public function getUrl(NodeInterface $node)
    {

        $hasData = false;
        if ($node->hasNode('jcr:content')) {
            $contentNode = $node->getNode('jcr:content');
            if ($contentNode->hasProperty('jcr:data')) {
                $hasData = true;
            }
        }
        if (!$hasData) {
            //TODO: notfound exception is not appropriate ... how to best do this?
            //throw new NotFoundHttpException('no picture found at ' . $node->getPath());
            return 'notfound';
        }

        $path = $node->getPath();
        $relativePath = $this->pathMapper->getUrl($path);
        $fullPath = $this->fileBasePath . $relativePath . $this->getExtension($contentNode);

        if (!file_exists($fullPath)) {
            try {
                $this->saveData($contentNode, $fullPath);
            } catch (Imagine\Exception\Exception $e) {
                //TODO: notfound exception is not appropriate ... how to best do this?
                //throw new NotFoundHttpException('image save to filesystem failed: ' . $e->getMessage());
                return 'notfound';
            }
        }

        return $this->webRelativePath . $relativePath . $this->getExtension($contentNode);
    }
 /**
  * Gets a relative filesystem path based on the repository path, AND
  * creates the file on the filesystem if it's in the repository
  * and not yet on the filesystem.
  * The repository path points to a nt-resource node, whose title
  * should be the filename, and which has a child+property
  * jcr:content/jcr:data where the file data is stored.
  *
  * @param string $path path to the nt-resource node.
  * @return string with a path to the file, relative to the web directory.
  */
 public function getUrl(NodeInterface $node)
 {
     $hasData = false;
     if ($node->hasNode('jcr:content')) {
         $contentNode = $node->getNode('jcr:content');
         if ($contentNode->hasProperty('jcr:data')) {
             $hasData = true;
         }
     }
     if (!$hasData) {
         //TODO: notfound exception is not appropriate ... how to best do this?
         //throw new NotFoundHttpException('no picture found at ' . $node->getPath());
         return 'notfound';
     }
     $path = $node->getPath();
     $relativePath = $this->pathMapper->getUrl($path);
     $extension = $this->getExtension($contentNode);
     $fullPath = $this->fileBasePath . '/' . $relativePath . $extension;
     if (!file_exists($fullPath)) {
         if (!$this->saveData($contentNode, $fullPath)) {
             throw new FileException('failed to save data to file: ' . $fullPath);
         }
     }
     return $this->webRelativePath . '/' . $relativePath . $extension;
 }
Пример #6
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);
 }
Пример #7
0
 public function testCreateFromString()
 {
     $parent = new FileTestObj();
     $parent->file = new File();
     $parent->id = '/functional/filetest';
     $parent->file->setFileContent('Lorem ipsum dolor sit amet');
     $this->dm->persist($parent);
     $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'));
     $binaryStream = $this->node->getNode('filetest')->getNode('file')->getNode('jcr:content')->getProperty('jcr:data')->getBinary();
     $this->assertNotNull($binaryStream, 'Ensure that we got a stream from the file');
     $content = stream_get_contents($binaryStream);
     $this->assertEquals('Lorem ipsum dolor sit amet', $content);
 }
 public function testBindTranslation()
 {
     $parent = $this->dm->find($this->type, '/functional/thename');
     $child = new Article();
     $child->parent = $parent;
     $child->id = '/functional/thename/child';
     $child->author = 'John Doe';
     $child->topic = 'Some interesting subject';
     $child->text = 'Lorem ipsum...';
     $this->dm->persist($child);
     $this->dm->bindTranslation($child, 'fr');
     $this->dm->flush();
     $this->assertTrue($this->node->getNode('thename')->hasNode('child'));
     $this->assertEquals('/functional/thename/child', $child->id);
     $this->dm->clear();
     $child = $this->dm->findTranslation($this->type, '/functional/thename/child', 'fr');
     $this->assertEquals('fr', $child->locale);
 }
Пример #9
0
 protected function getTranslationNode(NodeInterface $parentNode, $locale)
 {
     $name = Translation::LOCALE_NAMESPACE . ":{$locale}";
     if (!$parentNode->hasNode($name)) {
         $node = $parentNode->addNode($name);
     } else {
         $node = $parentNode->getNode($name);
     }
     return $node;
 }
Пример #10
0
 public function testChangeset()
 {
     $user = $this->node->getNode('user');
     // the property is not nullable, but this should only be checked on saving, not on loading
     $user->getProperty('username')->remove();
     $this->dm->getPhpcrSession()->save();
     $userDoc = $this->dm->find(null, $user->getPath());
     $this->assertInstanceOf($this->type, $userDoc);
     $this->assertNull($userDoc->username);
     // nothing should happen, we did not alter any value
     $this->dm->flush();
 }
Пример #11
0
 /**
  * @expectedException \PHPCR\NodeType\ConstraintViolationException
  */
 public function testChangingProtectedPropertyToNullThrowsException()
 {
     $test = new TestObject();
     $test->id = '/functional/protected';
     $test->changeMe = 'test';
     $this->dm->persist($test);
     $this->dm->flush();
     $this->dm->clear();
     $test = $this->dm->find(null, '/functional/protected');
     $test->changeMe = 'changed';
     $test->created = null;
     $this->dm->flush();
     $this->assertEquals('changed', $this->node->getNode('protected')->getProperty('change_me')->getString());
 }
Пример #12
0
 /**
  * @param NodeInterface $parentNode
  * @param string $name
  * @param null|NodeInterface $forNode
  *
  * @return string
  */
 public function resolveName(NodeInterface $parentNode, $name, $forNode = null)
 {
     if ($forNode && $parentNode->hasNode($name) && $parentNode->getNode($name) == $forNode) {
         return $name;
     }
     $index = 0;
     $baseName = $name;
     do {
         if ($index > 0) {
             $name = $baseName . '-' . $index;
         }
         $hasChild = $parentNode->hasNode($name);
         ++$index;
     } while ($hasChild);
     return $name;
 }
Пример #13
0
 /**
  * Assert that $node has a folder child that is an nt:folder and has a
  * child * called file that is an nt:file.
  *
  * @param NodeInterface $node
  */
 private function assertFolderAndFile(NodeInterface $node)
 {
     $this->assertTrue($node->hasNode('folder'));
     $folder = $node->getNode('folder');
     $this->assertTrue($folder->hasProperty('jcr:created'));
     $this->assertInstanceOf('\\DateTime', $folder->getPropertyValue('jcr:created'));
     $this->assertTrue($folder->hasNode('file'));
     $file = $folder->getNode('file');
     $this->assertTrue($file->hasNode('jcr:content'));
     $resource = $file->getNode('jcr:content');
     $this->assertTrue($resource->hasProperty('jcr:lastModified'));
     $this->assertInstanceOf('\\DateTime', $resource->getPropertyValue('jcr:lastModified'));
     $this->assertTrue($resource->hasProperty('jcr:data'));
     $binaryStream = $file->getNode('jcr:content')->getProperty('jcr:data')->getBinary();
     $this->assertNotNull($binaryStream, 'We got no content from the file');
     $content = stream_get_contents($binaryStream);
     $this->assertEquals(self::FILE_CONTENT, $content);
 }
Пример #14
0
 public function testMoveByAssignmentWithProxy()
 {
     $user = $this->node->getNode('dbu')->addNode('assistant');
     $user->setProperty('username', 'foo');
     $user->setProperty('status', 'created');
     $user->setProperty('phpcr:class', $this->type, PropertyType::STRING);
     $this->dm->getPhpcrSession()->save();
     $this->dm->clear();
     $user = $this->dm->find($this->type, '/functional/dbu');
     $this->assertNotNull($user, 'User must exist');
     $team = $this->dm->find($this->type, '/functional/team');
     $this->assertNotNull($team, 'Team must exist');
     $user->parent = $team;
     $this->assertFalse($user->child->__isInitialized());
     $this->dm->flush();
     $this->assertFalse($user->child->__isInitialized());
     $this->assertEquals('/functional/team/dbu/assistant', $user->child->getId());
     $this->assertEquals('foo', $user->child->getUsername());
 }
Пример #15
0
 public function testInsertGrandchildWithNewParent()
 {
     $parent = new NameDoc();
     $parent->id = '/functional/parent';
     $child = new NameDoc();
     $child->parent = $parent;
     $child->nodename = 'child';
     $parent->children = array($child);
     # the grand child 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 testHasNodesFalse()
 {
     $node = $this->node->getNode('index.txt/jcr:content');
     $this->assertFalse($node->hasNodes());
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function getNode($relPath)
 {
     return $this->node->getNode($relPath);
 }
Пример #18
0
 /**
  * @see \PHPCR\NodeInterface::getNode
  */
 public function getNode($path)
 {
     return new Node($this->node->getNode($path));
 }
Пример #19
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 = '../a';
     $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->assertEquals(PropertyType::STRING, $this->node->getNode('p')->getProperty('string')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('long'));
     $this->assertEquals(PropertyType::LONG, $this->node->getNode('p')->getProperty('long')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('int'));
     $this->assertEquals(PropertyType::LONG, $this->node->getNode('p')->getProperty('int')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('decimal'));
     $this->assertEquals(PropertyType::DECIMAL, $this->node->getNode('p')->getProperty('decimal')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('double'));
     $this->assertEquals(PropertyType::DOUBLE, $this->node->getNode('p')->getProperty('double')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('float'));
     $this->assertEquals(PropertyType::DOUBLE, $this->node->getNode('p')->getProperty('float')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('date'));
     $this->assertEquals(PropertyType::DATE, $this->node->getNode('p')->getProperty('date')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('boolean'));
     $this->assertEquals(PropertyType::BOOLEAN, $this->node->getNode('p')->getProperty('boolean')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('name'));
     $this->assertEquals(PropertyType::NAME, $this->node->getNode('p')->getProperty('name')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('path'));
     $this->assertEquals(PropertyType::PATH, $this->node->getNode('p')->getProperty('path')->getType());
     $this->assertTrue($this->node->getNode('p')->hasProperty('uri'));
     $this->assertEquals(PropertyType::URI, $this->node->getNode('p')->getProperty('uri')->getType());
     $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('../a', $doc->path);
     $this->assertNotNull($doc->uri);
     $this->assertEquals('http://cmf.symfony.com:8080/about.html#there', $doc->uri);
 }