Skip to content
Snippets Groups Projects
Commit d4db4e2b authored by Luke Leber's avatar Luke Leber Committed by Sean Adams-Hiett
Browse files

Fix schema; add tests.

parent cac140f8
No related branches found
No related tags found
No related merge requests found
use_popover: 0
trigger_label: 'Add block'
use_label: 0
label: 'Add block'
......@@ -2,7 +2,7 @@ lb_direct_add.settings:
type: config_object
mapping:
use_label:
type: string
type: integer
label: "How to display the blocks to be added"
label:
type: string
......
<?php
namespace Drupal\Tests\lb_direct_add\FunctionalJavascript;
/**
* Contains test cases for dropbutton functionality.
*
* @group lb_direct_add
*/
class LayoutBuilderDirectAddDropbuttonTest extends LayoutBuilderDirectAddTestBase {
/**
* Test case for dropbutton functionality.
*/
public function testDropbutton() {
$this->drupalLogin($this->drupalCreateUser([], NULL, TRUE));
$this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
$page = $this->getSession()->getPage();
$dropbutton_action = $page->findLink('Basic block');
static::assertNotNull($dropbutton_action);
static::assertTrue($dropbutton_action->isVisible());
static::assertEquals(static::BASIC_BLOCK_HREF, $dropbutton_action->getAttribute('href'));
// Make sure the more option is not visible by default.
$dropbutton_more = $page->findLink('More options');
static::assertNotNull($dropbutton_more);
static::assertFalse($dropbutton_more->isVisible());
static::assertEquals(static::CHOOSE_BLOCK_HREF, $dropbutton_more->getAttribute('href'));
$dropbutton_toggle = $page->findButton('List additional actions');
static::assertNotNull($dropbutton_toggle);
static::assertTrue($dropbutton_toggle->isVisible());
$dropbutton_toggle->click();
static::assertTrue($dropbutton_more->isVisible());
$dropbutton_toggle->click();
static::assertFalse($dropbutton_more->isVisible());
}
}
<?php
namespace Drupal\Tests\lb_direct_add\FunctionalJavascript;
/**
* Contains test cases for popover functionality.
*
* @group lb_direct_add
*/
class LayoutBuilderDirectAddPopoverTest extends LayoutBuilderDirectAddTestBase {
/**
* Test case for popover functionality.
*/
public function testPopover() {
$this->setUsePopover(1);
$this->drupalLogin($this->drupalCreateUser([], NULL, TRUE));
$this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
$page = $this->getSession()->getPage();
$add_block = $page->findLink('Add block');
static::assertNotNull($add_block);
static::assertTrue($add_block->isVisible());
$this->setTriggerLabel('Add a block');
$this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
$add_block = $page->findLink('Add block');
static::assertNull($add_block);
$add_block = $page->findLink('Add a block');
static::assertNotNull($add_block);
static::assertTrue($add_block->isVisible());
$basic_block = $page->findLink('Basic block');
$more = $page->findLink('More options');
static::assertNotNull($basic_block);
static::assertNotNull($more);
static::assertEquals(static::BASIC_BLOCK_HREF, $basic_block->getAttribute('href'));
static::assertEquals(static::CHOOSE_BLOCK_HREF, $more->getAttribute('href'));
static::assertFalse($basic_block->isVisible());
static::assertFalse($more->isVisible());
$add_block->click();
static::assertTrue($basic_block->isVisible());
static::assertTrue($more->isVisible());
$add_block->click();
static::assertFalse($basic_block->isVisible());
static::assertFalse($more->isVisible());
}
}
<?php
namespace Drupal\Tests\lb_direct_add\FunctionalJavascript;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Base class for layout builder direct add javascript tests.
*/
abstract class LayoutBuilderDirectAddTestBase extends WebDriverTestBase {
/**
* Path prefix for the field UI for the test bundle.
*/
protected const FIELD_UI_PREFIX = 'admin/structure/types/manage/bundle_with_section_field';
/**
* Known href attribute for adding a basic block.
*/
protected const BASIC_BLOCK_HREF = '/layout_builder/add/block/defaults/node.bundle_with_section_field.default/0/content/inline_block%3Abasic';
/**
* Known href attribute for adding a block through the core chooser.
*/
protected const CHOOSE_BLOCK_HREF = '/layout_builder/choose/block/defaults/node.bundle_with_section_field.default/0/content';
/**
* {@inheritdoc}
*/
protected static $modules = [
'block_content',
'layout_builder',
'block',
'node',
'contextual',
'lb_direct_add',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Sets a new drop button display option.
*
* @param int $setting
* The new drop button display option.
*/
protected function setUsePopover($setting) {
$this->config('lb_direct_add.settings')
->set('use_popover', $setting)
->save();
}
/**
* Sets a new trigger label.
*
* @param string $setting
* The new label.
*/
protected function setTriggerLabel($setting) {
$this->config('lb_direct_add.settings')
->set('trigger_label', $setting)
->save();
}
/**
* {@inheritdoc}
*
* Sets up the content types required for lb_direct_add tests.
*/
protected function setUp() {
parent::setUp();
$this->createContentType([
'type' => 'bundle_with_section_field',
'new_revision' => TRUE,
]);
/** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display */
$display = \Drupal::service('entity_display.repository')->getViewDisplay('node', 'bundle_with_section_field');
$display->enableLayoutBuilder()->setOverridable()->save();
$bundle = BlockContentType::create([
'id' => 'basic',
'label' => 'Basic block',
'revision' => 1,
]);
$bundle->save();
block_content_add_body_field($bundle->id());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment