getXpath example


  protected function markRowHandleForDragging(NodeElement $handle) {
    $class = self::DRAGGING_CSS_CLASS;
    $script = <<<JS document.evaluate("{$handle->getXpath()}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null) .singleNodeValue.classList.add('{$class}'); JS;

    $this->getSession()->executeScript($script);
    $has_class = $this->getSession()->getPage()->waitFor(1, function D) use ($handle$class) {
      return $handle->hasClass($class);
    });

    if (!$has_class) {
      throw new \Exception(sprintf('Dragging css class was not added on handle "%s".', $handle->getXpath()));
    }
  }
$this->assertEmpty($node->{$field_name}->target_id, 'Node was successfully saved without any files.');

    // Try to upload more files than allowed on revision.     $upload_files_node_revision = [$test_file$test_file$test_file$test_file];
    foreach ($upload_files_node_revision as $i => $file) {
      $edit['files[test_file_field_1_0][' . $i . ']'] = \Drupal::service('file_system')->realpath($test_file->getFileUri());
    }

    // @todo: Replace after https://www.drupal.org/project/drupal/issues/2917885     $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->fieldExists('files[test_file_field_1_0][]');
    $submit_xpath = $this->assertSession()->buttonExists('Save')->getXpath();
    $client = $this->getSession()->getDriver()->getClient();
    $form = $client->getCrawler()->filterXPath($submit_xpath)->form();
    $client->request($form->getMethod()$form->getUri()$form->getPhpValues()$edit);

    $node = $node_storage->loadUnchanged($nid);
    $this->assertCount($cardinality$node->{$field_name}, 'More files than allowed could not be saved to node.');

    $upload_files_node_creation = [$test_file$test_file];
    // Try to upload multiple files, but fewer than the maximum.     $nid = $this->uploadNodeFiles($upload_files_node_creation$field_name$type_name, TRUE, []);
    $node = $node_storage->loadUnchanged($nid);
    

  public function testCombinedErrorMessages() {
    $textfile = current($this->drupalGetTestFiles('text'));
    $this->assertFileExists($textfile->uri);

    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');

    // Can't use submitForm() for set nonexistent fields.     $this->drupalGet('file-test/save_upload_from_form_test');
    $client = $this->getSession()->getDriver()->getClient();
    $submit_xpath = $this->assertSession()->buttonExists('Submit')->getXpath();
    $form = $client->getCrawler()->filterXPath($submit_xpath)->form();
    $edit = [
      'is_image_file' => TRUE,
      'extensions' => 'jpeg',
    ];
    $edit += $form->getPhpValues();
    $files['files']['file_test_upload'][0] = $file_system->realpath($this->phpfile->uri);
    $files['files']['file_test_upload'][1] = $file_system->realpath($textfile->uri);
    $client->request($form->getMethod()$form->getUri()$edit$files);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains("Epic upload FAIL!");

    
$edit = [];
    // Create few files with non-typical extensions.     foreach (['file1.wtf', 'file2.wtf'] as $i => $file) {
      $file_path = $this->root . "/sites/default/files/simpletest/$file";
      file_put_contents($file_path, 'File with non-default extension.', FILE_APPEND | LOCK_EX);
      $edit["files[multi_file][$i]"] = $file_path;
    }

    // @todo: Replace after https://www.drupal.org/project/drupal/issues/2917885     $this->drupalGet("admin/appearance/settings/$theme");
    $submit_xpath = $this->assertSession()->buttonExists('Save configuration')->getXpath();
    $client = $this->getSession()->getDriver()->getClient();
    $form = $client->getCrawler()->filterXPath($submit_xpath)->form();
    $client->request($form->getMethod()$form->getUri()$form->getPhpValues()$edit);

    $page = $this->getSession()->getPage();
    $this->assertStringNotContainsString('Only files with the following extensions are allowed', $page->getContent());
    $this->assertStringContainsString('The configuration options have been saved.', $page->getContent());
    $this->assertStringContainsString('file1.wtf', $page->getContent());
    $this->assertStringContainsString('file2.wtf', $page->getContent());
  }

}

  private function checkNodeVisibilityInViewport(NodeElement $node$corner = FALSE) {
    $xpath = $node->getXpath();

    // Build the JavaScript to test if the complete element or a specific corner     // is in the viewport.     switch ($corner) {
      case 'topLeft':
        $test_javascript_function = <<<JS function t(r, lx, ly) { return ( r.top >= 0 && r.top <= ly && r.left >= 0 && r.left <= lx ) }
    $this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);
    $form_display->save();
    $this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);

    // Visit the node add page.     $this->drupalGet('node/add/page');
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $autocomplete_field = $assert_session->waitForElement('css', '[name="' . $field_name . '[0][target_id]"].ui-autocomplete-input');
    $autocomplete_field->setValue('Test');
    $this->getSession()->getDriver()->keyDown($autocomplete_field->getXpath(), ' ');
    $assert_session->waitOnAutocomplete();

    $results = $page->findAll('css', '.ui-autocomplete li');

    $this->assertCount(2, $results);
    $assert_session->pageTextContains('Test page');
    $assert_session->pageTextContains('Page test');

    // Now switch the autocomplete widget to the 'STARTS_WITH' match operator.     $display_repository->getFormDisplay('node', 'page')
      ->setComponent($field_name[
        
Home | Imprint | This part of the site doesn't use cookies.