浏览代码

Improved ListMapper tests: cover deprecated view action

Andrej Hudec 11 年之前
父节点
当前提交
0445205b7c
共有 1 个文件被更改,包括 28 次插入0 次删除
  1. 28 0
      Tests/Datagrid/ListMapperTest.php

+ 28 - 0
Tests/Datagrid/ListMapperTest.php

@@ -116,6 +116,34 @@ class ListMapperTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('fooName', $fieldDescription->getOption('label'));
     }
 
+    public function testAddViewInlineActionException()
+    {
+        $this->setExpectedException('PHPUnit_Framework_Error', 'Inline action "view" is deprecated since version 2.2.4. Use inline action "show" instead.');
+
+        $this->assertFalse($this->listMapper->has('_action'));
+        $this->listMapper->add('_action', 'actions', array('actions'=>array('view'=>array())));
+    }
+
+    public function testAddViewInlineAction()
+    {
+        // ignore E_USER_DEPRECATED error
+        $previousErrorHandler = set_error_handler( function() {}, E_USER_DEPRECATED);
+
+        $this->assertFalse($this->listMapper->has('_action'));
+        $this->listMapper->add('_action', 'actions', array('actions'=>array('view'=>array())));
+
+        $this->assertTrue($this->listMapper->has('_action'));
+
+        $fieldDescription = $this->listMapper->get('_action');
+
+        $this->assertInstanceOf('Sonata\AdminBundle\Admin\FieldDescriptionInterface', $fieldDescription);
+        $this->assertEquals('_action', $fieldDescription->getName());
+        $this->assertCount(1, $fieldDescription->getOption('actions'));
+        $this->assertEquals(array('show'=>array()), $fieldDescription->getOption('actions'));
+
+        set_error_handler($previousErrorHandler);
+    }
+
     public function testAddRemove()
     {
         $this->assertFalse($this->listMapper->has('fooName'));