|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Webfactory\ShortcodeBundle\Tests\Functional; |
|
4
|
|
|
|
|
5
|
|
|
use Generator; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
9
|
|
|
use Webfactory\ShortcodeBundle\Test\EndToEndTestHelper; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Test shortcode processing using EmbeddedShortcodeHandler and a fixture ShortodeTestController, |
|
13
|
|
|
* to make sure shortcodes defined in various places (DI config, bundle config) work as expected. |
|
14
|
|
|
*/ |
|
15
|
|
|
class EmbeddedShortcodeHandlerTest extends KernelTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** @test */ |
|
18
|
|
|
public function paragraphs_wrapping_shortcodes_get_removed(): void |
|
19
|
|
|
{ |
|
20
|
|
|
self::assertSame('test', $this->processShortcodes('<p>[test-config-inline]</p>')); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** @test */ |
|
24
|
|
|
public function content_without_shortcodes_wont_be_changed(): void |
|
25
|
|
|
{ |
|
26
|
|
|
self::assertSame('<p>Content without shortcode</p>', $this->processShortcodes('<p>Content without shortcode</p>')); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @test |
|
31
|
|
|
* @dataProvider provideShortcodeNames |
|
32
|
|
|
*/ |
|
33
|
|
|
public function expand_shortcodes_registered_in_different_ways(string $shortcodeName): void |
|
34
|
|
|
{ |
|
35
|
|
|
// All shortcodes are set up as fixtures and use ShortcodeTestController |
|
36
|
|
|
self::assertSame('test foo=bar', $this->processShortcodes("[$shortcodeName foo=bar]")); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function provideShortcodeNames(): Generator |
|
40
|
|
|
{ |
|
41
|
|
|
yield 'Inline shortcode defined in bundle config' => ['test-config-inline']; |
|
42
|
|
|
yield 'ESI-based shortcode defined in bundle config' => ['test-config-esi']; |
|
43
|
|
|
yield 'Inline shortcode defined in service definitions' => ['test-service-inline']; |
|
44
|
|
|
yield 'ESI-based shortcode defined in service definitions' => ['test-service-esi']; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @test |
|
49
|
|
|
* @dataProvider provideEsiShortcodes |
|
50
|
|
|
*/ |
|
51
|
|
|
public function processing_with_esi_fragments(string $shortcodeName): void |
|
52
|
|
|
{ |
|
53
|
|
|
$request = new Request([], [], [], [], [], ['SCRIPT_URL' => '/', 'HTTP_HOST' => 'localhost']); |
|
54
|
|
|
$request->headers->set('Surrogate-Capability', 'ESI/1.0'); |
|
55
|
|
|
|
|
56
|
|
|
self::assertStringContainsString('<esi:include ', $this->processShortcodes("[$shortcodeName foo=bar]", $request)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function provideEsiShortcodes(): Generator |
|
60
|
|
|
{ |
|
61
|
|
|
yield 'ESI-based shortcode defined in bundle configuration' => ['test-config-esi']; |
|
62
|
|
|
yield 'ESI-based shortcode defined in service configuration' => ['test-service-esi']; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function processShortcodes(string $content, Request $request = null): string |
|
66
|
|
|
{ |
|
67
|
|
|
self::bootKernel(); |
|
68
|
|
|
|
|
69
|
|
|
if ($request) { |
|
70
|
|
|
static::$container->get(RequestStack::class)->push($request); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return EndToEndTestHelper::createFromContainer(static::$container)->processShortcode($content); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|