Skip to content

Commit 109a6d9

Browse files
committed
Add tests for AppExtension
1 parent 7514fb0 commit 109a6d9

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/AppBundle/Twig/AppExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public function __construct(Parser $parser)
3030
*/
3131
public function getFilters()
3232
{
33-
return array(
33+
return [
3434
new \Twig_SimpleFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
35-
);
35+
];
3636
}
3737

3838
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1>Heading 1</h1>
2+
<p>Text</p>
3+
<h2>Heading 2</h2>
4+
<pre><code class="language-php">$code = true;</code></pre>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Heading 1
2+
3+
Text
4+
5+
## Heading 2
6+
7+
```php
8+
$code = true;
9+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Tests\AppBundle\Twig;
4+
5+
use AppBundle\Twig\AppExtension;
6+
use Mni\FrontYAML\Parser;
7+
8+
class AppExtensionTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @dataProvider markdownProvider
12+
*/
13+
public function testMarkdownToHtml($md, $expected)
14+
{
15+
$parser = new Parser();
16+
$appExtension = new AppExtension($parser);
17+
$html = $appExtension->markdownToHtml($md);
18+
$this->assertEquals($html, $expected);
19+
}
20+
21+
public static function markdownProvider()
22+
{
23+
return [
24+
[file_get_contents(__DIR__.'/../Fixtures/content_1.md'), file_get_contents(__DIR__.'/../Fixtures/content_1.html')]
25+
];
26+
}
27+
}

0 commit comments

Comments
 (0)