mirror of
https://github.com/getgrav/grav.git
synced 2026-07-12 04:03:28 +02:00
Added start of Markdown tests
This commit is contained in:
74
tests/unit/Grav/Common/MarkdownTest.php
Normal file
74
tests/unit/Grav/Common/MarkdownTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Util\Fixtures;
|
||||
|
||||
/**
|
||||
* Class AssetsTest
|
||||
*/
|
||||
class MarkdownTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
protected $parsedown;
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$defaults = [
|
||||
'extra' => false,
|
||||
'auto_line_breaks' => false,
|
||||
'auto_url_links' => false,
|
||||
'escape_markup' => false,
|
||||
'special_chars' => ['>' => 'gt', '<' => 'lt'],
|
||||
];
|
||||
$page = new \Grav\Common\Page\Page();
|
||||
|
||||
$this->parsedown = new Parsedown($page, $defaults);
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
}
|
||||
|
||||
public function grav()
|
||||
{
|
||||
$grav = Fixtures::get('grav');
|
||||
return $grav;
|
||||
}
|
||||
|
||||
public function stripLeadingWhitespace($string)
|
||||
{
|
||||
return preg_replace('/^\s*(.*)/', '', $string);
|
||||
}
|
||||
|
||||
|
||||
public function testMarkdownSpecialProtocols()
|
||||
{
|
||||
$this->assertSame($this->parsedown->text('[mailto](mailto:user@domain.com)'), '<p><a href="mailto:user@domain.com">mailto</a></p>');
|
||||
$this->assertSame($this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'), '<p><a href="xmpp:xyx@domain.com">xmpp</a></p>');
|
||||
$this->assertSame($this->parsedown->text('[tel](tel:123-555-12345)'), '<p><a href="tel:123-555-12345">tel</a></p>');
|
||||
$this->assertSame($this->parsedown->text('[sms](sms:123-555-12345)'), '<p><a href="sms:123-555-12345">sms</a></p>');
|
||||
}
|
||||
|
||||
public function testMarkdownReferenceLinks()
|
||||
{
|
||||
$sample = '[relative link][r_relative]
|
||||
[r_relative]: ../03.assets#blah';
|
||||
$this->assertSame($this->parsedown->text($sample), '<p><a href="../03.assets#blah">relative link</a></p>');
|
||||
|
||||
$sample = '[absolute link][r_absolute]
|
||||
[r_absolute]: /blog/focus-and-blur#blah';
|
||||
$this->assertSame($this->parsedown->text($sample), '<p><a href="/blog/focus-and-blur#blah">absolute link</a></p>');
|
||||
|
||||
$sample = '[external link][r_external]
|
||||
[r_external]: http://www.cnn.com';
|
||||
$this->assertSame($this->parsedown->text($sample), '<p><a href="http://www.cnn.com">external link</a></p>');
|
||||
}
|
||||
|
||||
public function testMarkdownExternalLinks()
|
||||
{
|
||||
$this->assertSame($this->parsedown->text('[cnn.com](http://www.cnn.com)'), '<p><a href="http://www.cnn.com">cnn.com</a></p>');
|
||||
$this->assertSame($this->parsedown->text('[google.com](https://www.google.com)'), '<p><a href="https://www.google.com">google.com</a></p>');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user