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_core\Kernel\GraphQLCoreTestBase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Test block retrieval via GraphQL. |
11
|
|
|
* |
12
|
|
|
* @group graphql_block |
13
|
|
|
*/ |
14
|
|
|
class BlockTest extends GraphQLCoreTestBase { |
15
|
|
|
use BlockCreationTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
public static $modules = [ |
21
|
|
|
'block', |
22
|
|
|
'block_content', |
23
|
|
|
'text', |
24
|
|
|
'field', |
25
|
|
|
'filter', |
26
|
|
|
'editor', |
27
|
|
|
'ckeditor', |
28
|
|
|
'graphql_block_test', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function setUp() { |
35
|
|
|
parent::setUp(); |
36
|
|
|
|
37
|
|
|
/** @var \Drupal\Core\Extension\ThemeInstallerInterface $themeInstaller */ |
38
|
|
|
$themeInstaller = $this->container->get('theme_installer'); |
39
|
|
|
$themeInstaller->install(['stark']); |
40
|
|
|
|
41
|
|
|
$this->installEntitySchema('block_content'); |
42
|
|
|
$this->installConfig('block_content'); |
43
|
|
|
$this->installConfig('graphql_block_test'); |
44
|
|
|
|
45
|
|
|
$this->prophesize(BlockContent::class); |
46
|
|
|
|
47
|
|
|
$customBlock = BlockContent::create([ |
48
|
|
|
'type' => 'basic', |
49
|
|
|
'info' => 'Custom block test', |
50
|
|
|
'body' => [ |
51
|
|
|
'value' => '<p>This is a test block content.</p>', |
52
|
|
|
'format' => 'basic_html', |
53
|
|
|
], |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
$customBlock->save(); |
57
|
|
|
|
58
|
|
|
$this->placeBlock('block_content:' . $customBlock->uuid(), [ |
59
|
|
|
'region' => 'sidebar_first', |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Test if two static blocks are in the content area. |
65
|
|
|
*/ |
66
|
|
|
public function testStaticBlocks() { |
67
|
|
|
$query = $this->getQueryFromFile('Blocks/blocks.gql'); |
68
|
|
|
$metadata = $this->defaultCacheMetaData(); |
69
|
|
|
|
70
|
|
|
// TODO: Check cache metadata. |
71
|
|
|
$metadata->addCacheTags([ |
72
|
|
|
'block_content:1', |
73
|
|
|
'config:block.block.stark_powered', |
74
|
|
|
'config:field.storage.block_content.body', |
75
|
|
|
'entity_bundles', |
76
|
|
|
'entity_field_info', |
77
|
|
|
'entity_types', |
78
|
|
|
]); |
79
|
|
|
|
80
|
|
|
$this->assertResults($query, [], [ |
81
|
|
|
'route' => [ |
82
|
|
|
'content' => [ |
83
|
|
|
0 => [ |
84
|
|
|
'__typename' => 'UnexposedEntity', |
85
|
|
|
], |
86
|
|
|
], |
87
|
|
|
'sidebar' => [ |
88
|
|
|
0 => [ |
89
|
|
|
'__typename' => 'BlockContentBasic', |
90
|
|
|
'body' => [ |
91
|
|
|
'value' => '<p>This is a test block content.</p>', |
92
|
|
|
], |
93
|
|
|
], |
94
|
|
|
], |
95
|
|
|
], |
96
|
|
|
], $metadata); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|