Skip to content

Commit a30c888

Browse files
committed
adding highlight.js integration test for current functionality
1 parent 1a2090b commit a30c888

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace SymfonyDocsBuilder\Tests\Templates;
4+
5+
use Highlight\Highlighter;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class HighlightJsIntegrationTest extends TestCase
9+
{
10+
public static function setUpBeforeClass()
11+
{
12+
Highlighter::registerLanguage('php', __DIR__.'/../../src/Templates/highlight.php/php.json', true);
13+
Highlighter::registerLanguage('twig', __DIR__.'/../../src/Templates/highlight.php/twig.json', true);
14+
}
15+
16+
/**
17+
* @dataProvider getRenderingTests
18+
*/
19+
public function testCustomRendering(string $language, string $inputFile, string $outputFile)
20+
{
21+
$highlighter = new Highlighter();
22+
$actual = $highlighter->highlight(
23+
$language,
24+
file_get_contents(__DIR__.'/fixtures/'.$inputFile)
25+
)->value;
26+
27+
$this->assertSame(file_get_contents(__DIR__.'/fixtures/'.$outputFile), $actual);
28+
}
29+
30+
public function getRenderingTests()
31+
{
32+
yield 'php' => [
33+
'php',
34+
'php.input.txt',
35+
'php.output.html'
36+
];
37+
38+
yield 'twig' => [
39+
'twig',
40+
'twig.input.txt',
41+
'twig.output.html'
42+
];
43+
}
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// src/Controller/BlogController.php
2+
namespace App\Controller;
3+
4+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
5+
use Symfony\Component\Routing\Annotation\Route;
6+
7+
class BlogController extends AbstractController
8+
{
9+
/**
10+
* Matches /blog exactly
11+
*
12+
* @Route("/blog/{slug}", name="blog_list")
13+
*/
14+
public function list(UrlGeneratorInterface $urlGenerator, string $slug)
15+
{
16+
return $this->render('foo/bar.html.twig', [
17+
'key' => $value
18+
]
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<span class="hljs-comment">// src/Controller/BlogController.php</span>
2+
<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Controller</span>;
3+
4+
<span class="hljs-keyword">use</span> <span class="hljs-title">Symfony</span>\<span class="hljs-title">Bundle</span>\<span class="hljs-title">FrameworkBundle</span>\<span class="hljs-title">Controller</span>\<span class="hljs-title">AbstractController</span>;
5+
<span class="hljs-keyword">use</span> <span class="hljs-title">Symfony</span>\<span class="hljs-title">Component</span>\<span class="hljs-title">Routing</span>\<span class="hljs-title">Annotation</span>\<span class="hljs-title">Route</span>;
6+
7+
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BlogController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">AbstractController</span>
8+
</span>{
9+
<span class="hljs-comment">/**
10+
* Matches /blog exactly
11+
*
12+
* <span class="hljs-doctag">@Route</span>("/blog/{slug}", name="blog_list")
13+
*/</span>
14+
<span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">list</span><span class="hljs-params">(UrlGeneratorInterface <span class="hljs-variable">$urlGenerator</span>, string <span class="hljs-variable">$slug</span>)</span>
15+
</span>{
16+
<span class="hljs-keyword">return</span> <span class="hljs-variable">$this</span><span class="hljs-operator">-&gt;</span>render(<span class="hljs-string">'foo/bar.html.twig'</span>, [
17+
<span class="hljs-string">'key'</span> =&gt; <span class="hljs-variable">$value</span>
18+
]
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Welcome to Symfony!</title>
5+
</head>
6+
<body>
7+
<h1>{{ page_title }}</h1>
8+
9+
<ul id="navigation">
10+
{% for item in navigation %}
11+
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
12+
{% endfor %}
13+
</ul>
14+
</body>
15+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<span class="xml"><span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
2+
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
3+
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
4+
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Welcome to Symfony!<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
5+
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
6+
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
7+
<span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span></span><span class="hljs-template-variable">{{ page_title }}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
8+
9+
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"navigation"</span>&gt;</span>
10+
</span><span class="hljs-template-tag">{% <span class="hljs-name"><span class="hljs-keyword">for</span></span> item in navigation %}</span><span class="xml">
11+
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"</span></span></span><span class="hljs-template-variable">{{ item.href }}</span><span class="xml"><span class="hljs-tag"><span class="hljs-string">"</span>&gt;</span></span><span class="hljs-template-variable">{{ item.caption }}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
12+
</span><span class="hljs-template-tag">{% <span class="hljs-name"><span class="hljs-keyword">endfor</span></span> %}</span><span class="xml">
13+
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
14+
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
15+
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></span>

0 commit comments

Comments
 (0)