Skip to content

Commit a32dfcc

Browse files
committed
Make alt text optional, update tests
1 parent 64d6d13 commit a32dfcc

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/CliMenuBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function addLineBreak(string $breakChar = ' ', int $lines = 1) : self
138138
return $this;
139139
}
140140

141-
public function addAsciiArt(string $art, string $position = AsciiArtItem::POSITION_CENTER, string $alt) : self
141+
public function addAsciiArt(string $art, string $position = AsciiArtItem::POSITION_CENTER, string $alt = '') : self
142142
{
143143
$this->addMenuItem(new AsciiArtItem($art, $position, $alt));
144144

test/CliMenuBuilderTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,23 @@ public function testAsciiArtWithSpecificPosition() : void
245245
$this->checkItems($menu, $expected);
246246
}
247247

248-
public function testAddAsciiArtDetectsArtThatDoesNotFitAndSkipsIt() : void
248+
public function testAsciiArtWithAlt() : void
249249
{
250250
$builder = new CliMenuBuilder;
251-
$builder->setWidth(1);
252-
$builder->addAsciiArt("//\n//", AsciiArtItem::POSITION_LEFT);
251+
$builder->disableDefaultItems();
252+
$builder->addAsciiArt("//\n//", AsciiArtItem::POSITION_LEFT, 'Some ALT');
253253
$menu = $builder->build();
254254

255-
foreach ($menu->getItems() as $menuItem) {
256-
$this->assertNotInstanceOf(AsciiArtItem::class, $menuItem);
257-
}
255+
$expected = [
256+
[
257+
'class' => AsciiArtItem::class,
258+
'text' => "//\n//",
259+
'position' => AsciiArtItem::POSITION_LEFT,
260+
'alternateText' => 'Some ALT'
261+
]
262+
];
263+
264+
$this->checkItems($menu, $expected);
258265
}
259266

260267
public function testEndThrowsExceptionIfNoParentBuilder() : void

test/MenuItem/AsciiArtItemTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,18 @@ public function testHideAndShowItemExtraHasNoEffect() : void
127127
$item->hideItemExtra();
128128
$this->assertFalse($item->showsItemExtra());
129129
}
130+
131+
public function testGetRowsReturnsStaticAltItemWhenWidthIsTooSmall()
132+
{
133+
$menuStyle = $this->createMock(MenuStyle::class);
134+
135+
$menuStyle
136+
->expects($this->any())
137+
->method('getContentWidth')
138+
->will($this->returnValue(10));
139+
140+
$item = new AsciiArtItem('TOO LONG. SO SO LONG.', AsciiArtItem::POSITION_CENTER, 'my alt');
141+
142+
self::assertSame(['my alt'], $item->getRows($menuStyle));
143+
}
130144
}

0 commit comments

Comments
 (0)