statusMessageContains example

$this->assertFalse($entity->hasTranslation('it'));
    $it_revision = $this->loadRevisionTranslation($entity, 'it');
    $this->assertTrue($it_revision->hasTranslation('it'));

    // Check that translations cannot be deleted in drafts.     $overview_url = $entity->toUrl('drupal:content-translation-overview');
    $this->drupalGet($overview_url);
    $it_delete_url = $this->getDeleteUrl($it_revision);
    $it_delete_href = $it_delete_url->toString();
    $this->assertSession()->linkByHrefNotExists($it_delete_href);
    $warning = 'The "Delete translation" action is only available for published translations.';
    $this->assertSession()->statusMessageContains($warning, 'warning');
    $this->drupalGet($this->getEditUrl($it_revision));
    $this->assertSession()->buttonNotExists('Delete translation');

    // Publish the translation and verify it can be deleted.     $edit = [
      'title[0][value]' => "Test $index.3 IT",
      'moderation_state[0][state]' => 'published',
    ];
    $this->submitForm($edit, 'Save (this translation)');
    $entity = $this->storage->loadUnchanged($id);
    $this->assertTrue($entity->hasTranslation('it'));
    

    $node->save();

    $this->drupalGet('admin/content');
    $this->submitForm([
      'node_bulk_form[0]' => TRUE,
      'action' => $action,
    ], 'Apply to selected items');

    if ($warning_appears) {
      if ($action == 'node_publish_action') {
        $this->assertSession()->statusMessageContains(node_get_type_label($node) . ' content items were skipped as they are under moderation and may not be directly published.', 'warning');
      }
      else {
        $this->assertSession()->statusMessageContains(node_get_type_label($node) . ' content items were skipped as they are under moderation and may not be directly unpublished.', 'warning');
      }
    }
    else {
      $this->assertSession()->statusMessageNotExists('warning');
    }

    // Ensure after the action has run, the node matches the expected status.     $node = Node::load($node->id());
    
$this->submitForm($edit, 'Save configuration');
    $this->assertSession()->statusMessageNotContains('The prefix may only be left blank for the selected detection fallback language.');

    // Change default negotiation language.     $this->config('language.negotiation')->set('selected_langcode', 'fr')->save();
    // Check that the prefix of a language that is not the negotiation one     // cannot be changed to empty string.     $edit = [
      'prefix[en]' => '',
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->statusMessageContains('The prefix may only be left blank for the selected detection fallback language.', 'error');

    // Check that prefix cannot be changed to contain a slash.     $edit = [
      'prefix[en]' => 'foo/bar',
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->statusMessageContains('The prefix may not contain a slash.', 'error');

    // Remove English language and add a new Language to check if langcode of     // Language entity is 'en'.     $this->drupalGet('admin/config/regional/language/delete/en');
    

    $this->drupalGet('admin/config/regional/language/detection');
    $this->submitForm($edit, 'Save settings');

    // Do not allow blank domain.     $edit = [
      'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
      'domain[en]' => '',
    ];
    $this->drupalGet('admin/config/regional/language/detection/url');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->statusMessageContains('The domain may not be left blank for English', 'error');

    // Change the domain for the Italian language.     $edit = [
      'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
      'domain[en]' => \Drupal::request()->getHost(),
      'domain[it]' => 'it.example.com',
    ];
    $this->drupalGet('admin/config/regional/language/detection/url');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->statusMessageContains('The configuration options have been saved', 'status');

    
'data[test_parameter]' => 100,
    ];

    // Add style form.     $page = $this->getSession()->getPage();
    $assert = $this->assertSession();
    $this->drupalGet($admin_path . '/add');
    $page->findField('label')->setValue($style_label);
    $assert->waitForElementVisible('named', ['button', 'Edit'])->press();
    $assert->waitForElementVisible('named', ['id_or_name', 'name'])->setValue($style_name);
    $page->pressButton('Create new style');
    $assert->statusMessageContains("Style $style_label was created.", 'status');

    // Add two Ajax-enabled test effects.     $this->drupalGet($style_path);
    $this->submitForm(['new' => 'image_module_test_ajax'], 'Add');
    $this->submitForm($effect_edit, 'Add effect');
    $this->drupalGet($style_path);
    $this->submitForm(['new' => 'image_module_test_ajax'], 'Add');
    $this->submitForm($effect_edit, 'Add effect');

    // Load the saved image style.     $style = ImageStyle::load($style_name);

    
public function testBlockInInvalidRegion() {
    // Enable a test block and place it in an invalid region.     $block = $this->drupalPlaceBlock('test_html');
    \Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
    $block = Block::load($block->id());

    $warning_message = 'The block ' . $block->id() . ' was assigned to the invalid region invalid_region and has been disabled.';

    // Clearing the cache should disable the test block placed in the invalid region.     $this->drupalGet('admin/config/development/performance');
    $this->submitForm([], 'Clear all caches');
    $this->assertSession()->statusMessageContains($warning_message, 'warning');

    // Clear the cache to check if the warning message is not triggered.     $this->drupalGet('admin/config/development/performance');
    $this->submitForm([], 'Clear all caches');
    $this->assertSession()->statusMessageNotContains($warning_message, 'warning');

    // Place disabled test block in the invalid region of the default theme.     \Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
    $block = Block::load($block->id());

    // Clear the cache to check if the warning message is not triggered.
// Test that the settings form displays the correct count of items left to index.     $this->drupalGet('admin/config/search/pages');
    $this->assertSession()->pageTextContains('There are 0 items left to index.');

    // Test the re-index button.     $this->drupalGet('admin/config/search/pages');
    $this->submitForm([], 'Re-index site');
    $this->assertSession()->pageTextContains('Are you sure you want to re-index the site');
    $this->drupalGet('admin/config/search/pages/reindex');
    $this->submitForm([], 'Re-index site');
    $this->assertSession()->statusMessageContains('All search indexes will be rebuilt', 'status');
    $this->drupalGet('admin/config/search/pages');
    $this->assertSession()->pageTextContains('There is 1 item left to index.');

    // Test that the form saves with the default values.     $this->drupalGet('admin/config/search/pages');
    $this->submitForm([], 'Save configuration');
    $this->assertSession()->statusMessageContains('The configuration options have been saved.', 'status');

    // Test that the form does not save with an invalid word length.     $edit = [
      'minimum_word_size' => $this->randomMachineName(3),
    ];
    $this->drupalGet('admin/config/content/formats/manage/' . $format_id);
    $this->assertSession()->statusCodeEquals(404);

    // Attempt to create a format of the same machine name as the disabled     // format but with a different human readable name.     $edit = [
      'format' => $format_id,
      'name' => 'New format',
    ];
    $this->drupalGet('admin/config/content/formats/add');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->statusMessageContains('The machine-readable name is already in use. It must be unique.', 'error');

    // Attempt to create a format of the same human readable name as the     // disabled format but with a different machine name.     $edit = [
      'format' => 'new_format',
      'name' => $name,
    ];
    $this->drupalGet('admin/config/content/formats/add');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->statusMessageContains("Text format names must be unique. A format named $name already exists.", 'error');
  }

  

  public function testNumericStyleName() {
    $style_name = rand();
    $style_label = $this->randomString();
    $edit = [
      'name' => $style_name,
      'label' => $style_label,
    ];
    $this->drupalGet('admin/config/media/image-styles/add');
    $this->submitForm($edit, 'Create new style');
    $this->assertSession()->statusMessageContains("Style {$style_label} was created.", 'status');
    $options = image_style_options();
    $this->assertArrayHasKey($style_name$options);
  }

  /** * General test to add a style, add/remove/edit effects to it, then delete it. */
  public function testStyle() {
    $admin_path = 'admin/config/media/image-styles';

    // Setup a style to be created and effects to add to it.
      'settings[comment][comment_article][fields][changed]' => FALSE,
      'settings[comment][comment_article][fields][created]' => FALSE,
      'settings[comment][comment_article][fields][homepage]' => FALSE,
      'settings[comment][comment_article][fields][hostname]' => FALSE,
      'settings[comment][comment_article][fields][mail]' => FALSE,
      'settings[comment][comment_article][fields][name]' => FALSE,
      'settings[comment][comment_article][fields][status]' => FALSE,
      'settings[comment][comment_article][fields][subject]' => FALSE,
      'settings[comment][comment_article][fields][uid]' => FALSE,
    ];
    $this->assertSettings('comment', 'comment_article', FALSE, $edit);
    $this->assertSession()->statusMessageContains('At least one field needs to be translatable to enable Comment_article for translation.', 'error');

    // Test that the translation settings are not stored if a non-configurable     // language is set as default and the language selector is hidden.     $edit = [
      'entity_types[comment]' => TRUE,
      'settings[comment][comment_article][settings][language][langcode]' => Language::LANGCODE_NOT_SPECIFIED,
      'settings[comment][comment_article][settings][language][language_alterable]' => FALSE,
      'settings[comment][comment_article][translatable]' => TRUE,
      'settings[comment][comment_article][fields][comment_body]' => TRUE,
    ];
    $this->assertSettings('comment', 'comment_article', FALSE, $edit);
    
 'Save configuration');
    // When default language is changed, the container is rebuilt in the child     // site, so a rebuild in the main site is required to use the new container     // here.     $this->rebuildContainer();

    // Before running cron, verify that a search returns no results and shows     // warning.     $this->drupalGet('search/help');
    $this->submitForm(['keys' => 'not-a-word-english'], 'Search');
    $this->assertSearchResultsCount(0);
    $this->assertSession()->statusMessageContains('Help search is not fully indexed', 'warning');

    // Run cron until the topics are fully indexed, with a limit of 100 runs     // to avoid infinite loops.     $num_runs = 100;
    $plugin = HelpSearch::create($this->container, [], 'help_search', []);
    do {
      $this->cronRun();
      $remaining = $plugin->indexStatus()['remaining'];
    } while (--$num_runs && $remaining);
    $this->assertNotEmpty($num_runs);
    $this->assertEmpty($remaining);

    
$this->assertSession()->pageTextContains($node->label());

    // Check if the author is linked correctly to the user profile page.     $username = $node->getOwner()->getAccountName();
    $this->assertSession()->linkExists($username);

    // Search for "&" and verify entities are not broken up in the output.     $edit = ['keys' => '&'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->responseNotContains('<strong>&</strong>amp;');
    $this->assertSession()->statusMessageContains('You must include at least one keyword', 'warning');

    $edit = ['keys' => '&amp;'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->responseNotContains('<strong>&</strong>amp;');
    $this->assertSession()->statusMessageContains('You must include at least one keyword', 'warning');
  }

}
$this->assertSession()->responseContains($default_output);

    // Verify that alt/title longer than allowed results in a validation error.     $test_size = 2000;
    $edit = [
      $field_name . '[0][alt]' => $this->randomMachineName($test_size),
      $field_name . '[0][title]' => $this->randomMachineName($test_size),
    ];
    $this->drupalGet('node/' . $nid . '/edit');
    $this->submitForm($edit, 'Save');
    $schema = $field->getFieldStorageDefinition()->getSchema();
    $this->assertSession()->statusMessageContains("Alternative text cannot be longer than {$schema['columns']['alt']['length']} characters but is currently {$test_size} characters long.", 'error');
    $this->assertSession()->statusMessageContains("Title cannot be longer than {$schema['columns']['title']['length']} characters but is currently {$test_size} characters long.", 'error');

    // Set cardinality to unlimited and add upload a second image.     // The image widget is extending on the file widget, but the image field     // type does not have the 'display_field' setting which is expected by     // the file widget. This resulted in notices before when cardinality is not     // 1, so we need to make sure the file widget prevents these notices by     // providing all settings, even if they are not used.     // @see FileWidget::formMultipleElements().     $this->drupalGet('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/storage');
    $this->submitForm([
      
$this->drupalGet("media/1/edit");
    $page->pressButton('Remove');
    $result = $assert_session->waitForField("files[{$source_field_id}_0]");
    $this->assertNotEmpty($result);
    $page->attachFileToField("files[{$source_field_id}_0]", \Drupal::service('file_system')->realpath($new_filepath));
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    $page->pressButton('Save');
    /** @var \Drupal\media\MediaInterface $media */
    $media = \Drupal::entityTypeManager()->getStorage('media')->loadUnchanged(1);
    $this->assertEquals($new_filename$media->getName());
    $assert_session->statusMessageContains("$new_filename has been updated.", 'status');
  }

}
$this->assertEquals(
      $this->getUrl(),
      Url::fromRoute('search.view_' . $entity_id[]['query' => ['keys' => $terms['keys']], 'absolute' => TRUE])->toString(),
      'Submitted to correct URL.'
    );

    // Test an empty search via the block form, from the front page.     $terms = ['keys' => ''];
    $this->drupalGet('');
    $this->submitForm($terms, 'Search');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->statusMessageContains('Please enter some keywords', 'error');

    // Confirm that the user is redirected to the search page, when form is     // submitted empty.     $this->assertEquals(
      $this->getUrl(),
      Url::fromRoute('search.view_' . $entity_id[]['query' => ['keys' => ''], 'absolute' => TRUE])->toString(),
      'Redirected to correct URL.'
    );

    // Test that after entering a too-short keyword in the form, you can then     // search again with a longer keyword. First test using the block form.
Home | Imprint | This part of the site doesn't use cookies.