fieldValueEquals example

// Check that the block exists in the database.     $blocks = \Drupal::entityQuery('block_content')
      ->accessCheck(FALSE)
      ->condition('info', $edit['info[0][value]'])
      ->execute();
    $block = BlockContent::load(reset($blocks));
    $this->assertNotEmpty($block, 'Content block found in database.');

    // Load the edit page.     $this->drupalGet('admin/content/block/' . $block->id());
    $this->assertSession()->fieldValueEquals($title_key$edit[$title_key]);
    $this->assertSession()->fieldValueEquals($body_key$edit[$body_key]);

    // Edit the content of the block.     $edit = [];
    $edit[$title_key] = $this->randomMachineName(8);
    $edit[$body_key] = $this->randomMachineName(16);
    // Stay on the current page, without reloading.     $this->submitForm($edit, 'Save');

    // Edit the same block, creating a new revision.     $this->drupalGet("admin/content/block/" . $block->id());
    
    foreach (static::$timezones as $timezone) {

      $this->setSiteTimezone($timezone);
      $this->assertEquals($timezone$this->config('system.date')->get('timezone.default'), 'Time zone set to ' . $timezone);

      // Ensure field is set to a date-only field.       $this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATE);
      $this->fieldStorage->save();

      // Display creation form.       $this->drupalGet('entity_test/add');
      $this->assertSession()->fieldValueEquals("{$field_name}[0][value][date]", '');
      $this->assertSession()->fieldValueEquals("{$field_name}[0][end_value][date]", '');
      $this->assertSession()->elementExists('xpath', '//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]');
      $this->assertSession()->fieldNotExists("{$field_name}[0][value][time]");
      $this->assertSession()->fieldNotExists("{$field_name}[0][end_value][time]");
      $this->assertSession()->elementTextContains('xpath', '//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label);
      $this->assertSession()->elementExists('xpath', '//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]');
      $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0--description"]');

      // Build up dates in the UTC timezone.       $value = '2012-12-31 00:00:00';
      $start_date = new DrupalDateTime($value, 'UTC');
      
$edit['options[group_info][group_items][2][operator]'] = '<=';
    $edit['options[group_info][group_items][2][value][value]'] = 27;
    $edit['options[group_info][group_items][3][title]'] = 'From 26 to 28';
    $edit['options[group_info][group_items][3][operator]'] = 'between';
    $edit['options[group_info][group_items][3][value][min]'] = 26;
    $edit['options[group_info][group_items][3][value][max]'] = 28;

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

    $this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
    foreach ($edit as $name => $value) {
      $this->assertSession()->fieldValueEquals($name$value);
    }

    $this->drupalGet('admin/structure/views/view/test_view');
    $this->submitForm([], 'Save');
    $this->assertConfigSchemaByName('views.view.test_view');

    // Test that the exposed filter works as expected.     $this->drupalGet('test_view-path');
    $this->assertSession()->pageTextContains('John');
    $this->assertSession()->pageTextContains('Paul');
    $this->assertSession()->pageTextContains('Ringo');
    
$test_source_field = $assert_session->elementExists('xpath', "//*[contains(text(), '$source_field_label')]", $form)->getOuterHtml();
      $vertical_tabs = $assert_session->elementExists('css', '.js-form-type-vertical-tabs', $form)->getOuterHtml();
      $this->assertGreaterThan(strpos($form_html$test_source_field)strpos($form_html$vertical_tabs));
      // The "Published" checkbox should be the last element.       $date_field = $assert_session->fieldExists('Date', $form)->getOuterHtml();
      $published_checkbox = $assert_session->fieldExists('Published', $form)->getOuterHtml();
      $this->assertGreaterThan(strpos($form_html$date_field)strpos($form_html$published_checkbox));
      if (is_a($media_type->getSource(), Image::class, TRUE)) {
        // Assert the default entity view display is configured with an image         // style.         $this->drupalGet('/admin/structure/media/manage/' . $media_type->id() . '/display');
        $assert_session->fieldValueEquals('fields[field_media_image][type]', 'image');
        $assert_session->elementTextContains('css', 'tr[data-drupal-selector="edit-fields-field-media-image"]', 'Image style: Large (480×480)');
        // By default for media types with an image source, only the image         // component should be enabled.         $assert_session->elementsCount('css', 'input[name$="_settings_edit"]', 1);
      }

    }
  }

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

  /** * Tests Image toolkit setup form. */
  public function testToolkitSetupForm() {
    // Get form.     $this->drupalGet('admin/config/media/image-toolkit');

    // Test that default toolkit is GD.     $this->assertSession()->fieldValueEquals('image_toolkit', 'gd');

    // Test changing the jpeg image quality.     $edit = ['gd[image_jpeg_quality]' => '70'];
    $this->submitForm($edit, 'Save configuration');
    $this->assertEquals('70', $this->config('system.image.gd')->get('jpeg_quality'));

    // Test changing the toolkit.     $edit = ['image_toolkit' => 'test'];
    $this->submitForm($edit, 'Save configuration');
    $this->assertEquals('test', $this->config('system.image')->get('toolkit'));
    $this->assertSession()->fieldValueEquals('test[test_parameter]', '10');

    
foreach (filter_formats() as $format) {
      if (!$format->isFallbackFormat()) {
        $this->drupalGet('admin/config/content/formats/manage/' . $format->id() . '/disable');
        $this->submitForm([], 'Disable');
      }
    }
    $this->drupalLogin($this->webUser);

    // Display the creation form. Since the user only has access to one format,     // no format selector will be displayed.     $this->drupalGet('entity_test/add');
    $this->assertSession()->fieldValueEquals("{$field_name}[0][value]", '');
    $this->assertSession()->fieldNotExists("{$field_name}[0][format]");

    // Submit with data that should be filtered.     $value = '<em>' . $this->randomMachineName() . '</em>';
    $edit = [
      "{$field_name}[0][value]" => $value,
    ];
    $this->submitForm($edit, 'Save');
    preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
    $id = $match[1];
    $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been created.');

    

      ])
      ->save();
    $display_repository->getViewDisplay('entity_test', 'entity_test')
      ->setComponent($field_name[
        'type' => 'number_decimal',
      ])
      ->save();

    // Display creation form.     $this->drupalGet('entity_test/add');
    $this->assertSession()->fieldValueEquals("{$field_name}[0][value]", '');
    $this->assertSession()->responseContains('placeholder="0.00"');

    // Submit a signed decimal value within the allowed precision and scale.     $value = '-1234.5678';
    $edit = [
      "{$field_name}[0][value]" => $value,
    ];
    $this->submitForm($edit, 'Save');
    preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
    $id = $match[1];
    $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been created.');
    
// Assert that the default display of the media type only shows the source     // field.     $this->drupalGet("/admin/structure/media/manage/$media_type_id/display");
    // There should be only one field with editable settings, and it should be     // the source field.     $assert_session->elementsCount('css', 'input[name$="_settings_edit"]', 1);
    $source_field_name = $media_type->getSource()
      ->getSourceFieldDefinition($media_type)
      ->getName();
    $assert_session->buttonExists("{$source_field_name}_settings_edit");
    // Ensure the source field label is configured as expected.     $assert_session->fieldValueEquals("fields[$source_field_name][label]", $source_label_visibility);

    // Bundle definitions are statically cached in the context of the test, we     // need to make sure we have updated information before proceeding with the     // actions on the UI.     \Drupal::service('entity_type.bundle.info')->clearCachedBundles();

    return $media_type;
  }

}
$this->clickLink('Add a new transition');
    $this->assertCount(2, $this->cssSelect('input[name="to"][type="radio"]'));
    $this->assertCount(0, $this->cssSelect('input[name="to"][checked="checked"][type="radio"]'));
    $this->submitForm(['id' => 'create_new_draft', 'label' => 'Create new draft', 'from[draft]' => 'draft', 'to' => 'draft'], 'Save');
    $this->assertSession()->pageTextContains('Created Create new draft transition.');
    $workflow = $workflow_storage->loadUnchanged('test');
    $this->assertTrue($workflow->getTypePlugin()->getState('draft')->canTransitionTo('draft'), 'Can transition from draft to draft');

    // The fist state to edit on the page should be published.     $this->clickLink('Edit');
    $this->assertSession()->fieldValueEquals('label', 'Published');
    // Change the label.     $this->submitForm(['label' => 'Live'], 'Save');
    $this->assertSession()->pageTextContains('Saved Live state.');

    // Allow published to draft.     $this->clickLink('Edit', 3);
    $this->submitForm(['from[published]' => 'published'], 'Save');
    $this->assertSession()->pageTextContains('Saved Create new draft transition.');
    $workflow = $workflow_storage->loadUnchanged('test');
    $this->assertTrue($workflow->getTypePlugin()->getState('published')->canTransitionTo('draft'), 'Can transition from published to draft');

    
$this->clickLink('Add text format');
    $format_id = mb_strtolower($this->randomMachineName());
    $name = $this->randomMachineName();
    $edit = [
      'format' => $format_id,
      'name' => $name,
    ];
    $this->submitForm($edit, 'Save configuration');

    // Verify default weight of the text format.     $this->drupalGet('admin/config/content/formats');
    $this->assertSession()->fieldValueEquals("formats[$format_id][weight]", 0);

    // Change the weight of the text format.     $edit = [
      "formats[$format_id][weight]" => 5,
    ];
    $this->drupalGet('admin/config/content/formats');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->fieldValueEquals("formats[$format_id][weight]", 5);

    // Edit text format.     $this->drupalGet('admin/config/content/formats');
    


    // The untrusted user tries to edit content that is written in a text format     // that they are not allowed to use. The editor is still loaded. CKEditor,     // for example, supports being loaded in a disabled state.     $this->drupalGet('node/1/edit');
    [$editor_settings_present$editor_js_present$body] = $this->getThingsToCheck('body');
    $this->assertTrue($editor_settings_present, 'Text Editor module settings.');
    $this->assertTrue($editor_js_present, 'Text Editor JavaScript.');
    $this->assertSession()->elementsCount('xpath', $body, 1);
    $this->assertSession()->fieldDisabled("edit-body-0-value");
    $this->assertSession()->fieldValueEquals("edit-body-0-value", 'This field has been disabled because you do not have sufficient permissions to edit it.');
    $this->assertSession()->elementNotExists('css', 'select.js-filter-list');
    // Verify that no single text format hidden input exists on the page.     $this->assertSession()->elementNotExists('xpath', '//input[@type="hidden" and contains(@class, "editor")]');
  }

  /** * Tests supported element types. */
  public function testSupportedElementTypes() {
    // Associate the unicorn text editor with the "Full HTML" text format.     $editor = Editor::create([
      
$this->rebuildContainer();
    $this->drupalGet('admin/config/media/file-system');
    $this->assertSession()->fieldExists('translation_path');

    // The setting should persist.     $translation_path = $this->publicFilesDirectory . '/translations_changed';
    $fields = [
      'translation_path' => $translation_path,
    ];
    $this->submitForm($fields, 'Save configuration');
    $this->drupalGet('admin/config/media/file-system');
    $this->assertSession()->fieldValueEquals('translation_path', $translation_path);
    $this->assertEquals($this->config('locale.settings')->get('translation.path')$translation_path);
  }

}
$this->drupalGet("{$translation_base_url}/fr/add");
    $this->submitForm($edit, 'Save translation');
    $this->assertSession()->pageTextContains('Successfully saved French translation.');

    // Check for edit, delete links (and no 'add' link) for French language.     $this->assertSession()->linkByHrefNotExists("$translation_base_url/fr/add");
    $this->assertSession()->linkByHrefExists("$translation_base_url/fr/edit");
    $this->assertSession()->linkByHrefExists("$translation_base_url/fr/delete");

    // Check translation saved proper.     $this->drupalGet("$translation_base_url/fr/edit");
    $this->assertSession()->fieldValueEquals('translation[config_names][system.site][name]', $fr_site_name);
    $this->assertSession()->fieldValueEquals('translation[config_names][system.site][slogan]', $fr_site_slogan);

    // Place branding block with site name and slogan into header region.     $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);

    // Check French translation of site name and slogan are in place.     $this->drupalGet('fr');
    $this->assertSession()->pageTextContains($fr_site_name);
    $this->assertSession()->pageTextContains($fr_site_slogan);

    // Visit French site to ensure base language string present as source.
// Make sure that the action updated properly.     $this->assertSession()->pageTextContains('The action has been successfully saved.');
    // The old action label does NOT appear on the configuration page.     $this->assertSession()->pageTextNotContains($action_label);
    // The action label appears on the configuration page after we've updated     // the complex action.     $this->assertSession()->pageTextContains($new_action_label);

    // Make sure the URL appears when re-editing the action.     $this->clickLink('Configure');
    $this->assertSession()->fieldValueEquals('url', 'admin');

    // Make sure that deletions work properly.     $this->drupalGet('admin/config/system/actions');
    $this->clickLink('Delete');
    $this->assertSession()->statusCodeEquals(200);
    $edit = [];
    $this->submitForm($edit, 'Delete');
    $this->assertSession()->statusCodeEquals(200);

    // Make sure that the action was actually deleted.     $this->assertSession()->pageTextContains("The action $new_action_label has been deleted.");
    
$this->assertSession()->elementNotExists('xpath', $field_xpath);
    $this->assertSession()->elementNotExists('xpath', $clue_xpath);

    // Verify a warning is displayed.     $this->assertSession()->statusMessageContains('Fields that apply to all languages are hidden to avoid conflicting changes.', 'warning');
    $this->assertSession()->elementExists('xpath', '//a[@href="' . $entity->toUrl('edit-form')->toString() . '" and text()="Edit them on the original language form"]');

    // Verify that checkboxes on the language content settings page are checked     // and disabled for moderated bundles.     $this->drupalGet($settings_url);
    $field_name = "settings[{$this->entityTypeId}][{$this->bundle}][settings][content_translation][untranslatable_fields_hide]";
    $this->assertSession()->fieldValueEquals($field_name, 1);
    $this->assertSession()->fieldDisabled($field_name);
    $this->submitForm([$settings_key => 0], 'Save configuration');
    $this->assertSession()->fieldValueEquals($field_name, 1);
    $this->assertSession()->fieldDisabled($field_name);
  }

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