Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Added missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Oct 11, 2016
1 parent ac74d90 commit cc03d90
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 9 deletions.
2 changes: 1 addition & 1 deletion benchmark/DoctrinePhpcrBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setUp()
'type' => 'datetime',
],
'referencedImage' => [
'type' => 'image_reference',
'type' => 'object_reference',
],
'paragraphs' => [
'type' => 'collection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function preFlush(ManagerEventArgs $args)
throw new \InvalidArgumentException(sprintf(
'Currently, all documents which belong to a mapped collection must use the ' .
'assigned ID generator strategy, "%s" is using "%s".',
$childMetadata->getClass(), $idGenerator
$childMetadata->getName(), $idGenerator
));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use Psi\Component\ContentType\Storage\Mapping\TypeFactory;
use Psi\Component\ContentType\Storage\Mapping\TypeRegistry;
use Psi\Component\ContentType\Tests\Functional\Example\Field\ImageField;
use Psi\Component\ContentType\Tests\Functional\Example\Field\ImageReferenceField;
use Psi\Component\ContentType\Tests\Functional\Example\Field\ObjectReferenceField;
use Psi\Component\ContentType\Tests\Functional\Example\View\ImageView;
use Psi\Component\ContentType\View\ScalarView;
use Psi\Component\ContentType\ViewRegistry;
Expand Down Expand Up @@ -101,7 +101,7 @@ private function loadPsiContentType()
$registry->register('integer', new IntegerField());
$registry->register('datetime', new DateTimeField());
$registry->register('image', new ImageField());
$registry->register('image_reference', new ImageReferenceField());
$registry->register('object_reference', new ObjectReferenceField());
$registry->register('collection', new CollectionField($registry));

return $registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Psi\Component\ContentType\View\ScalarView;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class ImageReferenceField implements FieldInterface
class ObjectReferenceField implements FieldInterface
{
public function getViewType(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;

/**
* @PHPCR\Document()
* @PHPCR\Document(referenceable=true)
*/
class Article
{
Expand All @@ -22,4 +22,5 @@ class Article
public $referencedImage;
public $numbers;
public $paragraphs = [];
public $objectReferences;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Psi\Component\ContentType\Tests\Functional\Example\Storage\Doctrine\PhpcrOdm;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;

/**
* @PHPCR\Document(referenceable=true)
*/
class ImageNotAssignedGenerator
{
/**
* @PHPCR\Id(strategy="parent")
*/
public $id;

/**
* @PHPCR\ParentDocument()
*/
public $parent;

/**
* @PHPCR\Nodename()
*/
public $name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Psi\Component\ContentType\Tests\Functional\Example\Storage\Doctrine\PhpcrOdm\Article;
use Psi\Component\ContentType\Tests\Functional\Example\Storage\Doctrine\PhpcrOdm\ArticleWithRestrictedChildren;
use Psi\Component\ContentType\Tests\Functional\Example\Storage\Doctrine\PhpcrOdm\Image;
use Psi\Component\ContentType\Tests\Functional\Example\Storage\Doctrine\PhpcrOdm\ImageNotAssignedGenerator;

class ObjectTest extends PhpcrOdmTestCase
{
Expand All @@ -24,6 +25,12 @@ public function setUp()
'field' => 'image',
],
],
'objectReferences' => [
'type' => 'collection',
'options' => [
'field' => 'object_reference',
],
],
],
],
],
Expand Down Expand Up @@ -185,17 +192,48 @@ public function testCollectionPersistNoUpdater()

/**
* It should throw an exception when a document in a collection does not have the "ASSIGNED" ID generator.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Currently, all documents which belong to a mapped collection must use the assigned ID generator strategy
*/
public function testCollectionPersistNoAssignedGenerator()
{
$this->markTestIncomplete('TODO');
$image1 = new ImageNotAssignedGenerator();
$article = new Article();
$article->id = '/test/article';
$article->slideshow = [$image1];
$this->updater->update($this->documentManager, $article);
$this->documentManager->persist($article);
$this->documentManager->flush();
}

/**
* It should store arrays of references.
*/
public function testStoreArrayOfReferences()
{
$this->markTestIncomplete('TODO');
$article = new Article();
$article->id = '/test/article';

$article1 = new Article();
$article1->id = '/test/article1';

$article2 = new Article();
$article2->id = '/test/article2';

$this->documentManager->persist($article1);
$this->documentManager->persist($article2);
$this->documentManager->flush();

$article->objectReferences = [$article1, $article2];
$this->documentManager->persist($article);
$this->documentManager->flush();
$this->documentManager->clear();

$article = $this->documentManager->find(null, '/test/article');
$this->assertCount(2, $article->objectReferences);
$this->assertEquals('/test/article1', $article->objectReferences[0]->id);
$this->assertEquals('/test/article2', $article->objectReferences[1]->id);
}

private function createArticleSlideshow()
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Storage/Doctrine/PhpcrOdm/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function setUp()
'type' => 'datetime',
],
'referencedImage' => [
'type' => 'image_reference',
'type' => 'object_reference',
],
],
],
Expand Down

0 comments on commit cc03d90

Please sign in to comment.