浏览代码

Unit test x editable method

Grégoire Paris 8 年之前
父节点
当前提交
0a071b68b7
共有 1 个文件被更改,包括 37 次插入0 次删除
  1. 37 0
      Tests/Twig/Extension/SonataAdminExtensionTest.php

+ 37 - 0
Tests/Twig/Extension/SonataAdminExtensionTest.php

@@ -2138,6 +2138,43 @@ EOT
         $this->assertSame(1234567, $this->twigExtension->getUrlsafeIdentifier($entity, $this->adminBar));
     }
 
+    public function xEditableChoicesProvider()
+    {
+        return array(
+            'needs processing' => array(array('Status1' => 'Alias1', 'Status2' => 'Alias2')),
+            'already processed' => array(array(
+                array('value' => 'Status1', 'text' => 'Alias1'),
+                array('value' => 'Status2', 'text' => 'Alias2'),
+            )),
+        );
+    }
+
+    /**
+     * @dataProvider xEditablechoicesProvider
+     */
+    public function testGetXEditableChoicesIsIdempotent(array $input)
+    {
+        $fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
+        $fieldDescription->expects($this->exactly(2))
+            ->method('getOption')
+            ->withConsecutive(
+                array('choices', array()),
+                array('catalogue')
+            )
+            ->will($this->onConsecutiveCalls(
+                $input,
+                'MyCatalogue'
+            ));
+
+        $this->assertSame(
+            array(
+                array('value' => 'Status1', 'text' => 'Alias1'),
+                array('value' => 'Status2', 'text' => 'Alias2'),
+            ),
+            $this->twigExtension->getXEditableChoices($fieldDescription)
+        );
+    }
+
     /**
      * This method generates url part for Twig layout. Allows to keep BC for PHP 5.3.
      *