fieldExists example

->setComponent($field_name[
        'type' => 'text_textfield',
      ])
      ->save();
    $entity_display_repository->getViewDisplay('entity_test', 'entity_test', 'full')
      ->setComponent($field_name)
      ->save();

    // Display the creation form.     $this->drupalLogin($this->webUser);
    $this->drupalGet('entity_test/add');
    $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());

    $filtered_markup = FilteredMarkup::create('<div><strong><span>Hello World</span></strong></div>');
    $edit = [
      "{$field_name}[0][value]" => $filtered_markup,
    ];
    $this->submitForm($edit, 'Save');
    preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
    $id = $match[1];
    
$this->connection->query('DROP TABLE {' . $table . '}');
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function addField($table$field$specification$keys_new = []) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot add field '$table.$field': table doesn't exist.");
    }
    if ($this->fieldExists($table$field)) {
      throw new SchemaObjectExistsException("Cannot add field '$table.$field': field already exists.");
    }
    if (isset($keys_new['primary key']) && in_array($field$keys_new['primary key'], TRUE)) {
      $this->ensureNotNullPrimaryKey($keys_new['primary key'][$field => $specification]);
    }

    // SQLite doesn't have a full-featured ALTER TABLE statement. It only     // supports adding new fields to a table, in some simple cases. In most     // cases, we have to create a new table and copy the data over.     if (empty($keys_new) && (empty($specification['not null']) || isset($specification['default']))) {
      // When we don't have to create new keys and we are not creating a

  public function testPageAccess() {
    // Initially disable access grant records in     // node_access_test_node_access_records().     \Drupal::state()->set('node_access_test.private', TRUE);

    $this->drupalLogin($this->adminUser);

    // Access the node form before moderation is enabled, the publication state     // should now be visible.     $this->drupalGet('node/add/moderated_content');
    $this->assertSession()->fieldExists('Published');

    // Now enable the workflow.     $this->enableModerationThroughUi('moderated_content', 'editorial');

    // Access that the status field is no longer visible.     $this->drupalGet('node/add/moderated_content');
    $this->assertSession()->fieldNotExists('Published');

    // Create a node to test with.     $this->submitForm([
      'title[0][value]' => 'moderated content',
      
$this->connection->query('DROP TABLE {' . $table . '}');
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function addField($table$field$spec$keys_new = []) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot add field '$table.$field': table doesn't exist.");
    }
    if ($this->fieldExists($table$field)) {
      throw new SchemaObjectExistsException("Cannot add field '$table.$field': field already exists.");
    }

    // Fields that are part of a PRIMARY KEY must be added as NOT NULL.     $is_primary_key = isset($keys_new['primary key']) && in_array($field$keys_new['primary key'], TRUE);
    if ($is_primary_key) {
      $this->ensureNotNullPrimaryKey($keys_new['primary key'][$field => $spec]);
    }

    $fixnull = FALSE;
    if (!empty($spec['not null']) && !isset($spec['default']) && !$is_primary_key) {
      


  /** * Tests the visibility settings for the blocks based on language. */
  public function testLanguageBlockVisibility() {
    // Check if the visibility setting is available.     $default_theme = $this->config('system.theme')->get('default');
    $this->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);
    // Ensure that the language visibility field is visible without a type     // setting.     $this->assertSession()->fieldExists('visibility[language][langcodes][en]');
    $this->assertSession()->fieldNotExists('visibility[language][context_mapping][language]');

    // Enable a standard block and set the visibility setting for one language.     $edit = [
      'visibility[language][langcodes][en]' => TRUE,
      'id' => strtolower($this->randomMachineName(8)),
      'region' => 'sidebar_first',
    ];
    $this->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);
    $this->submitForm($edit, 'Save block');

    
// Add another section.     $assert_session->linkExists('Add section');
    $this->clickLink('Add section');

    $this->waitForOffCanvasArea();
    $assert_session->waitForElementVisible('named', ['link', 'Layout plugin (with settings)']);

    $assert_session->linkExists('Layout plugin (with settings)');
    $this->clickLink('Layout plugin (with settings)');
    $this->assertOffCanvasFormAfterWait('layout_builder_configure_section');
    $assert_session->fieldExists('layout_settings[setting_1]');
    $page->pressButton('Add section');

    $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
    $assert_session->pageTextContains('Default');
    $assert_session->linkExists('Add block');

    // Ensure validation error is displayed for ConfigureSectionForm.     $assert_session->linkExists('Add section');
    $this->clickLink('Add section');
    $this->waitForOffCanvasArea();

    
// Make sure the link to the field options exists.     $handler_options_path = 'admin/structure/views/nojs/handler/test_handler_relationships/default/field/title';
    $view_edit_path = 'admin/structure/views/view/test_handler_relationships/edit';
    $this->drupalGet($view_edit_path);
    $this->assertSession()->linkByHrefExists($handler_options_path);

    // The test view has a relationship to node_revision so the field should     // show a relationship selection.
    $this->drupalGet($handler_options_path);
    $relationship_name = 'options[relationship]';
    $this->assertSession()->fieldExists($relationship_name);

    // Check for available options.     $fields = $this->getSession()->getPage()->findAll('named_exact', ['field', $relationship_name]);
    $options = [];
    foreach ($fields as $field) {
      $items = $field->findAll('css', 'option');
      foreach ($items as $item) {
        $options[] = $item->getAttribute('value');
      }
    }
    $expected_options = ['none', 'nid'];
    
/** * Tests that the "tagged with" form element only shows for node types that support it. */
  public function testTaggedWithByNodeType() {
    // The tagging field is associated with one of our node types only. So the     // "tagged with" form element on the view wizard should appear on the form     // by default (when the wizard is configured to display all content) and     // also when the node type that has the tagging field is selected, but not     // when the node type that doesn't have the tagging field is selected.     $this->drupalGet('admin/structure/views/add');
    $this->assertSession()->fieldExists("show[tagged_with]");
    $view['show[type]'] = $this->nodeTypeWithTags->id();
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Update "of type" choice');
    $this->assertSession()->fieldExists("show[tagged_with]");
    $view['show[type]'] = $this->nodeTypeWithoutTags->id();
    $this->submitForm($view, 'Update "of type" choice (2)');
    $this->assertSession()->fieldNotExists("show[tagged_with]");

    // If we add an instance of the tagging field to the second node type, the     // "tagged with" form element should not appear for it too.     FieldConfig::create([
      
    // edit content that does not have an assigned format.     $this->drupalLogin($this->webUser);
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->fieldDisabled($body_value_key);
    $this->assertSession()->fieldValueEquals($body_value_key, 'This field has been disabled because you do not have sufficient permissions to edit it.');

    // Log back in as the filter administrator and verify that the body field     // can be edited.     $this->drupalLogin($this->filterAdminUser);
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->fieldEnabled($body_value_key);
    $this->assertSession()->fieldExists($body_format_key);

    // Verify that trying to save the node without selecting a new text format     // produces an error message, and does not result in the node being saved.     $old_title = $new_edit['title[0][value]'];
    $new_title = $this->randomMachineName(8);
    $edit = [];
    $edit['title[0][value]'] = $new_title;
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->statusMessageContains('Text format field is required.', 'error');
    $this->drupalGet('node/' . $node->id());
    
'access comments',
      'post comments',
    ]);
    $this->drupalLogin($commenting_user);

    $this->drupalGet('node/' . $book_node->id());

    $this->assertSession()->pageTextContains($comment_subject);
    $this->assertSession()->pageTextContains($comment_body);
    $this->assertSession()->pageTextContains('Add new comment');
    // Ensure that the comment form subject field exists.     $this->assertSession()->fieldExists('subject[0][value]');

    $this->drupalGet('book/export/html/' . $book_node->id());

    $this->assertSession()->pageTextContains('Comments');
    $this->assertSession()->pageTextContains($comment_subject);
    $this->assertSession()->pageTextContains($comment_body);

    $this->assertSession()->pageTextNotContains('Add new comment');
    // Verify that the comment form subject field is not found.     $this->assertSession()->fieldNotExists('subject[0][value]');
  }

}
// Import.     $this->configImporter->reset()->import();

    // Verify the values appeared.     $config = $this->config($config_name);
    $this->assertSame($config_id$config->get('id'));

    // Verify that updates were performed.     $entity_type = $this->container->get('entity_type.manager')->getDefinition($entity_type_id);
    $table = $entity_type->getDataTable();
    $db_schema = $this->container->get('database')->schema();
    $result = $db_schema->fieldExists($table, 'content_translation_source') && $db_schema->fieldExists($table, 'content_translation_outdated');
    $this->assertTrue($result, 'Content translation updates were successfully performed during config import.');
  }

}
public function testMediaOverviewPage() {
    $assert_session = $this->assertSession();

    // Check the view exists, is access-restricted, and some defaults are there.     $this->drupalGet('/admin/content/media');
    $assert_session->statusCodeEquals(403);
    $role = Role::load(RoleInterface::AUTHENTICATED_ID);
    $this->grantPermissions($role['access media overview']);
    $this->getSession()->reload();
    $assert_session->statusCodeEquals(200);
    $assert_session->titleEquals('Media | Drupal');
    $assert_session->fieldExists('Media name');
    $assert_session->selectExists('type');
    $assert_session->selectExists('status');
    $assert_session->selectExists('langcode');
    $assert_session->buttonExists('Filter');
    $header = $assert_session->elementExists('css', 'th#view-thumbnail-target-id-table-column');
    $this->assertSame('Thumbnail', $header->getText());
    $header = $assert_session->elementExists('css', 'th#view-name-table-column');
    $this->assertSame('Media name', $header->getText());
    $header = $assert_session->elementExists('css', 'th#view-bundle-table-column');
    $this->assertSame('Type', $header->getText());
    $header = $assert_session->elementExists('css', 'th#view-uid-table-column');
    
    // trigger an AJAX rebuild.     $page->pressButton('Save configuration');
    $assert_session->pageTextContains('Added text format');

    // Verify that the configuration was saved.     $this->drupalGet('admin/config/content/formats/manage/ckeditor5');
    $page->clickLink('Style');
    $this->assertNotNull($styles_textarea = $assert_session->waitForElementVisible('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-style-styles"]'));

    $this->assertSame("p.foo.bar|Foobar paragraph\n", $styles_textarea->getValue());
    $assert_session->pageTextContains('One style configured');
    $allowed_html_field = $assert_session->fieldExists('filters[filter_html][settings][allowed_html]');
    $this->assertStringContainsString('<p class="foo bar">', $allowed_html_field->getValue());

    // Attempt to use an unsupported HTML5 tag.     $javascript = <<<JS const allowedTags = document.querySelector('[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-style-styles"]'); allowedTags.value = 's.redacted|Redacted'; allowedTags.dispatchEvent(new Event('change')); JS;
    $this->getSession()->executeScript($javascript);

    // The CKEditor 5 module should refuse to specify styles on tags that cannot
$this->drupalLogin($this->drupalCreateUser(['administer views']));
  }

  /** * Tests that 'api_json' is not a RestExport format option. */
  public function testFormatOptions() {
    $this->assertSame(['json' => 'serialization', 'xml' => 'serialization']$this->container->getParameter('serializer.format_providers'));

    $this->drupalGet('admin/structure/views/nojs/display/test_serializer_display_entity/rest_export_1/style_options');
    $this->assertSession()->fieldExists('style_options[formats][json]');
    $this->assertSession()->fieldExists('style_options[formats][xml]');
    $this->assertSession()->fieldNotExists('style_options[formats][api_json]');
  }

}
\Drupal::entityTypeManager()->getStorage('workspace')->delete($workspaces);
      }

      $now_installed_list = \Drupal::moduleHandler()->getModuleList();
      $added_modules = array_diff(array_keys($now_installed_list)array_keys($was_installed_list));
      while ($added_modules) {
        $initial_count = count($added_modules);
        foreach ($added_modules as $to_uninstall) {
          // See if we can currently uninstall this module (if its dependencies           // have been uninstalled), and do so if we can.           $this->drupalGet('admin/modules/uninstall');
          $checkbox = $this->assertSession()->fieldExists("uninstall[$to_uninstall]");
          if (!$checkbox->hasAttribute('disabled')) {
            // This one is eligible for being uninstalled.             $package = $all_modules[$to_uninstall]->info['package'];
            $this->assertSuccessfulUninstall($to_uninstall$package);
            $added_modules = array_diff($added_modules[$to_uninstall]);
          }
        }

        // If we were not able to find a module to uninstall, fail and exit the         // loop.         $final_count = count($added_modules);
        
Home | Imprint | This part of the site doesn't use cookies.