-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from andrewnicols/imgAlt
Supply the image alt text when converting images
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Html2Text; | ||
|
||
class ImageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testImageDataProvider() { | ||
return array( | ||
'Without alt tag' => array( | ||
'html' => '<img src="http://example.com/example.jpg">', | ||
'expected' => '', | ||
), | ||
'Without alt tag, wrapped in text' => array( | ||
'html' => 'xx<img src="http://example.com/example.jpg">xx', | ||
'expected' => 'xxxx', | ||
), | ||
'With alt tag' => array( | ||
'html' => '<img src="http://example.com/example.jpg" alt="An example image">', | ||
'expected' => '[An example image]', | ||
), | ||
'With alt, and title tags' => array( | ||
'html' => '<img src="http://example.com/example.jpg" alt="An example image" title="Should be ignored">', | ||
'expected' => '[An example image]', | ||
), | ||
'With alt tag, wrapped in text' => array( | ||
'html' => 'xx<img src="http://example.com/example.jpg" alt="An example image">xx', | ||
'expected' => 'xx[An example image]xx', | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider testImageDataProvider | ||
*/ | ||
public function testImages($html, $expected) | ||
{ | ||
$html2text = new Html2Text($html); | ||
$output = $html2text->getText(); | ||
|
||
$this->assertEquals($expected, $output); | ||
} | ||
} |