From fab18597edf15fb7a88d9e57025fa7baafcb8b80 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:36:56 +1100 Subject: [PATCH 01/19] Add setText to interface --- src/MenuItem/MenuItemInterface.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MenuItem/MenuItemInterface.php b/src/MenuItem/MenuItemInterface.php index 0561fce0..63ef1a76 100644 --- a/src/MenuItem/MenuItemInterface.php +++ b/src/MenuItem/MenuItemInterface.php @@ -19,6 +19,11 @@ public function getRows(MenuStyle $style, bool $selected = false) : array; */ public function getText() : string; + /** + * Set the raw string of text + */ + public function setText() : void; + /** * Can the item be selected */ From 841938029f0e06509c519c8ee0071b66546908c7 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:38:59 +1100 Subject: [PATCH 02/19] Add setText to AsciiArtItem --- src/MenuItem/AsciiArtItem.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/MenuItem/AsciiArtItem.php b/src/MenuItem/AsciiArtItem.php index 047bc37c..9f4cbb44 100644 --- a/src/MenuItem/AsciiArtItem.php +++ b/src/MenuItem/AsciiArtItem.php @@ -41,9 +41,7 @@ public function __construct(string $text, string $position = self::POSITION_CENT { Assertion::inArray($position, [self::POSITION_CENTER, self::POSITION_RIGHT, self::POSITION_LEFT]); - $this->text = implode("\n", array_map(function (string $line) { - return rtrim($line, ' '); - }, explode("\n", $text))); + $this->setText($text); $this->position = $position; $this->alternateText = $alt; $this->artLength = max(array_map('mb_strlen', explode("\n", $text))); @@ -103,6 +101,16 @@ public function getText() : string return $this->text; } + /** + * Set the raw string of text + */ + public function setText(string $text) : void + { + $this->text = implode("\n", array_map(function (string $line) { + return rtrim($line, ' '); + }, explode("\n", $text))); + } + /** * Return the length of the art */ From eb0edc9c804d04d0c9645d5fbfe0c80904319a23 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:40:12 +1100 Subject: [PATCH 03/19] Add setText to LineBreakItem --- src/MenuItem/LineBreakItem.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/MenuItem/LineBreakItem.php b/src/MenuItem/LineBreakItem.php index ae2dfac1..dc581965 100644 --- a/src/MenuItem/LineBreakItem.php +++ b/src/MenuItem/LineBreakItem.php @@ -64,6 +64,14 @@ public function getText() : string return $this->breakChar; } + /** + * Set the raw string of text + */ + public function setText(string $text) : void + { + $this->breakChar = $text; + } + /** * Whether or not the menu item is showing the menustyle extra value */ From 756263ea16fca1be7a43566b4b3e1bc196c7a751 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:41:19 +1100 Subject: [PATCH 04/19] Add setText to SelectableItem --- src/MenuItem/SelectableItem.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/MenuItem/SelectableItem.php b/src/MenuItem/SelectableItem.php index 02445528..6b58f81c 100644 --- a/src/MenuItem/SelectableItem.php +++ b/src/MenuItem/SelectableItem.php @@ -41,4 +41,12 @@ public function getText() : string { return $this->text; } + + /** + * Set the raw string of text + */ + public function setText(string $text) : void + { + $this->text = $text; + } } From ebae511695ce53aaf47695145a4fed718e26dcb8 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:42:20 +1100 Subject: [PATCH 05/19] Add setText to SplitItem --- src/MenuItem/SplitItem.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/MenuItem/SplitItem.php b/src/MenuItem/SplitItem.php index 03d433af..94bad277 100644 --- a/src/MenuItem/SplitItem.php +++ b/src/MenuItem/SplitItem.php @@ -303,4 +303,12 @@ public function getText() : string { throw new \BadMethodCallException(sprintf('Not supported on: %s', __CLASS__)); } + + /** + * Nothing to set with SplitItem + */ + public function setText(string $text) : void + { + throw new \BadMethodCallException(sprintf('Not supported on: %s', __CLASS__)); + } } From 77f5abfd28d93711a086aa9353c03a5be2ef51c1 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:43:06 +1100 Subject: [PATCH 06/19] Add setText to StaticItem --- src/MenuItem/StaticItem.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/MenuItem/StaticItem.php b/src/MenuItem/StaticItem.php index 64576393..fc532a0f 100644 --- a/src/MenuItem/StaticItem.php +++ b/src/MenuItem/StaticItem.php @@ -53,6 +53,14 @@ public function getText() : string return $this->text; } + /** + * Set the raw string of text + */ + public function setText(string $text) : void + { + $this->text = $text; + } + /** * Whether or not the menu item is showing the menustyle extra value */ From 434a4eb6fd7c47f65edad5949b6619c2e6c2ad43 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:44:05 +1100 Subject: [PATCH 07/19] Add setText to MenuMenuItem --- src/MenuItem/MenuMenuItem.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/MenuItem/MenuMenuItem.php b/src/MenuItem/MenuMenuItem.php index c7fb11e6..920cece5 100644 --- a/src/MenuItem/MenuMenuItem.php +++ b/src/MenuItem/MenuMenuItem.php @@ -39,6 +39,14 @@ public function getText() : string { return $this->text; } + + /** + * Set the raw string of text + */ + public function setText(string $text) : void + { + $this->text = $text; + } /** * Returns the sub menu From 30c9fb56d16a233c182d3ab04d0486e84f822a67 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:45:27 +1100 Subject: [PATCH 08/19] Missing argument --- src/MenuItem/MenuItemInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MenuItem/MenuItemInterface.php b/src/MenuItem/MenuItemInterface.php index 63ef1a76..fdfbe338 100644 --- a/src/MenuItem/MenuItemInterface.php +++ b/src/MenuItem/MenuItemInterface.php @@ -22,7 +22,7 @@ public function getText() : string; /** * Set the raw string of text */ - public function setText() : void; + public function setText(string $text) : void; /** * Can the item be selected From 3620f694dcfe5977bf6b12ff1797f24bfce9aa7a Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:52:28 +1100 Subject: [PATCH 09/19] add AsciiArtItem setText tests --- test/MenuItem/AsciiArtItemTest.php | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/MenuItem/AsciiArtItemTest.php b/test/MenuItem/AsciiArtItemTest.php index 6d3558fc..915a7674 100644 --- a/test/MenuItem/AsciiArtItemTest.php +++ b/test/MenuItem/AsciiArtItemTest.php @@ -236,4 +236,37 @@ public function testWithRealAsciiArtCenterAlignedWithWhiteSpaceAtTheEndOfEachLin $item->getRows($menuStyle) ); } + + public function testSetText() : void + { + $menuStyle = $this->createMock(MenuStyle::class); + + $menuStyle + ->expects($this->any()) + ->method('getContentWidth') + ->will($this->returnValue(30)); + + $art = <<setText($art); + + $this->assertEquals( + [ + ' _ __ _', + ' / |..| \\', + ' \/ || \/', + " |_''_|", + ' PHP SCHOOL', + ' LEARNING FOR ELEPHANTS' + ], + $item->getRows($menuStyle) + ); + } } From a042cd03538f496db769a2c6a6a7fbcb3979b206 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:54:57 +1100 Subject: [PATCH 10/19] setText test for LineBreakItem --- test/MenuItem/LineBreakItemTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/MenuItem/LineBreakItemTest.php b/test/MenuItem/LineBreakItemTest.php index ac50d690..64f79190 100644 --- a/test/MenuItem/LineBreakItemTest.php +++ b/test/MenuItem/LineBreakItemTest.php @@ -90,6 +90,20 @@ public function testGetRowsWithMultiByteChars() : void $this->assertEquals(['❅❅❅❅❅', '❅❅❅❅❅'], $item->getRows($menuStyle)); } + public function testSetText() : void + { + $menuStyle = $this->createMock(MenuStyle::class); + + $menuStyle + ->expects($this->any()) + ->method('getContentWidth') + ->will($this->returnValue(5)); + + $item = new LineBreakItem('ABC', 2); + $item->setText('❅-'); + $this->assertEquals(['❅-❅-❅', '❅-❅-❅'], $item->getRows($menuStyle)); + } + public function testHideAndShowItemExtraHasNoEffect() : void { $item = new LineBreakItem('*'); From 767bfeba7e02f4fe13ee17b759779ee979e7a107 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:57:17 +1100 Subject: [PATCH 11/19] setText test for SelectableItem --- test/MenuItem/SelectableItemTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/MenuItem/SelectableItemTest.php b/test/MenuItem/SelectableItemTest.php index 9c35a078..3f8b39d1 100644 --- a/test/MenuItem/SelectableItemTest.php +++ b/test/MenuItem/SelectableItemTest.php @@ -60,6 +60,23 @@ public function testGetRows() : void $this->assertEquals([' Item'], $item->getRows($menuStyle, true)); } + public function testSetText() : void + { + $menuStyle = $this->createMock(MenuStyle::class); + + $menuStyle + ->expects($this->any()) + ->method('getContentWidth') + ->will($this->returnValue(10)); + + $item = new SelectableItem('Item', function () { + }); + $item->setText('New Text'); + $this->assertEquals([' New Text'], $item->getRows($menuStyle)); + $this->assertEquals([' New Text'], $item->getRows($menuStyle, false)); + $this->assertEquals([' New Text'], $item->getRows($menuStyle, true)); + } + public function testGetRowsWithUnSelectedMarker() : void { $menuStyle = $this->createMock(MenuStyle::class); From deb95f85e8ab8ab9fbd32e59a93b71b6f5b23180 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 00:58:19 +1100 Subject: [PATCH 12/19] setText test for SplitItem --- test/MenuItem/SplitItemTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/MenuItem/SplitItemTest.php b/test/MenuItem/SplitItemTest.php index 99b3aa8e..76aaac38 100644 --- a/test/MenuItem/SplitItemTest.php +++ b/test/MenuItem/SplitItemTest.php @@ -375,6 +375,14 @@ public function testGetTextThrowsAnException() : void (new SplitItem([]))->getText(); } + + public function testSetTextThrowsAnException() : void + { + self::expectException(\BadMethodCallException::class); + self::expectExceptionMessage(sprintf('Not supported on: %s', SplitItem::class)); + + (new SplitItem([]))->setText('test'); + } public function testGetRowsThrowsAnExceptionIfNoItemsWereAdded() : void { From 2551372eb00dfdf5143705a9719ac364ad91c2e8 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 01:00:17 +1100 Subject: [PATCH 13/19] setText test for StaticItem --- test/MenuItem/StaticItemTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/MenuItem/StaticItemTest.php b/test/MenuItem/StaticItemTest.php index c1ffca46..28e020c5 100644 --- a/test/MenuItem/StaticItemTest.php +++ b/test/MenuItem/StaticItemTest.php @@ -69,6 +69,24 @@ public function testGetRowsWithContentWhichDoesNotFitOnOneLineIsWrapped() : void ); } + public function testSetText() : void + { + $menuStyle = $this->createMock(MenuStyle::class); + + $menuStyle + ->expects($this->once()) + ->method('getContentWidth') + ->will($this->returnValue(10)); + + $item = new StaticItem('CONTENT'); + $item->setText('CONTENT 2 LINES'); + + $this->assertEquals( + ['CONTENT 2', 'LINES'], + $item->getRows($menuStyle) + ); + } + public function testHideAndShowItemExtraHasNoEffect() : void { $item = new StaticItem('CONTENT 1 LINE'); From 961c8486260d7c06b9e917a7df8c833e99b0f1a5 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 01:07:45 +1100 Subject: [PATCH 14/19] Add 1 new AsciiArt test --- test/MenuItem/AsciiArtItemTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/MenuItem/AsciiArtItemTest.php b/test/MenuItem/AsciiArtItemTest.php index 915a7674..c9b35969 100644 --- a/test/MenuItem/AsciiArtItemTest.php +++ b/test/MenuItem/AsciiArtItemTest.php @@ -142,6 +142,20 @@ public function testGetRowsReturnsStaticAltItemWhenWidthIsTooSmall() : void self::assertSame(['my alt'], $item->getRows($menuStyle)); } + public function testGetRowsDoesNotReturnsStaticAltItemWhenOnlySpacesOverflow() : void + { + $menuStyle = $this->createMock(MenuStyle::class); + + $menuStyle + ->expects($this->any()) + ->method('getContentWidth') + ->will($this->returnValue(15)); + + $item = new AsciiArtItem('NOT TOO LONG ', AsciiArtItem::POSITION_LEFT, 'my alt'); + + self::assertSame(['NOT TOO LONG'], $item->getRows($menuStyle)); + } + public function testWithRealAsciiArtCenterAligned() : void { $menuStyle = $this->createMock(MenuStyle::class); From b5f319bc4b94fa0c8e13ea4857c3e858f031ec5d Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 01:13:16 +1100 Subject: [PATCH 15/19] Fix right spaces causing fallback to alt text --- src/MenuItem/AsciiArtItem.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/MenuItem/AsciiArtItem.php b/src/MenuItem/AsciiArtItem.php index 9f4cbb44..5ed7bc46 100644 --- a/src/MenuItem/AsciiArtItem.php +++ b/src/MenuItem/AsciiArtItem.php @@ -44,7 +44,7 @@ public function __construct(string $text, string $position = self::POSITION_CENT $this->setText($text); $this->position = $position; $this->alternateText = $alt; - $this->artLength = max(array_map('mb_strlen', explode("\n", $text))); + $this->calculateArtLength(); } /** @@ -111,6 +111,14 @@ public function setText(string $text) : void }, explode("\n", $text))); } + /** + * Calculate the length of the art + */ + private function calculateArtLength() : void + { + $this->artLength = max(array_map('mb_strlen', explode("\n", $this->text))); + } + /** * Return the length of the art */ From ab99086f959a9448864fd353fd412b541511cdfc Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 01:16:15 +1100 Subject: [PATCH 16/19] Moving calculateArtLength inside setText --- src/MenuItem/AsciiArtItem.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MenuItem/AsciiArtItem.php b/src/MenuItem/AsciiArtItem.php index 5ed7bc46..61b3132d 100644 --- a/src/MenuItem/AsciiArtItem.php +++ b/src/MenuItem/AsciiArtItem.php @@ -44,7 +44,6 @@ public function __construct(string $text, string $position = self::POSITION_CENT $this->setText($text); $this->position = $position; $this->alternateText = $alt; - $this->calculateArtLength(); } /** @@ -109,6 +108,8 @@ public function setText(string $text) : void $this->text = implode("\n", array_map(function (string $line) { return rtrim($line, ' '); }, explode("\n", $text))); + + $this->calculateArtLength(); } /** From 2e60a174983a0f61d8599c8b5a7a17204303369e Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 02:17:44 +1100 Subject: [PATCH 17/19] Remove setText from interface --- src/MenuItem/MenuItemInterface.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/MenuItem/MenuItemInterface.php b/src/MenuItem/MenuItemInterface.php index fdfbe338..0561fce0 100644 --- a/src/MenuItem/MenuItemInterface.php +++ b/src/MenuItem/MenuItemInterface.php @@ -19,11 +19,6 @@ public function getRows(MenuStyle $style, bool $selected = false) : array; */ public function getText() : string; - /** - * Set the raw string of text - */ - public function setText(string $text) : void; - /** * Can the item be selected */ From 02ed75f7d289d24643b7568ac9db7adade87949e Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 02:18:12 +1100 Subject: [PATCH 18/19] Remove setText from SplitItem --- src/MenuItem/SplitItem.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/MenuItem/SplitItem.php b/src/MenuItem/SplitItem.php index 94bad277..03d433af 100644 --- a/src/MenuItem/SplitItem.php +++ b/src/MenuItem/SplitItem.php @@ -303,12 +303,4 @@ public function getText() : string { throw new \BadMethodCallException(sprintf('Not supported on: %s', __CLASS__)); } - - /** - * Nothing to set with SplitItem - */ - public function setText(string $text) : void - { - throw new \BadMethodCallException(sprintf('Not supported on: %s', __CLASS__)); - } } From 483eaeb7e888677c3e87433f98c509c004aec0b0 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Wed, 16 May 2018 02:18:52 +1100 Subject: [PATCH 19/19] Remove SplitItem's setText test --- test/MenuItem/SplitItemTest.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/MenuItem/SplitItemTest.php b/test/MenuItem/SplitItemTest.php index 76aaac38..99b3aa8e 100644 --- a/test/MenuItem/SplitItemTest.php +++ b/test/MenuItem/SplitItemTest.php @@ -375,14 +375,6 @@ public function testGetTextThrowsAnException() : void (new SplitItem([]))->getText(); } - - public function testSetTextThrowsAnException() : void - { - self::expectException(\BadMethodCallException::class); - self::expectExceptionMessage(sprintf('Not supported on: %s', SplitItem::class)); - - (new SplitItem([]))->setText('test'); - } public function testGetRowsThrowsAnExceptionIfNoItemsWereAdded() : void {