This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
src/Helper/Placeholder/Container Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -113,9 +113,14 @@ public function __toString()
113113 */
114114 public function toString ($ indent = null )
115115 {
116- $ indent = ($ indent !== null )
117- ? $ this ->getWhitespace ($ indent )
118- : $ this ->getIndent ();
116+ // If we don't have items - do not show prefix and postfix
117+ if (! count ($ this )) {
118+ return '' ;
119+ }
120+
121+ $ indent = ($ indent === null )
122+ ? $ this ->getIndent ()
123+ : $ this ->getWhitespace ($ indent );
119124
120125 $ items = $ this ->getArrayCopy ();
121126 $ return = $ indent
Original file line number Diff line number Diff line change @@ -432,4 +432,17 @@ public function testIndentationIsHonored()
432432 $ this ->assertContains (" <ul> \n" , $ string , $ string );
433433 $ this ->assertContains ("\n </ul> " , $ string , $ string );
434434 }
435+
436+ public function testNoUsePrefixPostfixIfNoItems ()
437+ {
438+ $ this ->container ->setPrefix ("<h1> " )
439+ ->setPostfix ("</h1> " );
440+ $ string = $ this ->container ->toString ();
441+ $ this ->assertEquals ('' , $ string );
442+
443+ $ this ->container ->set ('' );
444+ $ string = $ this ->container ->toString ();
445+ $ this ->assertEquals ('<h1></h1> ' , $ string );
446+ }
447+
435448}
You can’t perform that action at this time.
0 commit comments