Bläddra i källkod

Merge pull request #2680 from WouterJ/patch-3

Add a way to see if a tab group is open
Thomas 10 år sedan
förälder
incheckning
4cd443ea68
2 ändrade filer med 21 tillägg och 0 borttagningar
  1. 10 0
      Mapper/BaseGroupedMapper.php
  2. 11 0
      Tests/Mapper/BaseGroupedMapperTest.php

+ 10 - 0
Mapper/BaseGroupedMapper.php

@@ -219,6 +219,16 @@ abstract class BaseGroupedMapper extends BaseMapper
 
         return $this;
     }
+    
+    /**
+     * Returns a boolean indicating if there is an open tab at the moment.
+     * 
+     * @return boolean
+     */
+    public function hasOpenTab()
+    {
+        return null !== $this->currentTab;
+    }
 
     /**
      * Add the fieldname to the current group

+ 11 - 0
Tests/Mapper/BaseGroupedMapperTest.php

@@ -132,6 +132,17 @@ class BaseGroupedMapperTest extends \PHPUnit_Framework_TestCase
         $this->baseGroupedMapper->tab('fooTab');
         $this->baseGroupedMapper->tab('barTab');
     }
+    
+    public function testHasOpenTab()
+    {
+        $this->assertFalse($this->baseGroupedMapper->hasOpenTab(), '->hasOpenTab() returns false when there are no tabs');
+        
+        $this->baseGroupedMapper->tab('fooTab');
+        $this->assertTrue($this->baseGroupedMapper->hasOpenTab(), '->hasOpenTab() returns true when there is an open tab');
+        
+        $this->baseGroupedMapper->end();
+        $this->assertFalse($this->baseGroupedMapper->hasOpenTab(), '->hasOpenTab() returns false when all tabs are closed');
+    }
 
     /**
      * @expectedException        RuntimeException