optionExists example

// Expect that there's no 'auto_create_bundle' selected.     $this->assertSession()->fieldNotExists('settings[handler_settings][auto_create_bundle]');

    $edit = [
      'settings[handler_settings][target_bundles][' . $vocabularies[1]->id() . ']' => TRUE,
    ];
    // Enable the second vocabulary as a target bundle.     $this->drupalGet($path);
    $this->submitForm($edit, 'Save settings');
    $this->drupalGet($path);
    // Expect a select element with the two vocabularies as options.     $this->assertSession()->optionExists('settings[handler_settings][auto_create_bundle]', $vocabularies[0]->id());
    $this->assertSession()->optionExists('settings[handler_settings][auto_create_bundle]', $vocabularies[1]->id());

    $edit = [
      'settings[handler_settings][auto_create]' => TRUE,
      'settings[handler_settings][auto_create_bundle]' => $vocabularies[1]->id(),
    ];
    $this->submitForm($edit, 'Save settings');

    /** @var \Drupal\field\Entity\FieldConfig $field_config */
    $field_config = FieldConfig::load($field_id);
    // Expect that the target bundle has been saved in the backend.

  public function testFieldAdminHandler() {
    $bundle_path = 'admin/structure/types/manage/' . $this->type;

    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // First step: 'Add new field' on the 'Manage fields' page.     $this->drupalGet($bundle_path . '/fields/add-field');

    // Check if the commonly referenced entity types appear in the list.     $this->assertSession()->optionExists('edit-new-storage-type', 'field_ui:entity_reference:node');
    $this->assertSession()->optionExists('edit-new-storage-type', 'field_ui:entity_reference:user');

    $page->findField('new_storage_type')->setValue('entity_reference');
    $assert_session->waitForField('label')->setValue('Test');
    $machine_name = $assert_session->waitForElement('xpath', '//*[@id="edit-label-machine-name-suffix"]/span[contains(text(), "field_test")]');
    $this->assertNotEmpty($machine_name);
    $page->pressButton('Save and continue');

    // Node should be selected by default.     $this->assertSession()->fieldValueEquals('settings[target_type]', 'node');

    
$this->submitForm($edit, 'Save');

    // Assert that the unpublished node can be selected as a parent menu link     // for users with access to the node.     $node = $this->drupalGetNodeByTitle($node_title);
    $this->assertTrue($node->access('view', $editor_with_unpublished_content_access));
    $this->assertEquals($edit['title[0][value]']$node->getTitle());
    $this->drupalGet('node/add/page');
    $link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];
    /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $link */
    $link = MenuLinkContent::load($link_id);
    $this->assertSession()->optionExists('edit-menu-menu-parent', 'main:' . $link->getPluginId());

    // Assert that the unpublished node cannot be selected as a parent menu link     // for users without access to the node.     $editor_without_unpublished_content_access = $this->drupalCreateUser([
      'administer nodes',
      'administer menu',
      'create page content',
      'use editorial transition create_new_draft',
    ]);
    $this->drupalLogin($editor_without_unpublished_content_access);
    $this->assertFalse($node->access('view', $editor_without_unpublished_content_access));
    
// Create the vocabulary.     $vid = mb_strtolower($this->randomMachineName());
    $edit['name'] = $this->randomMachineName();
    $edit['description'] = $this->randomMachineName();
    $edit['langcode'] = 'aa';
    $edit['vid'] = $vid;
    $this->submitForm($edit, 'Save');

    // Check the language on the edit page.     $this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
    $this->assertTrue($this->assertSession()->optionExists('edit-langcode', $edit['langcode'])->isSelected());

    // Change the language and save again.     $edit['langcode'] = 'bb';
    unset($edit['vid']);
    $this->submitForm($edit, 'Save');

    // Check again the language on the edit page.     $this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
    $this->assertTrue($this->assertSession()->optionExists('edit-langcode', $edit['langcode'])->isSelected());
  }

  
$created_links[] = 'tools:' . $last_link->getPluginId();
    }

    // The last link cannot be a parent in the new menu link form.     $this->drupalGet('admin/structure/menu/manage/admin/add');
    $value = 'tools:' . $last_link->getPluginId();
    $this->assertSession()->optionNotExists('edit-menu-parent', $value);

    // All but the last link can be parents in the new menu link form.     array_pop($created_links);
    foreach ($created_links as $key => $link) {
      $this->assertSession()->optionExists('edit-menu-parent', $link);
    }
  }

  /** * Verifies a menu link using the UI. * * @param \Drupal\menu_link_content\Entity\MenuLinkContent $item * Menu link. * @param object $item_node * Menu link content node. * @param \Drupal\menu_link_content\Entity\MenuLinkContent $parent * Parent menu link. * @param object $parent_node * Parent menu link content node. */
// Click on the widget settings button to open the widget settings form.     $this->submitForm([]$field_name . "_settings_edit");
    $this->assertSession()->elementExists('xpath', $xpathIncr);

    // Display creation form.     $this->drupalGet('entity_test/add');

    foreach (['value', 'end-value'] as $column) {
      foreach (['year', 'month', 'day', 'hour', 'minute', 'ampm'] as $element) {
        $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-$column-$element\"]");
        $this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-$column-$element", '')->isSelected());
      }
    }

    // Submit a valid date and ensure it is accepted.     $start_date_value = ['year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15];
    $end_date_value = ['year' => 2013, 'month' => 1, 'day' => 15, 'hour' => 3, 'minute' => 30];

    $edit = [];
    // Add the ampm indicator since we are testing 12 hour time.     $start_date_value['ampm'] = 'am';
    $end_date_value['ampm'] = 'pm';
    
$this->submitForm($edit, 'Save');

    // Run cron to update the search index totals.     $this->cronRun();

    // Test that the settings form displays the content ranking section.     $this->drupalGet('admin/config/search/pages/manage/node_search');
    $this->assertSession()->pageTextContains('Content ranking');

    // Check that all rankings are visible and set to 0.     foreach ($node_ranks as $node_rank) {
      $this->assertSession()->optionExists('edit-rankings-' . $node_rank . '-value', '0');
    }

    // Test each of the possible rankings.     $edit = [];
    foreach ($node_ranks as $node_rank) {
      // Enable the ranking we are testing.       $edit['rankings[' . $node_rank . '][value]'] = 10;
      $this->drupalGet('admin/config/search/pages/manage/node_search');
      $this->submitForm($edit, 'Save search page');
      $this->drupalGet('admin/config/search/pages/manage/node_search');
      $this->assertSession()->optionExists('edit-rankings-' . $node_rank . '-value', '10');

      
->loadByProperties(['title' => 'Test']);
    if (empty($nodes)) {
      $this->fail('Could not load node with title Test');
      return;
    }
    $node = reset($nodes);
    $this->drupalGet('node/' . $node->id());
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkByHrefExists('node/' . $node->id() . '/edit');
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->optionExists('moderation_state[0][state]', 'draft');
    $this->assertSession()->optionNotExists('moderation_state[0][state]', 'published');

    $this->drupalLogin($editor_with_publish);
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->optionExists('moderation_state[0][state]', 'draft');
    $this->assertSession()->optionExists('moderation_state[0][state]', 'published');
  }

  /** * @covers \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsBundleFormAlter */


  /** * Verifies plugin-supplied settings form. */
  public function testSearchModuleSettingsPage() {
    $this->drupalGet('admin/config/search/pages');
    $this->clickLink('Edit', 1);

    // Ensure that the default setting was picked up from the default config     $this->assertTrue($this->assertSession()->optionExists('edit-extra-type-settings-boost', 'bi')->isSelected());

    // Change extra type setting and also modify a common search setting.     $edit = [
      'extra_type_settings[boost]' => 'ii',
    ];
    $this->submitForm($edit, 'Save search page');

    // Ensure that the modifications took effect.     $this->assertSession()->statusMessageContains("The Dummy search type search page has been updated.", 'status');
    $this->drupalGet('admin/config/search/pages/manage/dummy_search_type');
    $this->assertTrue($this->assertSession()->optionExists('edit-extra-type-settings-boost', 'ii')->isSelected());
  }

  public function testModerationForm() {
    // Test the states that appear by default when creating a new item of     // content.     $this->drupalGet('node/add/moderated_content');
    $this->assertSession()->optionExists('moderation_state[0][state]', 'draft');
    $this->assertSession()->optionExists('moderation_state[0][state]', 'published');
    $this->assertSession()->optionNotExists('moderation_state[0][state]', 'archived');
    // Previewing a new item of content should not change the available states.     $this->submitForm([
      'moderation_state[0][state]' => 'published',
      'title[0][value]' => 'Some moderated content',
      'body[0][value]' => 'First version of the content.',
    ], 'Preview');
    $this->clickLink('Back to content editing');
    $this->assertSession()->optionExists('moderation_state[0][state]', 'draft');
    $this->assertSession()->optionExists('moderation_state[0][state]', 'published');
    
/** * Installer step: Select language. */
  protected function setUpLanguage() {
    // Place a custom local translation in the translations directory.     mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
    touch($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.xoxo.po');

    // Check that all predefined languages show up with their native names.     $this->visitInstaller();
    foreach (LanguageManager::getStandardLanguageList() as $langcode => $names) {
      $this->assertSession()->optionExists('edit-langcode', $langcode);
      $this->assertSession()->responseContains('>' . $names[1] . '<');
    }

    // Check that our custom one shows up with the file name indicated language.     $this->assertSession()->optionExists('edit-langcode', 'xoxo');
    $this->assertSession()->responseContains('>xoxo<');

    parent::setUpLanguage();
  }

  /** * Confirms that the installation succeeded. */
$this->drupalGet('admin/structure/block/add/system_powered_by_block');
    $assert_session = $this->assertSession();
    // Pick a theme with a region that does not exist in another theme.     $assert_session->selectExists('Theme')->selectOption('claro');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->selectExists('Region')->selectOption('pre_content');
    $assert_session->assertWaitOnAjaxRequest();
    // Switch to a theme that doesn't contain the region selected above.     $assert_session->selectExists('Theme')->selectOption('stark');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextNotContains('The submitted value Pre-content in the Region element is not allowed.');
    $assert_session->optionExists('Region', '- Select -');
  }

}
$this->submitForm([], 'Update preview');
    $this->assertSession()->pageTextNotContains('The submitted value "page" in the Type element is not allowed.');
  }

  /** * Tests the limit of the expose operator functionality. */
  public function testLimitExposedOperators() {

    $this->drupalGet('test_filter_in_operator_ui');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->optionExists('edit-nid-op', '<');
    $this->assertSession()->optionExists('edit-nid-op', '<=');
    $this->assertSession()->optionExists('edit-nid-op', '=');
    $this->assertSession()->optionNotExists('edit-nid-op', '>');
    $this->assertSession()->optionNotExists('edit-nid-op', '>=');

    // Because there are not operators that use the min and max fields, those     // fields should not be in the exposed form.     $this->assertSession()->fieldExists('edit-nid-value');
    $this->assertSession()->fieldNotExists('edit-nid-min');
    $this->assertSession()->fieldNotExists('edit-nid-max');

    
/** * Tests an entity type that has fields shown by default. */
  public function testNodeView() {
    // By default, the one-column layout is used.     $this->drupalGet('node/1');
    $this->assertSession()->elementExists('css', '.layout--onecol');
    $this->assertSession()->elementTextContains('css', '.layout__region--content', 'The node body');

    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertEquals(['Content', 'Disabled']$this->getRegionTitles());
    $this->assertSession()->optionExists('fields[body][region]', 'content');
  }

  /** * Tests that changes to the regions still leave the fields visible. */
  public function testRegionChanges() {
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertEquals(['Content', 'Disabled']$this->getRegionTitles());
    $this->assertSession()->optionExists('fields[body][region]', 'content');

    \Drupal::state()->set('field_layout_test.alter_regions', TRUE);
    
$this->drupalGet($handler_options_path);
    $this->assertSession()->fieldNotExists($relationship_name);

    // Create a view of comments with node relationship.     View::create(['base_table' => 'comment_field_data', 'id' => 'test_get_entity_type'])->save();
    $this->drupalGet('admin/structure/views/nojs/add-handler/test_get_entity_type/default/relationship');
    $this->submitForm(['name[comment_field_data.node]' => 'comment_field_data.node'], 'Add and configure relationships');
    $this->submitForm([], 'Apply');
    // Add a content type filter.     $this->drupalGet('admin/structure/views/nojs/add-handler/test_get_entity_type/default/filter');
    $this->submitForm(['name[node_field_data.type]' => 'node_field_data.type'], 'Add and configure filter criteria');
    $this->assertTrue($this->assertSession()->optionExists('edit-options-relationship', 'node')->isSelected());
    $this->submitForm(['options[value][page]' => 'page'], 'Apply');
    // Check content type filter options.     $this->drupalGet('admin/structure/views/nojs/handler/test_get_entity_type/default/filter/type');
    $this->assertTrue($this->assertSession()->optionExists('edit-options-relationship', 'node')->isSelected());
    $this->assertSession()->checkboxChecked('edit-options-value-page');
  }

  /** * Tests the relationship method on the base class. */
  public function testSetRelationship() {
    
Home | Imprint | This part of the site doesn't use cookies.