toc/tests/MarkupFixerTest.php

71 строка
1.9 KiB
PHP
Исходник Обычный вид История

2014-12-30 18:53:32 +00:00
<?php
2015-01-22 21:52:45 +00:00
2014-12-30 18:53:32 +00:00
/**
* PHP TableOfContents Library
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/caseyamcl/toc
* @version 1.0
* @package caseyamcl/toc
* @author Casey McLaughlin <caseyamcl@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* ------------------------------------------------------------------
2014-12-30 18:53:32 +00:00
*/
namespace TOC;
2015-01-22 21:52:45 +00:00
class MarkupFixerTest extends \PHPUnit_Framework_TestCase
2014-12-30 18:53:32 +00:00
{
public function testInstantiateSucceeds()
{
$obj = new MarkupFixer();
$this->assertInstanceOf('\TOC\MarkupFixer', $obj);
2014-12-30 18:53:32 +00:00
}
// ---------------------------------------------------------------
public function testFixAddsIdsOnlyToElementsWithoutThem()
{
$obj = new MarkupFixer();
2014-12-30 18:53:32 +00:00
$html = "<h1>No ID</h1><h2>Existing ID</h2><h3>Ignored</h3>";
$this->assertEquals(
'<h1 id="no-id">No ID</h1><h2 id="existing-id">Existing ID</h2><h3>Ignored</h3>',
$obj->fix($html, 1, 2)
);
}
// ---------------------------------------------------------------
public function testFixDoesNotDuplicateIdsWhenFixing()
{
$obj = new MarkupFixer();
2014-12-30 18:53:32 +00:00
$html = "<h1>FooBar</h1><h2>FooBar</h2><h3>FooBar</h3>";
$this->assertEquals(
'<h1 id="foobar">FooBar</h1><h2 id="foobar-1">FooBar</h2><h3 id="foobar-2">FooBar</h3>',
$obj->fix($html, 1, 3)
);
}
// ---------------------------------------------------------------
public function testFixUsesTitleAttributeWhenAvailable()
{
$obj = new MarkupFixer();
2014-12-30 18:53:32 +00:00
$html = "<h1>No ID</h1><h2 title='b'>Existing ID</h2><h3>Ignored</h3>";
$this->assertEquals(
'<h1 id="no-id">No ID</h1><h2 title=\'b\' id="b">Existing ID</h2><h3>Ignored</h3>',
$obj->fix($html, 1, 2)
);
}
}