Skip to content

Commit

Permalink
Added test for grouped entity choice list
Browse files Browse the repository at this point in the history
Refs #889
  • Loading branch information
ericclemmons committed May 27, 2011
1 parent 91b1bec commit d380486
Showing 1 changed file with 52 additions and 3 deletions.
Expand Up @@ -40,9 +40,9 @@ public function testChoicesMustBeManaged()
{
$entity1 = new SingleIdentEntity(1, 'Foo');
$entity2 = new SingleIdentEntity(2, 'Bar');

// no persist here!

$choiceList = new EntityChoiceList(
$this->em,
self::SINGLE_IDENT_CLASS,
Expand All @@ -53,8 +53,57 @@ public function testChoicesMustBeManaged()
$entity2,
)
);

// triggers loading -> exception
$choiceList->getChoices();
}

public function testFlattenedChoicesAreManaged()
{
$entity1 = new SingleIdentEntity(1, 'Foo');
$entity2 = new SingleIdentEntity(2, 'Bar');

// Persist for managed state
$this->em->persist($entity1);
$this->em->persist($entity2);

$choiceList = new EntityChoiceList(
$this->em,
self::SINGLE_IDENT_CLASS,
'name',
null,
array(
$entity1,
$entity2,
)
);

$this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $choiceList->getChoices());
}

public function testNestedChoicesAreManaged()
{
$entity1 = new SingleIdentEntity(1, 'Foo');
$entity2 = new SingleIdentEntity(2, 'Bar');

// Oh yea, we're persistin' with fire now!
$this->em->persist($entity1);
$this->em->persist($entity2);

$choiceList = new EntityChoiceList(
$this->em,
self::SINGLE_IDENT_CLASS,
'name',
null,
array(
'group1' => array($entity1),
'group2' => array($entity2),
)
);

$this->assertSame(array(
'group1' => array(1 => 'Foo'),
'group2' => array(2 => 'Bar')
), $choiceList->getChoices());
}
}

0 comments on commit d380486

Please sign in to comment.