-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Forms] Fix PhpcrOdmQueryBuilderLoader and depend on symfony version that fixed DoctrineType #201
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Tests/Functional/Form/ChoiceList/PhpcrOdmQueryBuilderLoaderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\PHPCRBundle\Tests\Functional\Form\ChoiceList; | ||
|
||
use Doctrine\Bundle\PHPCRBundle\Form\ChoiceList\PhpcrOdmQueryBuilderLoader; | ||
use Doctrine\ODM\PHPCR\DocumentManager; | ||
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; | ||
|
||
class PhpcrOdmQueryBuilderLoaderTest extends BaseTestCase | ||
{ | ||
/** | ||
* @var DocumentManager | ||
*/ | ||
private $dm; | ||
|
||
public function setUp() | ||
{ | ||
$this->db('PHPCR')->loadFixtures(array( | ||
'Doctrine\Bundle\PHPCRBundle\Tests\Resources\DataFixtures\PHPCR\LoadData', | ||
)); | ||
|
||
$this->dm = $this->getContainer()->get('doctrine_phpcr.odm.default_document_manager'); | ||
} | ||
|
||
public function testGetByIds() | ||
{ | ||
$qb = $this->dm->getRepository('Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument')->createQueryBuilder('e'); | ||
$loader = new PhpcrOdmQueryBuilderLoader($qb, $this->dm); | ||
$ids = array('/test/doc', '/test/doc2', '/test/doc3'); | ||
$documents = $loader->getEntitiesByIds('id', $ids); | ||
$this->assertCount(2, $documents); | ||
foreach ($documents as $i => $document) { | ||
$this->assertInstanceOf('Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument', $document); | ||
$this->assertTrue(in_array($document->id, $ids)); | ||
} | ||
} | ||
|
||
public function testGetByIdsNotFound() | ||
{ | ||
$qb = $this->dm->getRepository('Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument')->createQueryBuilder('e'); | ||
$loader = new PhpcrOdmQueryBuilderLoader($qb, $this->dm); | ||
$documents = $loader->getEntitiesByIds('id', array('/foo/bar')); | ||
$this->assertCount(0, $documents); | ||
} | ||
|
||
public function testGetByIdsFilter() | ||
{ | ||
$qb = $this->dm->getRepository('Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument')->createQueryBuilder('e'); | ||
$qb->where()->eq()->field('e.text')->literal('thiswillnotmatch'); | ||
$loader = new PhpcrOdmQueryBuilderLoader($qb, $this->dm); | ||
$documents = $loader->getEntitiesByIds('id', array('/test/doc')); | ||
$this->assertCount(0, $documents); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\PHPCRBundle\Tests\Functional\Form\Type; | ||
|
||
use Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\ReferrerDocument; | ||
use Doctrine\ODM\PHPCR\DocumentManager; | ||
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class DocumentTypeTest extends BaseTestCase | ||
{ | ||
/** | ||
* @var DocumentManager | ||
*/ | ||
private $dm; | ||
|
||
/** | ||
* @var ReferrerDocument | ||
*/ | ||
private $referrer; | ||
|
||
public function setUp() | ||
{ | ||
$this->db('PHPCR')->loadFixtures(array( | ||
'Doctrine\Bundle\PHPCRBundle\Tests\Resources\DataFixtures\PHPCR\LoadData', | ||
)); | ||
$this->dm = $this->db('PHPCR')->getOm(); | ||
$document = $this->dm->find(null, '/test/doc'); | ||
$this->assertNotNull($document, 'fixture loading not working'); | ||
$this->referrer = $this->dm->find(null, '/test/ref'); | ||
$this->assertNotNull($this->referrer, 'fixture loading not working'); | ||
} | ||
|
||
/** | ||
* @return FormBuilderInterface | ||
*/ | ||
private function createFormBuilder($data, $options = array()) | ||
{ | ||
return $this->container->get('form.factory')->createBuilder('form', $data, $options); | ||
} | ||
|
||
/** | ||
* Render a form and return the HTML | ||
*/ | ||
private function renderForm(FormBuilderInterface $formBuilder) | ||
{ | ||
$formView = $formBuilder->getForm()->createView(); | ||
$templating = $this->getContainer()->get('templating'); | ||
|
||
return $templating->render('::form.html.twig', array('form' => $formView)); | ||
} | ||
|
||
public function testUnfiltered() | ||
{ | ||
$formBuilder = $this->createFormBuilder($this->referrer); | ||
|
||
$formBuilder | ||
->add('single', 'phpcr_document', array( | ||
'class' => 'Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument', | ||
)) | ||
; | ||
|
||
$html = $this->renderForm($formBuilder); | ||
$this->assertContains('<select id="form_single" name="form[single]"', $html); | ||
$this->assertContains('<option value="/test/doc"', $html); | ||
} | ||
|
||
public function testFiltered() | ||
{ | ||
$qb = $this->dm | ||
->getRepository('Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument') | ||
->createQueryBuilder('e') | ||
; | ||
$qb->where()->eq()->field('e.text')->literal('thiswillnotmatch'); | ||
$formBuilder = $this->createFormBuilder($this->referrer); | ||
|
||
$formBuilder | ||
->add('single', 'phpcr_document', array( | ||
'class' => 'Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument', | ||
'query_builder' => $qb, | ||
)) | ||
; | ||
|
||
$html = $this->renderForm($formBuilder); | ||
$this->assertContains('<select id="form_single" name="form[single]"', $html); | ||
$this->assertNotContains('<option', $html); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this would just overwrite the value on the same criteria several times would it not? Shouldnt the
->orX
be in the loop?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups, i think you are right dan. @lsmith77 can you maybe add a second document to the fixtures and test with one and two ids? Right now we dont test that we actually filter vs just loading all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't appear to be the case. I have added another document to the fixtures and it seems to just work ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs seem to agree as well http://doctrine-phpcr-odm.readthedocs.org/en/latest/reference/query-builder-reference.html#qbref-method-constraintfactory-orx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, your right.