Commit ba62969a authored by Marco Villegas's avatar Marco Villegas
Browse files

block_example module updates to follow core changes

- Follow core b435b703d6f639c58f733de2ea11c795d0f53e3e, see #2056513,
  PluginUI subsystem is removed, so change urls on test.
- Follow core fd9804d886a5dfabbf5fd01dd49e73c7c3e35ad0, see #2014215,
  BlockBase no longer provides a default build().
- Follow core 202fe604b47bb096434d21b7cd07a79486f5ee1f, see #1986802,
  PluginInspectionInterface's getDefinition() is now
  getPluginDefinition().
- Use WebTestBase::drupalPlaceBlock() on the block test.
parent fc1c5974
Loading
Loading
Loading
Loading
+1 −1
Changes for block_example/block_example.module: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ function block_example_page() {
 */
function block_example_block_view_alter(array &$build, \Drupal\block\BlockPluginInterface $block) {
  // We'll search for the string 'uppercase'.
  $definition = $block->getDefinition();
  $definition = $block->getPluginDefinition();
  if ((!empty($build['#configuration']['label']) && stristr($build['#configuration']['label'], 'uppercase')) || (!empty($definition['subject']) && stristr($definition['subject'], 'uppercase'))) {
    // This will uppercase the block title.
    $build['#configuration']['label'] = drupal_strtoupper($build['#configuration']['label']);
+1 −1
Changes for block_example/lib/Drupal/block_example/Plugin/Block/ExampleConfigurableTextBlock.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ public function blockSubmit($form, &$form_state) {
  /**
   * Implements \Drupal\block\BlockBase::blockBuild().
   */
  public function blockBuild() {
  public function build() {
    return array(
      '#type' => 'markup',
      '#markup' => $this->configuration['block_example_string'],
+1 −1
Changes for block_example/lib/Drupal/block_example/Plugin/Block/ExampleEmptyBlock.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class ExampleEmptyBlock extends BlockBase {
  /**
   * Implements \Drupal\block\BlockBase::blockBuild().
   */
  public function blockBuild() {
  public function build() {
    return array();
  }

+1 −1
Changes for block_example/lib/Drupal/block_example/Plugin/Block/ExampleUppercaseBlock.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class ExampleUppercaseBlock extends BlockBase {
  /**
   * Implements \Drupal\block\BlockBase::blockBuild().
   */
  public function blockBuild() {
  public function build() {
    return array(
      '#type' => 'markup',
      '#markup' => t("This block's title will be changed to uppercase. Any other block with 'uppercase' in the subject or title will also be altered. If you change this block's title through the UI to omit the word 'uppercase', it will still be altered to uppercase as the subject key has not been changed."),
+22 −35
Changes for block_example/lib/Drupal/block_example/Tests/BlockExampleTest.php: 22 added lines, 35 removed lines.
Original line number Diff line number Diff line
@@ -39,63 +39,50 @@ function setUp() {
  }

  /**
   * Login user, create an example node, and test block functionality through
   * the admin and user interfaces.
   * Tests block_example functionality.
   */
  function testBlockExampleBasic() {
    // Login the admin user.
    $this->drupalLogin($this->web_user);
    $theme_name = config('system.theme')->get('default');

    // Find the blocks in the settings page.
    $this->drupalGet('admin/structure/block/list/block_plugin_ui:' . $theme_name . '/add');
    // Verify the blocks are listed to be added.
    $this->drupalGet('admin/structure/block/list/' . $theme_name . '/add');
    $this->assertRaw(t('Title of first block (example_configurable_text)'), 'Block configurable-string found.');
    $this->assertRaw(t('Example: empty block'), 'Block empty-block found.');
    $this->assertRaw(t('Example: uppercase this please'), 'Block uppercase found.');

    // Add blocks
    // Create a new block and make sure it gets uppercased.
    $edit = array(
      'settings[label]' => t('Title of first block (example_configurable_text)'),
    // Define and place blocks.
    $example_configurable_text = array(
      'label' => t('Title of first block (example_configurable_text)'),
      'machine_name' => 'block_example_example_configurable_text',
      'region' => 'sidebar_first',
    );
    $this->drupalPost('admin/structure/block/add/example_configurable_text/' . $theme_name , $edit, t('Save block'));
    $this->assertText(t('The block configuration has been saved.'));
    $this->assertText($edit['settings[label]']);

    $this->drupalGet('admin/structure/block');
    $this->assertLinkByHref(url('admin/structure/block/manage/' . $theme_name . '.block_example_example_configurable_text/configure'));

    $edit = array(
      'settings[label]' => t('Configurable block to be uppercased'),
    $this->drupalPlaceBlock('example_configurable_text', $example_configurable_text, $theme_name);
    $example_uppercase = array(
      'label' => t('Configurable block to be uppercased'),
      'machine_name' => 'uppercased_block',
      'region' => 'sidebar_first',
    );
    $this->drupalPost('admin/structure/block/add/example_uppercase/' . $theme_name, $edit, t('Save block'));

    $edit = array(
      'settings[label]' => t('Example: empty block'),
    $this->drupalPlaceBlock('example_uppercase', $example_uppercase, $theme_name);
    $example_empty = array(
      'label' => t('Example: empty block'),
      'machine_name' => 'block_example_example_empty',
      'region' => 'sidebar_first',
    );
    $this->drupalPost('admin/structure/block/add/example_empty/' . $theme_name, $edit, t('Save block'));

    // Verify that blocks are not shown
    $this->drupalGet('/');
    $this->assertRaw(t('Title of first block (example_configurable_text)'), 'Block configurable test not found.');
    $this->assertNoRaw(t('Title of second block (example_empty)'), 'Block empty not found.');
    $this->drupalPlaceBlock('example_empty', $example_empty, $theme_name);

    // Verify that blocks are there. Empty block will not be shown, because it is empty
    // Verify that blocks are there. Empty block will not be shown, because it is empty.
    $this->drupalGet('/');
    $this->assertRaw(t('Title of first block (example_configurable_text)'), 'Block configurable text found.');
    $this->assertRaw($example_configurable_text['label'], 'Block configurable test not found.');
    $this->assertNoRaw($example_uppercase['label'], 'Block uppercase with normal label not found.');
    $this->assertRaw(drupal_strtoupper($example_uppercase['label']), 'Block uppercase with uppercased label found.');
    $this->assertNoRaw($example_empty['label'], 'Block empty not found.');

    // Change content of configurable text block
    // Change content of configurable text block.
    $edit = array(
      'settings[block_example_string_text]' => $this->randomName(),
    );
    $this->drupalPost('admin/structure/block/manage/' . $theme_name . '.block_example_example_configurable_text/configure', $edit, t('Save block'));
    $this->drupalPost('admin/structure/block/manage/' . $theme_name . '.block_example_example_configurable_text', $edit, t('Save block'));

    // Verify that new content is shown
    // Verify that new content is shown.
    $this->drupalGet('/');
    $this->assertRaw($edit['settings[block_example_string_text]'], 'Content of configurable text block successfully verified.');
  }