|
@@ -50,6 +50,11 @@ class ShowMapperTest extends \PHPUnit_Framework_TestCase
|
|
*/
|
|
*/
|
|
private $groups;
|
|
private $groups;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @var array
|
|
|
|
+ */
|
|
|
|
+ private $listShowFields;
|
|
|
|
+
|
|
public function setUp()
|
|
public function setUp()
|
|
{
|
|
{
|
|
$this->showBuilder = $this->getMock('Sonata\AdminBundle\Builder\ShowBuilderInterface');
|
|
$this->showBuilder = $this->getMock('Sonata\AdminBundle\Builder\ShowBuilderInterface');
|
|
@@ -65,9 +70,11 @@ class ShowMapperTest extends \PHPUnit_Framework_TestCase
|
|
->will($this->returnValue(array()));
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
$this->groups = array();
|
|
$this->groups = array();
|
|
|
|
+ $this->listShowFields = array();
|
|
|
|
|
|
// php 5.3 BC
|
|
// php 5.3 BC
|
|
$groups = &$this->groups;
|
|
$groups = &$this->groups;
|
|
|
|
+ $listShowFields = &$this->listShowFields;
|
|
|
|
|
|
$this->admin->expects($this->any())
|
|
$this->admin->expects($this->any())
|
|
->method('getShowGroups')
|
|
->method('getShowGroups')
|
|
@@ -114,6 +121,18 @@ class ShowMapperTest extends \PHPUnit_Framework_TestCase
|
|
->method('getLabelTranslatorStrategy')
|
|
->method('getLabelTranslatorStrategy')
|
|
->will($this->returnValue($labelTranslatorStrategy));
|
|
->will($this->returnValue($labelTranslatorStrategy));
|
|
|
|
|
|
|
|
+ $this->admin->expects($this->any())
|
|
|
|
+ ->method('hasShowFieldDescription')
|
|
|
|
+ ->will($this->returnCallback(function ($name) use (&$listShowFields) {
|
|
|
|
+ if (isset($listShowFields[$name])) {
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ $listShowFields[$name] = true;
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }));
|
|
|
|
+
|
|
$this->showBuilder->expects($this->any())
|
|
$this->showBuilder->expects($this->any())
|
|
->method('addField')
|
|
->method('addField')
|
|
->will($this->returnCallback(function ($list, $type, $fieldDescription, $admin) {
|
|
->will($this->returnCallback(function ($list, $type, $fieldDescription, $admin) {
|
|
@@ -319,6 +338,22 @@ class ShowMapperTest extends \PHPUnit_Framework_TestCase
|
|
$this->fail('Failed asserting that exception of type "\RuntimeException" is thrown.');
|
|
$this->fail('Failed asserting that exception of type "\RuntimeException" is thrown.');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function testAddDuplicateFieldNameException()
|
|
|
|
+ {
|
|
|
|
+ $name = 'name';
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ $this->showMapper->add($name);
|
|
|
|
+ $this->showMapper->add($name);
|
|
|
|
+ } catch (\RuntimeException $e) {
|
|
|
|
+ $this->assertContains(sprintf('Duplicate field name "%s" in show mapper. Names should be unique.', $name), $e->getMessage());
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->fail('Failed asserting that duplicate field name exception of type "\RuntimeException" is thrown.');
|
|
|
|
+ }
|
|
|
|
+
|
|
public function testReorder()
|
|
public function testReorder()
|
|
{
|
|
{
|
|
$this->assertSame(array(), $this->admin->getShowGroups());
|
|
$this->assertSame(array(), $this->admin->getShowGroups());
|