|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Webfactory\ShortcodeBundle\Tests\Functional; |
|
4
|
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
use RuntimeException; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
8
|
|
|
use Thunder\Shortcode\Handler\PlaceholderHandler; |
|
9
|
|
|
use Webfactory\ShortcodeBundle\Test\ShortcodeDefinitionTestHelper; |
|
10
|
|
|
use Webfactory\ShortcodeBundle\Tests\Fixtures\Controller\ShortcodeTestController; |
|
11
|
|
|
|
|
12
|
|
|
class ShortcodeDefinitionTestHelperTest extends KernelTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var ShortcodeDefinitionTestHelper |
|
16
|
|
|
*/ |
|
17
|
|
|
private $helper; |
|
18
|
|
|
|
|
19
|
|
|
protected function setUp(): void |
|
20
|
|
|
{ |
|
21
|
|
|
self::bootKernel(); |
|
22
|
|
|
$this->helper = static::$container->get(ShortcodeDefinitionTestHelper::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @test |
|
27
|
|
|
*/ |
|
28
|
|
|
public function throws_exception_for_handlers_that_do_not_use_controllers(): void |
|
29
|
|
|
{ |
|
30
|
|
|
self::expectException(RuntimeException::class); |
|
|
|
|
|
|
31
|
|
|
$this->helper->resolveShortcodeController('placeholder'); // uses the \Thunder\Shortcode\Handler\PlaceholderHandler handler class directly |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @test |
|
36
|
|
|
*/ |
|
37
|
|
|
public function throws_exception_for_shortcode_with_unresolvable_controller(): void |
|
38
|
|
|
{ |
|
39
|
|
|
self::expectException(InvalidArgumentException::class); |
|
|
|
|
|
|
40
|
|
|
$this->helper->resolveShortcodeController('test-config-invalid-controller'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
*/ |
|
46
|
|
|
public function can_test_whether_shortcode_is_defined(): void |
|
47
|
|
|
{ |
|
48
|
|
|
self::assertTrue($this->helper->hasShortcode('placeholder')); |
|
49
|
|
|
self::assertFalse($this->helper->hasShortcode('unknown-shortcode')); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @test |
|
54
|
|
|
*/ |
|
55
|
|
|
public function can_retrieve_handler(): void |
|
56
|
|
|
{ |
|
57
|
|
|
self::assertInstanceOf(PlaceholderHandler::class, $this->helper->getHandler('placeholder')); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @test |
|
62
|
|
|
*/ |
|
63
|
|
|
public function can_be_used_to_assert_controller_class_and_method(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$controller = $this->helper->resolveShortcodeController('test-config-inline'); |
|
66
|
|
|
|
|
67
|
|
|
self::assertInstanceOf(ShortcodeTestController::class, $controller[0]); |
|
68
|
|
|
self::assertSame('test', $controller[1]); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|