diff --git a/src/MenuItem/AsciiArtItem.php b/src/MenuItem/AsciiArtItem.php index efdc3d3c..875499b6 100644 --- a/src/MenuItem/AsciiArtItem.php +++ b/src/MenuItem/AsciiArtItem.php @@ -73,8 +73,7 @@ public function getRows(MenuStyle $style, bool $selected = false) : array break; case self::POSITION_CENTER: default: - $row = rtrim($row); - $padding = $padding - ($this->artLength - mb_strlen($row)); + $padding = $padding - ($this->artLength - $length); $left = ceil($padding/2); $right = $padding - $left; $row = sprintf('%s%s%s', str_repeat(' ', $left), $row, str_repeat(' ', $right)); diff --git a/test/MenuItem/AsciiArtItemTest.php b/test/MenuItem/AsciiArtItemTest.php index f1e805a3..46438254 100644 --- a/test/MenuItem/AsciiArtItemTest.php +++ b/test/MenuItem/AsciiArtItemTest.php @@ -96,6 +96,15 @@ public function testGetRowsCenterAligned() : void ], $item->getRows($menuStyle) ); + + $item = new AsciiArtItem(" // \n//////////", AsciiArtItem::POSITION_CENTER); + $this->assertEquals( + [ + " // ", + "//////////", + ], + $item->getRows($menuStyle) + ); } public function testGetRowsCenterAlignedWithOddWidth() : void @@ -115,6 +124,15 @@ public function testGetRowsCenterAlignedWithOddWidth() : void ], $item->getRows($menuStyle) ); + + $item = new AsciiArtItem(" // \n//////////", AsciiArtItem::POSITION_CENTER); + $this->assertEquals( + [ + " // ", + " //////////", + ], + $item->getRows($menuStyle) + ); } public function testHideAndShowItemExtraHasNoEffect() : void