diff core/modules/block/tests/src/Functional/BlockUiTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children af1871eacc83
line wrap: on
line diff
--- a/core/modules/block/tests/src/Functional/BlockUiTest.php	Tue Jul 10 15:07:59 2018 +0100
+++ b/core/modules/block/tests/src/Functional/BlockUiTest.php	Thu Feb 28 13:21:36 2019 +0000
@@ -3,6 +3,8 @@
 namespace Drupal\Tests\block\Functional;
 
 use Drupal\Component\Utility\Html;
+use Drupal\language\Entity\ConfigurableLanguage;
+use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
 use Drupal\Tests\BrowserTestBase;
 
 /**
@@ -239,6 +241,13 @@
     $this->assertText('User context found.');
     $this->assertRaw($expected_text);
 
+    // Test context mapping form element is not visible if there are no valid
+    // context options for the block (the test_context_aware_no_valid_context_options
+    // block has one context defined which is not available for it on the
+    // Block Layout interface).
+    $this->drupalGet('admin/structure/block/add/test_context_aware_no_valid_context_options/classy');
+    $this->assertSession()->fieldNotExists('edit-settings-context-mapping-email');
+
     // Test context mapping allows empty selection for optional contexts.
     $this->drupalGet('admin/structure/block/manage/testcontextawareblock');
     $edit = [
@@ -281,6 +290,24 @@
    * Tests the block placement indicator.
    */
   public function testBlockPlacementIndicator() {
+    // Test the block placement indicator with using the domain as URL language
+    // indicator. This causes destination query parameters to be absolute URLs.
+    \Drupal::service('module_installer')->install(['language', 'locale']);
+    $this->container = \Drupal::getContainer();
+    ConfigurableLanguage::createFromLangcode('it')->save();
+    $config = $this->config('language.types');
+    $config->set('negotiation.language_interface.enabled', [
+      LanguageNegotiationUrl::METHOD_ID => -10,
+    ]);
+    $config->save();
+    $config = $this->config('language.negotiation');
+    $config->set('url.source', LanguageNegotiationUrl::CONFIG_DOMAIN);
+    $config->set('url.domains', [
+      'en' => \Drupal::request()->getHost(),
+      'it' => 'it.example.com',
+    ]);
+    $config->save();
+
     // Select the 'Powered by Drupal' block to be placed.
     $block = [];
     $block['id'] = strtolower($this->randomMachineName());
@@ -289,11 +316,30 @@
 
     // After adding a block, it will indicate which block was just added.
     $this->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, t('Save block'));
-    $this->assertUrl('admin/structure/block/list/classy?block-placement=' . Html::getClass($block['id']));
+    $this->assertSession()->addressEquals('admin/structure/block/list/classy?block-placement=' . Html::getClass($block['id']));
 
-    // Resaving the block page will remove the block indicator.
+    // Resaving the block page will remove the block placement indicator.
     $this->drupalPostForm(NULL, [], t('Save blocks'));
-    $this->assertUrl('admin/structure/block/list/classy');
+    $this->assertSession()->addressEquals('admin/structure/block/list/classy');
+
+    // Place another block and test the remove functionality works with the
+    // block placement indicator. Click the first 'Place block' link to bring up
+    // the list of blocks to place in the first available region.
+    $this->clickLink('Place block');
+    // Select the first available block.
+    $this->clickLink('Place block');
+    $block = [];
+    $block['id'] = strtolower($this->randomMachineName());
+    $block['theme'] = 'classy';
+    $this->submitForm([], 'Save block');
+    $this->assertSession()->addressEquals('admin/structure/block/list/classy?block-placement=' . Html::getClass($block['id']));
+
+    // Removing a block will remove the block placement indicator.
+    $this->clickLink('Remove');
+    $this->submitForm([], 'Remove');
+    // @todo https://www.drupal.org/project/drupal/issues/2980527 this should be
+    //   'admin/structure/block/list/classy' but there is a bug.
+    $this->assertSession()->addressEquals('admin/structure/block');
   }
 
   /**