|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\Tests\graphql_core\Kernel\Blocks; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\block_content\Entity\BlockContent; |
|
6
|
|
|
use Drupal\simpletest\BlockCreationTrait; |
|
7
|
|
|
use Drupal\Tests\graphql\Kernel\GraphQLFileTestBase; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Test block retrieval via GraphQL. |
|
11
|
|
|
* |
|
12
|
|
|
* @group graphql_block |
|
13
|
|
|
*/ |
|
14
|
|
|
class BlockTest extends GraphQLFileTestBase { |
|
15
|
|
|
use BlockCreationTrait; |
|
16
|
|
|
/** |
|
17
|
|
|
* {@inheritdoc} |
|
18
|
|
|
*/ |
|
19
|
|
|
public static $modules = [ |
|
20
|
|
|
'system', |
|
21
|
|
|
'block', |
|
22
|
|
|
'block_content', |
|
23
|
|
|
'text', |
|
24
|
|
|
'field', |
|
25
|
|
|
'filter', |
|
26
|
|
|
'editor', |
|
27
|
|
|
'ckeditor', |
|
28
|
|
|
'graphql_core', |
|
29
|
|
|
'graphql_block_test', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function setUp() { |
|
36
|
|
|
parent::setUp(); |
|
37
|
|
|
|
|
38
|
|
|
/** @var \Drupal\Core\Extension\ThemeInstallerInterface $themeInstaller */ |
|
39
|
|
|
$themeInstaller = $this->container->get('theme_installer'); |
|
40
|
|
|
$themeInstaller->install(['stark']); |
|
41
|
|
|
|
|
42
|
|
|
$this->installEntitySchema('block_content'); |
|
43
|
|
|
$this->installConfig('block_content'); |
|
44
|
|
|
$this->installConfig('graphql_block_test'); |
|
45
|
|
|
|
|
46
|
|
|
$customBlock = BlockContent::create([ |
|
47
|
|
|
'type' => 'basic', |
|
48
|
|
|
'info' => 'Custom block test', |
|
49
|
|
|
'body' => [ |
|
50
|
|
|
'value' => '<p>This is a test block content.</p>', |
|
51
|
|
|
'format' => 'basic_html', |
|
52
|
|
|
], |
|
53
|
|
|
]); |
|
54
|
|
|
|
|
55
|
|
|
$customBlock->save(); |
|
56
|
|
|
|
|
57
|
|
|
$this->placeBlock('block_content:' . $customBlock->uuid(), [ |
|
58
|
|
|
'region' => 'sidebar_first', |
|
59
|
|
|
]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Test if two static blocks are in the content area. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testStaticBlocks() { |
|
66
|
|
|
$result = $this->executeQueryFile('Blocks/blocks.gql'); |
|
67
|
|
|
$this->assertEquals(1, count($result['data']['content']), 'Blocks can be retrieved on root level.'); |
|
68
|
|
|
$this->assertEquals(1, count($result['data']['route']['content']), 'Block listing respects visibility settings.'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Test placement of a content block. |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testContentBlock() { |
|
75
|
|
|
$result = $this->executeQueryFile('Blocks/blocks.gql'); |
|
76
|
|
|
$this->assertEquals(1, count($result['data']['route']['sidebar']), 'One content block in sidebar region.'); |
|
77
|
|
|
$this->assertEquals('<p>This is a test block content.</p>', $result['data']['route']['sidebar'][0]['body']['value'], 'Content block body contains expected text.'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|