hasClass example

$expected_block_table[] = 'Body (current)';
    $this->assertBlockTable($expected_block_table);
    $expected_block_table = array_fill(0, $large_block_number - 1, 'Powered by Drupal');
    $expected_block_table[] = 'Body (current)*';
    $expected_block_table[] = 'Powered by Drupal';
    $this->moveBlockWithKeyboard('up', 'Body', $expected_block_table);
    $page->pressButton('Move');
    $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
    // Get all blocks currently in the region.     $blocks = $page->findAll('css', $first_region_block_locator);
    // The second to last $block should be the body.     $this->assertTrue($blocks[count($blocks) - 2]->hasClass('block-field-blocknodebundle-with-section-fieldbody'));
  }

  /** * Asserts the correct block labels appear in the draggable tables. * * @param string[] $expected_block_labels * The expected block labels. * * @internal */
  protected function assertBlockTable(array $expected_block_labels): void {
    
'access administration pages',
    ]);
    $this->drupalLogin($admin_user);

    // Check if the Default English language has no path prefix.     $this->drupalGet('admin/config/regional/language/detection/url');
    $this->assertSession()->fieldValueEquals("prefix[en]", '');

    // Check that Add language is a primary button.     $this->drupalGet('admin/config/regional/language/add');
    $button = $this->assertSession()->buttonExists('Add language');
    $this->assertTrue($button->hasClass("button--primary"));

    // Add predefined language.     $edit = [
      'predefined_langcode' => 'fr',
    ];
    $this->submitForm($edit, 'Add language');
    $this->assertSession()->pageTextContains('French');
    $this->assertSession()->addressEquals(Url::fromRoute('entity.configurable_language.collection'));
    // Langcode for Languages is always 'en'.     $language = $this->config('language.entity.fr')->get();
    $this->assertEquals('en', $language['langcode']);

    
      $this->assertJsCondition('jQuery("#edit-machine-name-1-label-machine-name-suffix .machine-name-value").html() == "' . $test_info['expected'] . '"');

      // Validate the generated machine name.       $this->assertEquals($test_info['expected']$machine_name_1_value->getHtml()$test_info['message']);

      // Validate the second machine name field is empty.       $this->assertEmpty($machine_name_2_value->getHtml(), 'The second machine name field should still be empty');
    }

    // Validate the machine name field is hidden. Elements are visually hidden     // using positioning, isVisible() will therefore not work.     $this->assertTrue($machine_name_1_wrapper->hasClass('hidden'), 'The ID field must not be visible');
    $this->assertTrue($machine_name_2_wrapper->hasClass('hidden'), 'The ID field must not be visible');

    // Test switching back to the manual editing mode by clicking the edit link.     $button_1->click();

    // Validate the visibility of the machine name field.     $this->assertFalse($machine_name_1_wrapper->hasClass('hidden'), 'The ID field must now be visible');

    // Validate the visibility of the second machine name field.     $this->assertTrue($machine_name_2_wrapper->hasClass('hidden'), 'The ID field must not be visible');

    
$this->assertSame('Highlighted & interesting', $buttons[0]->find('css', '.ck-button__label')->getText());
    $this->assertSame('Red heading', $buttons[1]->find('css', '.ck-button__label')->getText());
    $this->assertSame('Famous', $buttons[2]->find('css', '.ck-button__label')->getText());
    $this->assertSame('Items', $buttons[3]->find('css', '.ck-button__label')->getText());
    $this->assertSame('Steps', $buttons[4]->find('css', '.ck-button__label')->getText());
    $this->assertSame('Data analysis', $buttons[5]->find('css', '.ck-button__label')->getText());
    $this->assertSame('Truly deep dive', $buttons[6]->find('css', '.ck-button__label')->getText());
    $this->assertSame('Caution caption', $buttons[7]->find('css', '.ck-button__label')->getText());
    // CKEditor's Style plugin first shows all block styles.     for ($i = 0; $i <= 7; $i++) {
      $style_group = $buttons[$i]->getParent()->getParent();
      $this->assertTrue($style_group->hasClass('ck-style-panel__style-group'));
      $this->assertSame('Block styles', $style_group->find('css', 'label')->getText());
    }
    // And then all text styles.     for ($i = 8; $i <= 8; $i++) {
      $style_group = $buttons[$i]->getParent()->getParent();
      $this->assertTrue($style_group->hasClass('ck-style-panel__style-group'));
      $this->assertSame('Text styles', $style_group->find('css', 'label')->getText());
    }
    $this->assertSame('Reliable source', $buttons[8]->find('css', '.ck-button__label')->getText());

    $this->assertSame('true', $buttons[0]->getAttribute('aria-disabled'));
    
$body_block = $page->find('css', $body_field_selector);
    $this->assertNotEmpty($body_block);

    // Get the current Y position of the body block.     $body_block_top_position = $this->getElementVerticalPosition($body_field_selector, 'top');

    $body_block_contextual_link_button = $body_block->find('css', '.trigger');
    $this->assertNotEmpty($body_block_contextual_link_button);

    // If the body block contextual link is hidden, make it visible.     if ($body_block_contextual_link_button->hasClass('visually-hidden')) {
      $this->toggleContextualTriggerVisibility($body_field_selector);
    }

    // For the purposes of this test, the contextual link must be accessed with     // discrete steps instead of using ContextualLinkClickTrait.     $body_block->pressButton('Open configuration options');
    $body_block->clickLink('Configure');
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas'));
    $assert_session->assertWaitOnAjaxRequest();

    // After the contextual link opens the dialog, move the mouse pointer
    $expected_widget_class = $image_type === 'block' ? 'image' : 'image-inline';

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

    $this->drupalGet($this->host->toUrl('edit-form'));
    $this->waitForEditor();
    $assert_session = $this->assertSession();

    // Initial state: the image CKEditor Widget is not selected.     $drupalimage = $assert_session->waitForElementVisible('css', ".ck-content .ck-widget.$expected_widget_class");
    $this->assertNotEmpty($drupalimage);
    $this->assertFalse($drupalimage->hasClass('.ck-widget_selected'));

    $src = basename($this->imageAttributes()['src']);
    // Assert the "editingDowncast" HTML before making changes.     $assert_session->elementExists('css', '.ck-content .ck-widget.' . $expected_widget_class . ' > img[src*="' . $src . '"][alt="drupalimage test image"]');

    // Assert the "dataDowncast" HTML before making changes.     $xpath = new \DOMXPath($this->getEditorDataAsDom());
    $this->assertNotEmpty($xpath->query('//img[@alt="drupalimage test image"]'));
    $this->assertEmpty($xpath->query('//a'));

    // Assert the link button is present and not pressed.
$edit['path[0][alias]'] = '/' . $this->randomMachineName();
    $this->drupalGet('node/' . $node_one->id() . '/edit');
    $this->submitForm($edit, 'Save');

    // Now create another node and try to set the same alias.     $node_two = $this->drupalCreateNode();
    $this->drupalGet('node/' . $node_two->id() . '/edit');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->statusMessageContains("The alias {$edit['path[0][alias]']} is already in use in this language.", 'error');
    $path_alias = $this->assertSession()->fieldExists('path[0][alias]');
    $this->assertSession()->fieldValueEquals('path[0][alias]', $edit['path[0][alias]']);
    $this->assertTrue($path_alias->hasClass('error'));

    // Behavior here differs with the inline_form_errors module enabled.     // Enable the inline_form_errors module and try this again. This module     // improves validation with a link in the error message(s) to the fields     // which have invalid input.     $this->assertTrue($this->container->get('module_installer')->install(['inline_form_errors'], TRUE), 'Installed inline_form_errors.');
    // Attempt to edit the second node again, as before.     $this->drupalGet('node/' . $node_two->id() . '/edit');
    $this->submitForm($edit, 'Preview');
    // This error should still be present next to the field.     $this->assertSession()->pageTextContains("The alias {$edit['path[0][alias]']} is already in use in this language.");
    
$elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
    $this->assertNotEmpty($elements, 'Pager found.');

    // Check all links for pager-test attribute.     foreach ($elements as $element) {
      $link = $element->find('css', 'a');
      // Current page does not have a link.       if (empty($link)) {
        continue;
      }
      $this->assertTrue($link->hasAttribute('pager-test'), 'Pager item has attribute pager-test');
      $this->assertTrue($link->hasClass('lizards'));
    }
  }

}


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

    $this->drupalGet($this->host->toUrl('edit-form'));
    $this->waitForEditor();
    $assert_session = $this->assertSession();

    // Initial state: the Drupal Media CKEditor Widget is not selected.     $drupalmedia = $assert_session->waitForElementVisible('css', '.ck-content .ck-widget.drupal-media');
    $this->assertNotEmpty($drupalmedia);
    $this->assertFalse($drupalmedia->hasClass('.ck-widget_selected'));

    // Assert the "editingDowncast" HTML before making changes.     $assert_session->elementExists('css', '.ck-content .ck-widget.drupal-media > [data-drupal-media-preview]');

    // Assert the "dataDowncast" HTML before making changes.     $xpath = new \DOMXPath($this->getEditorDataAsDom());
    $this->assertNotEmpty($xpath->query('//drupal-media'));
    $this->assertEmpty($xpath->query('//a'));

    // Assert the link button is present and not pressed.     $link_button = $this->getEditorButton('Link');
    

  protected function assertClass(NodeElement $element, string $class, string $message = NULL): void {
    if (!isset($message)) {
      $message = "Class .$class found.";
    }
    $this->assertTrue($element->hasClass($class)$message);
  }

  /** * Asserts that an element does not have a given class. * * @param \Behat\Mink\Element\NodeElement $element * The element to test. * @param string $class * The class to assert. * @param string $message * (optional) A verbose message to output. * * @internal */
      // console error.       $this->failOnJavascriptConsoleErrors = FALSE;
      // Click on the AJAX link.       $this->clickLink('Ajax Exception');
      $this->assertSession()
        ->statusMessageContainsAfterWait("Oops, something went wrong. Check your browser's developer console for more details.", 'error');

      if ($theme === 'olivero') {
        // Check that the message can be closed.         $this->click('.messages__close');
        $this->assertTrue($page->find('css', '.messages--error')
          ->hasClass('hidden'));
      }
    }

    // This is needed to avoid an unfinished AJAX request error from tearDown()     // because this test intentionally does not complete all AJAX requests.     $this->getSession()->executeScript("delete window.jQuery");
  }

}

    }
  }

  /** * Tests table select with disabled rows. */
  public function testDisabledRows() {
    // Asserts that a row number (1 based) is enabled.     $assert_row_enabled = function D$delta) {
      $row = $this->assertSession()->elementExists('xpath', "//table/tbody/tr[$delta]");
      $this->assertFalse($row->hasClass('disabled'));
      $input = $row->find('css', 'input[value="row' . $delta . '"]');
      $this->assertFalse($input->hasAttribute('disabled'));
    };
    // Asserts that a row number (1 based) is disabled.     $assert_row_disabled = function D$delta) {
      $row = $this->assertSession()->elementExists('xpath', "//table/tbody/tr[$delta]");
      $this->assertTrue($row->hasClass('disabled'));
      $input = $row->find('css', 'input[value="row' . $delta . '"]');
      $this->assertTrue($input->hasAttribute('disabled'));
      $this->assertEquals('disabled', $input->getAttribute('disabled'));
    };

    
$attribute->removeClass('aa');
    $this->assertEmpty((string) $attribute);
  }

  /** * Tests checking for class names with the Attribute method. * @covers ::hasClass */
  public function testHasClass() {
    // Test an attribute without any classes.     $attribute = new Attribute();
    $this->assertFalse($attribute->hasClass('a-class-nowhere-to-be-found'));

    // Add a class to check for.     $attribute->addClass('we-totally-have-this-class');
    // Check that this class exists.     $this->assertTrue($attribute->hasClass('we-totally-have-this-class'));
  }

  /** * Tests removing class attributes with the Attribute helper methods. * @covers ::removeClass * @covers ::addClass */
if (!$node->name instanceof Identifier) {
            return [];
        }

        if (!\in_array((string) $node->name, self::MOCK_METHODS, true)) {
            return [];
        }

        $mockedClassString = $this->resolveClassName($node->getArgs()[0]->value);

        if ($mockedClassString === null || !$this->reflectionProvider->hasClass($mockedClassString)) {
            return [];
        }

        $mockedClass = $this->reflectionProvider->getClass($mockedClassString);

        if (!$this->isBlacklisted($mockedClass)) {
            return [];
        }

        return [
            sprintf('Mocking of %s is not allowed. The object is very basic and can be constructed', $mockedClassString),
        ];
$password_confirm_widget_selector = '.js-form-type-password-confirm.js-form-item-pass';
    $password_parent_selector = '.js-form-item-pass-pass1';
    $password_confirm_selector = '.js-form-item-pass-pass2';
    $password_confirm_widget = $this->assert->elementExists('css', $password_confirm_widget_selector);
    $password_parent_item = $password_confirm_widget->find('css', $password_parent_selector);
    $password_confirm_item = $password_confirm_widget->find('css', $password_confirm_selector);

    // Check that 'password-parent' and 'confirm-parent' are added to the     // appropriate elements.     $this->assertNotNull($this->assert->waitForElement('css', "$password_parent_selector.password-parent"));
    $this->assertTrue($password_parent_item->hasClass('password-parent'));
    $this->assertNotNull($this->assert->waitForElement('css', "$password_confirm_selector.confirm-parent"));
    $this->assertTrue($password_confirm_item->hasClass('confirm-parent'));

    // Check the elements of the main password item.     $this->assertTrue($password_parent_item->has('css', 'input.js-password-field'));

    // Strength meter and bar.     $this->assertTrue($password_parent_item->has('css', 'input.js-password-field + .password-strength > [data-drupal-selector="password-strength-meter"]:first-child [data-drupal-selector="password-strength-indicator"]'));

    // Password strength feedback. No strength text feedback present without     // input.
Home | Imprint | This part of the site doesn't use cookies.