소스 검색

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.
      *