optionNotExists example


      $this->drupalGet("admin/structure/menu/manage/{$this->menu->id()}/add");
      $this->submitForm($edit, 'Save');
      $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => $title]);
      $last_link = reset($menu_links);
      $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. */
/** * 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');

    $edit = [];
    $edit['options[operator]'] = '>';
    $edit['options[expose][operator_list][]'] = ['>', '>=', 'between'];
    

  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');
    $this->assertSession()->optionNotExists('moderation_state[0][state]', 'archived');

    
$rendered_entity = \Drupal::service('renderer')->renderRoot($content);
    $this->assertStringContainsString('<div><strong><span>', (string) $rendered_entity);

    // Test when 2 of 3 formats are selected.     $field->setSetting('allowed_formats', [$format1->id()$format2->id()]);
    $field->save();
    $this->drupalGet('entity_test/add');
    // We should see the 'format' selector again.     $this->assertSession()->fieldExists("{$field_name}[0][value]", NULL);
    $this->assertSession()->optionExists("{$field_name}[0][format]", $format1->id());
    $this->assertSession()->optionExists("{$field_name}[0][format]", $format2->id());
    $this->assertSession()->optionNotExists("{$field_name}[0][format]", $format3->id());

    // Change field to allow all formats by configuring none as allowed.     $field->setSetting('allowed_formats', []);
    $field->save();
    $this->drupalGet('entity_test/add');
    // We should see the 'format' selector again.     $this->assertSession()->fieldExists("{$field_name}[0][value]", NULL);
    $this->assertSession()->optionExists("{$field_name}[0][format]", $format1->id());
    $this->assertSession()->optionExists("{$field_name}[0][format]", $format2->id());
    $this->assertSession()->optionExists("{$field_name}[0][format]", $format3->id());
  }

  
'administer users',
    ]));
    $action_id = 'user_add_role_action.' . $role;
    $edit = [
      'options[include_exclude]' => 'exclude',
      "options[selected_actions][$action_id]" => $action_id,
    ];
    $this->drupalGet('admin/structure/views/nojs/handler/test_user_bulk_form/default/field/user_bulk_form');
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');
    $this->drupalGet('test-user-bulk-form');
    $this->assertSession()->optionNotExists('edit-action', $action_id);
    $edit['options[include_exclude]'] = 'include';
    $this->drupalGet('admin/structure/views/nojs/handler/test_user_bulk_form/default/field/user_bulk_form');
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');
    $this->drupalGet('test-user-bulk-form');
    $this->assertSession()->optionExists('edit-action', $action_id);
  }

  /** * Tests the user bulk form with a combined field filter on the bulk column. */
  
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
  }

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

    $this->drupalGet('test_exposed_filter_datetime');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->optionExists('edit-field-date-value-op', '=');
    $this->assertSession()->optionNotExists('edit-field-date-value-op', '>');
    $this->assertSession()->optionNotExists('edit-field-date-value-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-field-date-value-value');
    $this->assertSession()->fieldNotExists('edit-field-date-value-min');
    $this->assertSession()->fieldNotExists('edit-field-date-value-max');

    $edit = [];
    $edit['options[operator]'] = '>';
    $edit['options[expose][operator_list][]'] = ['>', '>=', 'between'];
    
$this->assertSame('Locked', $locked[0]->getHtml(), 'Field is marked as Locked in the UI');
    $this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_name . '/delete');
    $this->assertSession()->statusCodeEquals(403);
  }

  /** * Tests that Field UI respects the 'no_ui' flag in the field type definition. */
  public function testHiddenFields() {
    // Check that the field type is not available in the 'add new field' row.     $this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/add-field');
    $this->assertSession()->optionNotExists('edit-new-storage-type', 'hidden_test_field');
    $this->assertSession()->optionExists('edit-new-storage-type', 'shape');

    // Create a field storage and a field programmatically.     $field_name = 'hidden_test_field';
    FieldStorageConfig::create([
      'field_name' => $field_name,
      'entity_type' => 'node',
      'type' => $field_name,
    ])->save();
    $field = [
      'field_name' => $field_name,
      
public function testsNonIntegerIdEntities() {
    // Create a bundle for entity_test_string_id.     entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test_string_id');
    $limited_user = $this->drupalCreateUser([
      'administer entity_test_string_id fields',
      'administer comment types',
    ]);
    $this->drupalLogin($limited_user);
    // Visit the Field UI field add page.     $this->drupalGet('entity_test_string_id/structure/entity_test/fields/add-field');
    // Ensure field isn't shown for string IDs.     $this->assertSession()->optionNotExists('edit-new-storage-type', 'comment');
    // Ensure a core field type shown.     $this->assertSession()->optionExists('edit-new-storage-type', 'boolean');

    // Attempt to add a comment-type referencing this entity-type.     $this->drupalGet('admin/structure/comment/types/add');
    $this->assertSession()->optionNotExists('edit-target-entity-type-id', 'entity_test_string_id');
    $this->assertSession()->responseNotContains('Test entity with string_id');

    // Create a bundle for entity_test_no_id.     entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test_no_id');
    $this->drupalLogin($this->drupalCreateUser([
      
// Assign a menu link to the second node, being a child of the first one.     $child_item = MenuLinkContent::create([
      'link' => [['uri' => 'entity:node/' . $child_node->id()]],
      'title' => $this->randomMachineName(16),
      'parent' => $item->getPluginId(),
      'menu_name' => $item->getMenuName(),
    ]);
    $child_item->save();
    // Edit the first node.     $this->drupalGet('node/' . $node->id() . '/edit');
    // Assert that it is not possible to set the parent of the first node to itself or the second node.     $this->assertSession()->optionNotExists('edit-menu-menu-parent', 'tools:' . $item->getPluginId());
    $this->assertSession()->optionNotExists('edit-menu-menu-parent', 'tools:' . $child_item->getPluginId());
    // Assert that unallowed Administration menu is not available in options.     $this->assertSession()->optionNotExists('edit-menu-menu-parent', 'admin:');
  }

  /** * Testing correct loading and saving of menu links via node form widget in a multilingual environment. */
  public function testMultilingualMenuNodeFormWidget() {
    // Setup languages.     $langcodes = ['de'];
    
// Make sure that a regular user only has permission to use the format     // they were granted access to.     $this->assertTrue($this->webUser->hasPermission($this->allowedFormat->getPermissionName()), 'A regular user has permission to use the allowed text format.');
    $this->assertFalse($this->webUser->hasPermission($this->disallowedFormat->getPermissionName()), 'A regular user does not have permission to use the disallowed text format.');

    // Make sure that the allowed format appears on the node form and that     // the disallowed format and fallback format do not.     $this->drupalLogin($this->webUser);
    $this->drupalGet('node/add/page');
    $this->assertSession()->optionExists('body[0][format]', $this->allowedFormat->id());
    $this->assertSession()->optionNotExists('body[0][format]', $this->disallowedFormat->id());
    $this->assertSession()->optionNotExists('body[0][format]', filter_fallback_format());

    // Check regular user access to the filter tips pages.     $this->drupalGet('filter/tips/' . $this->allowedFormat->id());
    $this->assertSession()->statusCodeEquals(200);
    $this->drupalGet('filter/tips/' . $this->disallowedFormat->id());
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet('filter/tips/' . filter_fallback_format());
    $this->assertSession()->statusCodeEquals(200);
    $this->drupalGet('filter/tips/invalid-format');
    $this->assertSession()->statusCodeEquals(404);

    
$this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains("{$field->getName()} field is required.");

    // Submit form: select first option.     $edit = ['card_1' => 0];
    $this->submitForm($edit, 'Save');
    $this->assertFieldValues($entity_init, 'card_1', [0]);

    // Display form: check that the right options are selected.     $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
    // A required field with a value has no 'none' option.     $this->assertSession()->optionNotExists('edit-card-1', '_none');
    $this->assertTrue($this->assertSession()->optionExists('card_1', 0)->isSelected());
    $this->assertFalse($this->assertSession()->optionExists('card_1', 1)->isSelected());
    $this->assertFalse($this->assertSession()->optionExists('card_1', 2)->isSelected());

    // Make the field non required.     $field->setRequired(FALSE);
    $field->save();

    // Display form.     $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
    // A non-required field has a 'none' option.

    foreach ([5 => 2, 6 => 3, 7 => 6, 8 => 7, 9 => 8, 10 => 9, 11 => 10] as $child => $parent) {
      $nodes[$child] = $this->createBookNode($book->id()$nodes[$parent]->id());
    }
    $this->drupalGet($nodes[0]->toUrl('edit-form'));
    // Since Node 0 has children 2 levels deep, nodes 10 and 11 should not     // appear in the selector.     $this->assertSession()->optionNotExists('edit-book-pid', $nodes[10]->id());
    $this->assertSession()->optionNotExists('edit-book-pid', $nodes[11]->id());
    // Node 9 should be available as an option.     $this->assertSession()->optionExists('edit-book-pid', $nodes[9]->id());

    // Get a shallow set of options.     /** @var \Drupal\book\BookManagerInterface $manager */
    $manager = $this->container->get('book.manager');
    $options = $manager->getTableOfContents($book->id(), 3);
    // Verify that all expected option keys are present.     $expected_nids = [$book->id()$nodes[0]->id()$nodes[1]->id()$nodes[2]->id()$nodes[3]->id()$nodes[6]->id()$nodes[4]->id()];
    $this->assertEquals($expected_nidsarray_keys($options));
    
// 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));
    $this->drupalGet('node/add/page');
    $this->assertSession()->optionNotExists('edit-menu-menu-parent', 'main:' . $link->getPluginId());
  }

}
'langcode' => $langcode,
      'translation' => 'untranslated',
    ];
    // Check that search finds the string as untranslated.     $this->drupalGet('admin/config/regional/translate');
    $this->submitForm($search, 'Filter');
    $this->assertSession()->pageTextContains($name);

    // No t() here, it's surely not translated yet.     $this->assertSession()->pageTextContains($name);
    // Verify that there is no way to translate the string to English.     $this->assertSession()->optionNotExists('edit-langcode', 'en');
    $this->drupalLogout();
    $this->drupalLogin($admin_user);
    $this->drupalGet('admin/config/regional/language/edit/en');
    $this->submitForm(['locale_translate_english' => TRUE], 'Save language');
    $this->drupalLogout();
    $this->drupalLogin($translate_user);
    // Check that search finds the string as untranslated.     $this->drupalGet('admin/config/regional/translate');
    $this->submitForm($search, 'Filter');
    $this->assertSession()->pageTextContains($name);

    
$node_type = $this->drupalCreateContentType()->id();

    // Entity types without an ID key should not be presented as options when     // creating an entity reference field in the UI.     $this->drupalGet("/admin/structure/types/manage/$node_type/fields/add-field");
    $edit = [
      'new_storage_type' => 'entity_reference',
      'label' => 'Test Field',
      'field_name' => 'test_reference_field',
    ];
    $this->submitForm($edit, 'Save and continue');
    $this->assertSession()->optionNotExists('settings[target_type]', 'entity_test_no_id');

    // Trying to do it programmatically should raise an exception.     $this->expectException('\Drupal\Core\Field\FieldException');
    $this->expectExceptionMessage('Entity type "entity_test_no_id" has no ID key and cannot be targeted by entity reference field "test_reference_field"');
    $this->createEntityReferenceField('node', $node_type, 'test_reference_field', 'Test Field', 'entity_test_no_id');
  }

}
Home | Imprint | This part of the site doesn't use cookies.