Skip to content

Commit 2f0d8c5

Browse files
committed
Fix the existing functional test for the module.
1 parent eaef9ff commit 2f0d8c5

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

tests/src/Functional/PatternkitTest.php

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,75 @@ class PatternkitTest extends BrowserTestBase {
2929
];
3030

3131
/**
32+
* Default Drupal theme for running tests.
33+
*
3234
* @var string
33-
* Default Drupal theme for running tests.
3435
*/
3536
protected $defaultTheme = 'stable';
3637

3738
/**
38-
* Verify that the toolbar tab and tray are showing and functioning.
39+
* Storage handler for patternkit_block content.
40+
*
41+
* @var \Drupal\Core\Entity\EntityStorageInterface
42+
*/
43+
protected $patternBlockStorage;
44+
45+
/**
46+
* Storage handler for patternkit_pattern content.
47+
*
48+
* @var \Drupal\Core\Entity\EntityStorageInterface
49+
*/
50+
protected $patternStorage;
51+
52+
/**
53+
* The patternkit library service.
54+
*
55+
* @var \Drupal\patternkit\Asset\Library
56+
*/
57+
protected $library;
58+
59+
/**
60+
* {@inheritdoc}
61+
*/
62+
public function setUp(): void {
63+
parent::setUp();
64+
65+
$entity_type_manager = $this->container->get('entity_type.manager');
66+
$this->patternBlockStorage = $entity_type_manager->getStorage('patternkit_block');
67+
$this->patternStorage = $entity_type_manager->getStorage('patternkit_pattern');
68+
$this->library = $this->container->get('patternkit.asset.library');
69+
}
70+
71+
/**
72+
* Verify creation, placement, and display of a patternkit block.
3973
*
4074
* @throws \Behat\Mink\Exception\ExpectationException
4175
* @throws \Behat\Mink\Exception\ResponseTextException
76+
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
77+
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
4278
* @throws \Drupal\Core\Entity\EntityStorageException
4379
*/
4480
public function testPatternkitExampleBlock() {
81+
// Create a block instance for placement.
4582
// @todo Remove this when
4683
// Drupal\patternkit\Plugin\Block\PatternkitBlock::setConfig
4784
// handles default block creation.
4885
/** @var \Drupal\patternkit\Entity\PatternkitBlock $patternkit_block */
49-
$patternkit_block = \Drupal::entityTypeManager()->getStorage('patternkit_block')->create([
86+
$patternkit_block = $this->patternBlockStorage->create([
5087
'data' => ['value' => '{}'],
5188
'info' => $this->randomMachineName(),
5289
'reusable' => FALSE,
5390
'published' => TRUE,
91+
'pattern_id' => '@patternkit/atoms/example/src/example',
5492
]);
5593
$patternkit_block->save();
56-
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $pattern_storage */
57-
$pattern_storage = \Drupal::entityTypeManager()->getStorage('patternkit_pattern');
94+
95+
// Identify and create the pattern entity to be used.
5896
$pattern_id = PatternkitBlock::derivativeToAssetId('patternkit_atoms_example_src_example');
59-
/** @var \Drupal\patternkit\Entity\PatternInterface $pattern */
60-
$pattern = Pattern::create(\Drupal::service('patternkit.asset.library')->getLibraryAsset($pattern_id));
61-
$pattern_cache = $pattern_storage->loadByProperties([
97+
$pattern = Pattern::create($this->library->getLibraryAsset($pattern_id));
98+
99+
// Load the pattern from storage.
100+
$pattern_cache = $this->patternStorage->loadByProperties([
62101
'library' => $pattern->getLibrary(),
63102
'path' => $pattern->getPath(),
64103
]);
@@ -75,7 +114,8 @@ public function testPatternkitExampleBlock() {
75114
}
76115
$pattern->save();
77116

78-
$this->drupalPlaceBlock('patternkit_block:patternkit_atoms_example_src_example', [
117+
// Place the block for viewing.
118+
$block = $this->drupalPlaceBlock('patternkit_block:patternkit_atoms_example_src_example', [
79119
'region' => 'content',
80120
'pattern' => $pattern->getRevisionId(),
81121
'patternkit_block_id' => $patternkit_block->id(),
@@ -84,9 +124,10 @@ public function testPatternkitExampleBlock() {
84124

85125
$assert = $this->assertSession();
86126

127+
// Expect to see the block content on the page request.
87128
$this->drupalGet('');
88129
$assert->statusCodeEquals(200);
89-
$assert->pageTextContains('Test sample twig template.');
130+
$assert->pageTextContains('Sample twig template.');
90131
}
91132

92133
}

0 commit comments

Comments
 (0)