-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Forms] Fix PhpcrOdmQueryBuilderLoader and depend on symfony version …
…that fixed DoctrineType
- Loading branch information
Showing
7 changed files
with
160 additions
and
10 deletions.
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
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
<?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); | ||
$documents = $loader->getEntitiesByIds('id', array('/test/doc')); | ||
$this->assertCount(1, $documents); | ||
$doc = reset($documents); | ||
$this->assertInstanceOf('Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument', $doc); | ||
} | ||
|
||
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