-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow block rendering using Block core Wrapper - Issue 3110310 #39
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\bamboo_twig\Kernel\Loader; | ||
|
||
use Drupal\block\Entity\Block; | ||
use Drupal\block_content\Entity\BlockContent; | ||
use Drupal\KernelTests\KernelTestBase; | ||
use Drupal\Tests\block\Traits\BlockCreationTrait; | ||
use Drupal\Tests\bamboo_twig\Traits\BlockCreationTrait as BambooBlockCreationTrait; | ||
|
||
/** | ||
* @coversDefaultClass \Drupal\bamboo_twig_loader\TwigExtension\Loader | ||
* | ||
* @group bamboo_twig | ||
* @group bamboo_twig_loader | ||
*/ | ||
class EntityBlockTest extends KernelTestBase { | ||
use BlockCreationTrait; | ||
use BambooBlockCreationTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static $modules = [ | ||
'system', | ||
'user', | ||
'block', | ||
'block_content', | ||
'block_test', | ||
'field', | ||
'text', | ||
'bamboo_twig', | ||
'bamboo_twig_loader', | ||
]; | ||
|
||
/** | ||
* The renderer service. | ||
* | ||
* @var \Drupal\Core\Render\RendererInterface | ||
*/ | ||
protected $renderer; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->installEntitySchema('user'); | ||
$this->installEntitySchema('block_content'); | ||
$this->installConfig(['block_content']); | ||
$this->installConfig(['block_test']); | ||
|
||
$this->createBlockContentType('basic'); | ||
|
||
/** @var \Drupal\bamboo_twig_loader\TwigExtension\Loader $loaderExtension */ | ||
$this->loaderExtension = $this->container->get('bamboo_twig_loader.twig.loader'); | ||
} | ||
|
||
/** | ||
* @covers ::loadEntity | ||
* | ||
* Cover the usage of {{ bamboo_render_entity('block', 'stark_branding') }}. | ||
*/ | ||
public function testLoaderBlockEntity() { | ||
$entity = $this->loaderExtension->loadEntity('block', 'test_block'); | ||
$this->assertInstanceOf(Block::class, $entity); | ||
} | ||
|
||
/** | ||
* @covers ::loadEntity | ||
* | ||
* Cover the usage of {{ bamboo_render_entity('block_content', 1) }}. | ||
*/ | ||
public function testLoaderBlockContentEntity() { | ||
$block = $this->createBlockContent(); | ||
$entity = $this->loaderExtension->loadEntity('block_content', $block->id()); | ||
$this->assertInstanceOf(BlockContent::class, $entity); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\bamboo_twig\Kernel\Render; | ||
|
||
use Drupal\block_content\Entity\BlockContent; | ||
use Drupal\KernelTests\KernelTestBase; | ||
use Drupal\Tests\block\Traits\BlockCreationTrait; | ||
use Drupal\Tests\bamboo_twig\Traits\BlockCreationTrait as BambooBlockCreationTrait; | ||
|
||
/** | ||
* @coversDefaultClass \Drupal\bamboo_twig_loader\TwigExtension\Render | ||
* | ||
* @group bamboo_twig | ||
* @group bamboo_twig_render | ||
*/ | ||
class ContentBlockTest extends KernelTestBase { | ||
use BlockCreationTrait; | ||
use BambooBlockCreationTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static $modules = [ | ||
'system', | ||
'user', | ||
'block', | ||
'block_content', | ||
'field', | ||
'text', | ||
'bamboo_twig', | ||
'bamboo_twig_loader', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
$this->installEntitySchema('user'); | ||
$this->installEntitySchema('block_content'); | ||
$this->installConfig(['block_content']); | ||
|
||
$this->createBlockContentType('basic'); | ||
|
||
/** @var \Drupal\bamboo_twig_loader\TwigExtension\Render $renderExtension */ | ||
$this->renderExtension = $this->container->get('bamboo_twig_loader.twig.render'); | ||
} | ||
|
||
/** | ||
* @covers ::renderBlock | ||
* | ||
* Cover the usage of | ||
* {{ bamboo_render_block('block_content:ca1f2401-16a3-474b') }}. | ||
* {{ bamboo_render_block('block_content:ca1f2401-16a3-474b', [], FALSE) }}. | ||
*/ | ||
public function testRenderContentBlock() { | ||
$block = $this->createBlockContent(); | ||
$this->placeBlock('block_content:' . $block->uuid()); | ||
|
||
// Ensure {{ bamboo_render_block('block_content:ca1f2401-1') }}. | ||
$renderer = $this->renderExtension->renderBlock('block_content:' . $block->uuid(), [], FALSE); | ||
$this->assertArrayHasKey('#block_content', $renderer); | ||
$this->assertInstanceOf(BlockContent::class, $renderer['#block_content']); | ||
|
||
// Ensure {{ bamboo_render_block('block_content:ca1f2401-1', [], FALSE) }}. | ||
$renderer = $this->renderExtension->renderBlock('block_content:' . $block->uuid(), [], TRUE); | ||
$this->assertArrayHasKey('#theme', $renderer); | ||
$this->assertEquals('block', $renderer['#theme']); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\bamboo_twig\Kernel\Render; | ||
|
||
use Drupal\block\Entity\Block; | ||
use Drupal\Core\Render\Markup; | ||
use Drupal\KernelTests\KernelTestBase; | ||
|
||
/** | ||
* @coversDefaultClass \Drupal\bamboo_twig_loader\TwigExtension\Render | ||
* | ||
* @group bamboo_twig | ||
* @group bamboo_twig_render | ||
*/ | ||
class PluginBlockTest extends KernelTestBase { | ||
|
||
/** | ||
* The renderer service. | ||
* | ||
* @var \Drupal\Core\Render\RendererInterface | ||
*/ | ||
protected $renderer; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static $modules = [ | ||
'system', | ||
'user', | ||
'block', | ||
'block_test', | ||
'bamboo_twig', | ||
'bamboo_twig_loader', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
/** @var \Drupal\bamboo_twig_loader\TwigExtension\Render $renderExtension */ | ||
$this->renderExtension = $this->container->get('bamboo_twig_loader.twig.render'); | ||
|
||
$this->renderer = $this->container->get('renderer'); | ||
} | ||
|
||
/** | ||
* @covers ::renderBlock | ||
* | ||
* Cover the usage of {{ bamboo_render_block('system_powered_by_block') }}. | ||
*/ | ||
public function testRenderSystemPluginBlock() { | ||
Block::create([ | ||
'id' => $this->randomMachineName(), | ||
'plugin' => 'system_powered_by_block', | ||
]); | ||
|
||
// Ensure {{ bamboo_render_block('system_powered_by_block') }}. | ||
$renderer = $this->renderExtension->renderBlock('system_powered_by_block', [], FALSE); | ||
$this->assertSame(['#markup'], array_keys($renderer)); | ||
$markup = $this->renderer->renderRoot($renderer); | ||
$this->assertEquals('<span>Powered by <a href="https://www.drupal.org">Drupal</a></span>', $markup->__toString()); | ||
|
||
// Ensure {{ bamboo_render_block('test_settings_validation', [], TRUE) }}. | ||
$renderer = $this->renderExtension->renderBlock('system_powered_by_block', [], TRUE); | ||
$this->assertSame([ | ||
'#theme', | ||
'#attributes', | ||
'#contextual_links', | ||
'#configuration', | ||
'#plugin_id', | ||
'#base_plugin_id', | ||
'#derivative_plugin_id', | ||
'content', | ||
], array_keys($renderer)); | ||
$markup = $this->renderer->renderRoot($renderer); | ||
$this->assertEquals('<div role="complementary"> | ||
|
||
|
||
<span>Powered by <a href="https://www.drupal.org">Drupal</a></span> | ||
</div> | ||
', $markup->__toString()); | ||
} | ||
|
||
/** | ||
* @covers ::renderBlock | ||
* | ||
* Cover the usage of {{ bamboo_render_block('test_settings_validation') }}. | ||
*/ | ||
public function testRenderCustomPluginBlock() { | ||
// Ensure {{ bamboo_render_block('test_settings_validation') }}. | ||
$renderer = $this->renderExtension->renderBlock('test_settings_validation'); | ||
$this->assertSame(['#markup'], array_keys($renderer)); | ||
$markup = $this->renderer->renderRoot($renderer); | ||
$this->assertArrayHasKey('#markup', $renderer); | ||
$this->assertInstanceOf(Markup::class, $markup); | ||
$this->assertEquals('foo', $markup->__toString()); | ||
|
||
// Ensure {{ bamboo_render_block('test_settings_validation', [], TRUE) }}. | ||
$renderer = $this->renderExtension->renderBlock('test_settings_validation', [], TRUE); | ||
$this->assertSame([ | ||
'#theme', | ||
'#attributes', | ||
'#contextual_links', | ||
'#configuration', | ||
'#plugin_id', | ||
'#base_plugin_id', | ||
'#derivative_plugin_id', | ||
'content', | ||
], array_keys($renderer)); | ||
$markup = $this->renderer->renderRoot($renderer); | ||
$this->assertInstanceOf(Markup::class, $markup); | ||
$this->assertEquals('<div> | ||
|
||
|
||
foo | ||
</div> | ||
', $markup->__toString()); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the question about the default value is still open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to change the current working process, and so set it to false :)