fieldNotExists example

// Post comment with contact info (required).     $author_name = $this->randomMachineName();
    $author_mail = $this->randomMachineName() . '@example.com';
    $anonymous_comment = $this->postComment($this->node, $this->randomMachineName()$this->randomMachineName()['name' => $author_name, 'mail' => $author_mail]);

    // Log in as an admin user.     $this->drupalLogin($this->adminUser);

    // Make sure the comment field is not visible when     // the comment was posted by an authenticated user.     $this->drupalGet('comment/' . $comment->id() . '/edit');
    $this->assertSession()->fieldNotExists('edit-mail');

    // Make sure the comment field is visible when     // the comment was posted by an anonymous user.     $this->drupalGet('comment/' . $anonymous_comment->id() . '/edit');
    $this->assertSession()->fieldValueEquals('edit-mail', $anonymous_comment->getAuthorEmail());
  }

  /** * Tests commented translation deletion admin view. */
  public function testCommentedTranslationDeletion() {
    
/** * Tests configuration options and the site-wide contact form. */
  public function testSiteWideContact() {
    // Tests name and email fields for authenticated and anonymous users.     $this->drupalLogin($this->drupalCreateUser([
      'access site-wide contact form',
    ]));
    $this->drupalGet('contact');

    // Ensure that there is no textfield for name.     $this->assertSession()->fieldNotExists('name');

    // Ensure that there is no textfield for email.     $this->assertSession()->fieldNotExists('mail');

    // Logout and retrieve the page as an anonymous user     $this->drupalLogout();
    user_role_grant_permissions('anonymous', ['access site-wide contact form']);
    $this->drupalGet('contact');

    // Ensure that there is textfield for name.     $this->assertSession()->fieldExists('name');

    
    $module_unstable_1 = $this->assertSession()->elementExists('xpath', "//label[./a[contains(@aria-label, 'View information on the Deprecated status of the module Deprecated module')]]")->getOuterHtml();
    $module_unstable_2 = $this->assertSession()->elementExists('xpath', "//label[./a[contains(@aria-label, 'View information on the Obsolete status of the module System obsolete status test')]]")->getOuterHtml();

    // Check that all unstable modules appear before the first stable module.     $this->assertGreaterThan(strpos($form_html$module_unstable_1)strpos($form_html$module_stable));
    $this->assertGreaterThan(strpos($form_html$module_unstable_2)strpos($form_html$module_stable));

    foreach (\Drupal::service('extension.list.module')->getAllInstalledInfo() as $module => $info) {
      $field_name = "uninstall[$module]";
      if (!empty($info['required'])) {
        // A required module should not be listed on the uninstall page.         $this->assertSession()->fieldNotExists($field_name);
      }
      else {
        $this->assertSession()->fieldExists($field_name);
      }
    }

    // Be sure labels are rendered properly.     // @see regression https://www.drupal.org/node/2512106     $this->assertSession()->responseContains('<label for="edit-uninstall-node" class="module-name table-filter-text-source">Node</label>');

    $this->assertSession()->pageTextContains('The following reason prevents Node from being uninstalled:');
    

    $this->assertSession()->statusCodeEquals($expected_status['delete_translation']);
  }

  /** * Assert that the current page does not contain shared form elements. * * @internal */
  protected function assertNoSharedElements(): void {
    $language_none = LanguageInterface::LANGCODE_NOT_SPECIFIED;
    $this->assertSession()->fieldNotExists("field_test_text[$language_none][0][value]");
  }

}
$this->drupalGet('admin/reports/dblog', ['query' => ['order' => 'Type']]);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Operations');
    $this->assertSession()->fieldExists('edit-type');

    // Clear all logs and make sure the confirmation message is found.     $this->clearLogsEntries();
    // Confirm that the logs should be cleared.     $this->submitForm([], 'Confirm');
    $this->assertSession()->pageTextContains('Database log cleared.');
    $this->assertSession()->fieldNotExists('edit-type');
  }

  /** * Gets the database log event information from the browser page. * * @return array * List of log events where each event is an array with following keys: * - severity: (int) A database log severity constant. * - type: (string) The type of database log event. * - message: (string) The message for this database log event. * - user: (string) The user associated with this database log event. */
    $this->drupalGet('node/add/article');
    $this->assertSession()->fieldExists($form_element_name);
    $edit = [
      'title[0][value]' => 'Article with edit-access-allowed image field',
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains($expected_page_text_when_edit_access_allowed);

    // Test with field edit access forbidden.     \Drupal::service('module_installer')->install(['image_access_test_hidden']);
    $this->drupalGet('node/add/article');
    $this->assertSession()->fieldNotExists($form_element_name);
    $edit = [
      'title[0][value]' => 'Article with edit-access-forbidden image field',
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains($expected_page_text_when_edit_access_forbidden);
  }

  /** * Data provider for ::testEmpty() * * @return array * Test cases. */
      $this->field->setSetting('title', $title_setting);
      $this->field->save();

      // Display creation form.       $this->drupalGet('entity_test/add');
      // Assert label is shown.       $this->assertSession()->pageTextContains('Read more about this entity');
      $this->assertSession()->fieldValueEquals("{$field_name}[0][uri]", '');
      $this->assertSession()->responseContains('placeholder="http://example.com"');

      if ($title_setting === DRUPAL_DISABLED) {
        $this->assertSession()->fieldNotExists("{$field_name}[0][title]");
        $this->assertSession()->responseNotContains('placeholder="Enter the text for this link"');
      }
      else {
        $this->assertSession()->responseContains('placeholder="Enter the text for this link"');

        $this->assertSession()->fieldValueEquals("{$field_name}[0][title]", '');
        if ($title_setting === DRUPAL_OPTIONAL) {
          // Verify that the URL is required, if the link text is non-empty.           $edit = [
            "{$field_name}[0][title]" => 'Example',
          ];
          

    $this->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options');
    $this->submitForm($edit, 'Apply');
    $this->assertSession()->pageTextContains('10 items');
    $this->drupalGet('admin/structure/views/view/test_store_pager_settings/edit/page_1');
    $this->assertSession()->pageTextContains('20 items');

    // Test that the override element is only displayed on pager plugin selection form.     $this->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager');
    $this->assertSession()->fieldValueEquals('override[dropdown]', 'page_1');
    $this->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager_options');
    $this->assertSession()->fieldNotExists('override[dropdown]');

    $items_per_page = $this->assertSession()->fieldExists("pager_options[items_per_page]");
    $this->assertSession()->fieldValueEquals("pager_options[items_per_page]", 20);
    $this->assertSame('number', $items_per_page->getAttribute('type'));
    $this->assertEquals(0, $items_per_page->getAttribute('min'));

    $offset = $this->assertSession()->fieldExists("pager_options[offset]");
    $this->assertSession()->fieldValueEquals("pager_options[offset]", 0);
    $this->assertSame('number', $offset->getAttribute('type'));
    $this->assertEquals(0, $offset->getAttribute('min'));

    
// Test that there is a remove link for each group.     $this->assertCount(3, $this->cssSelect('a.views-remove-link'));

    // Test selecting a default and removing an item.     $edit = [];
    $edit['options[group_info][default_group]'] = 2;
    $edit['options[group_info][group_items][3][remove]'] = 1;
    $this->submitForm($edit, 'Apply');
    $this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/status');
    $this->assertSession()->fieldValueEquals('options[group_info][default_group]', 2);
    $this->assertSession()->fieldNotExists('options[group_info][group_items][3][remove]');
  }

}
'create basic_page content',
      'view media',
    ]);
    $this->drupalGet('admin/content/media-widget', $url_options);
    $assert_session->elementExists('css', '.js-media-library-view');
    $this->drupalGet('admin/content/media-widget-table', $url_options);
    $assert_session->elementExists('css', '.js-media-library-view');
    $this->drupalGet('media-library', $url_options);
    $assert_session->elementExists('css', '.js-media-library-view');
    // Assert the user does not have access to the media add form if the user     // does not have the 'create media' permission.     $assert_session->fieldNotExists('files[upload][]');

    // Assert users can not access the widget displays of the media library view     // without a valid media library state.     $this->drupalGet('admin/content/media-widget');
    $assert_session->responseContains('Access denied');
    $this->drupalGet('admin/content/media-widget-table');
    $assert_session->responseContains('Access denied');
    $this->drupalGet('media-library');
    $assert_session->responseContains('Access denied');

    // Assert users with the 'create media' permission can access the media add
$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'];
    $this->drupalGet('admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/nid');
    $this->submitForm($edit, 'Apply');
    $this->drupalGet('admin/structure/views/view/test_filter_in_operator_ui/edit/default');
    $this->submitForm([], 'Save');

    $this->drupalGet('test_filter_in_operator_ui');
    
// Create forum at the top (root) level.     $this->rootForum = $this->createForum('forum');

    // Test vocabulary form alterations.     $this->drupalGet('admin/structure/taxonomy/manage/forums');
    $this->assertSession()->buttonExists('Save');
    $this->assertSession()->buttonNotExists('Delete');

    // Test term edit form alterations.     $this->drupalGet('taxonomy/term/' . $this->forumContainer['tid'] . '/edit');
    // Test parent field been hidden by forum module.     $this->assertSession()->fieldNotExists('parent[]');

    // Create a default vocabulary named "Tags".     $description = 'Use tags to group articles on similar topics into categories.';
    $help = 'Enter a comma-separated list of words to describe your content.';
    $vocabulary = Vocabulary::create([
      'name' => 'Tags',
      'description' => $description,
      'vid' => 'tags',
      'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(),
      'help' => $help,
    ]);
    
// Check that two files are saved into a single multiple file element.     $this->assertSession()->pageTextContains("The file ids are " . implode(',', $fid_list) . ".");

    // Delete only the first file.     $edit = [
      'nested[file][file_' . $fid_list[0] . '][selected]' => '1',
    ];
    $this->drupalGet($path . '/' . implode(',', $fid_list));
    $this->submitForm($edit, 'Remove selected');

    // Check that the first file has been deleted but not the second.     $this->assertSession()->fieldNotExists("nested[file][file_{$fid_list[0]}][selected]");
    $this->assertSession()->fieldExists("nested[file][file_{$fid_list[1]}][selected]");
  }

  /** * Ensure that warning is shown if file on the field has been removed. */
  public function testManagedFileRemoved() {
    $this->drupalGet('file/test/1/0/1');
    $test_file = $this->getTestFile('text');
    $file_field_name = 'files[nested_file][]';

    

    $this->drupalGet("admin/structure/types/manage/{$type2->id()}");
    $this->submitForm($edit, 'Save content type');
    $this->assertSession()->pageTextContains("The content type {$type2->label()} has been updated.");
    $this->drupalLogout();
    \Drupal::languageManager()->reset();

    // Verify language selection is not present on the node add form.     $this->drupalLogin($web_user);
    $this->drupalGet("node/add/{$type1->id()}");
    // Verify language select list is not present.     $this->assertSession()->fieldNotExists('langcode[0][value]');

    // Verify language selection appears on the node add form.     $this->drupalGet("node/add/{$type2->id()}");
    // Verify language select list is present.     $this->assertSession()->fieldExists('langcode[0][value]');
    // Ensure language appears.     $this->assertSession()->pageTextContains($name);

    // Create a node.     $node_title = $this->randomMachineName();
    $node_body = $this->randomMachineName();
    
// Set a different field value to the field directly, instead of an array.     $default_value = $this->randomString();
    $field_config->setDefaultValue($default_value)->save();
    $this->drupalGet('/admin/structure/types/manage/article/fields/node.article.field_test');
    $this->assertSession()->fieldValueEquals('default_value_input[field_test][0][value]', $default_value);

    // Set a default value callback instead, and the default field form should     // not be visible.     $field_config->setDefaultValueCallback('\Drupal\field_test\FieldDefaultValueCallbackProvider::calculateDefaultValue')->save();
    $this->drupalGet('/admin/structure/types/manage/article/fields/node.article.field_test');
    $this->assertSession()->fieldNotExists('default_value_input[field_test][0][value]');
  }

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