getDriver example

'en' => [
        'description' => '<p>Something in English.</p>',
      ],
    ];
    foreach ($node_links as $langcode => $link) {
      $expected[$langcode]['link'] = $link;
    }

    $this->drupalGet('test-feed-display-fields.xml');
    $this->assertSession()->statusCodeEquals(200);

    $items = $this->getSession()->getDriver()->find('//channel/item');
    // There should only be 3 items in the feed.     $this->assertCount(3, $items, "$link_style: 3 items in feed");

    // Don't rely on the sort order of the items in the feed. Instead, each     // item's title is the langcode for that item. Iterate over all the items,     // get the title text for each one, make sure we're expecting each langcode     // we find, and then assert that the rest of the content of that item is     // what we expect for the given langcode.     foreach ($items as $item) {
      $title_element = $item->findAll('xpath', 'title');
      $this->assertCount(1, $title_element, "$link_style: Missing title element");
      
$connection = $this->getContainer()->get(Connection::class);

        $connection = $this->getMockBuilder(Connection::class)
            ->setConstructorArgs([
                array_merge(
                    $connection->getParams(),
                    [
                        'url' => $_SERVER['DATABASE_URL'],
                        'dbname' => $connection->getDatabase(),
                    ]
                ),
                $connection->getDriver(),
                $connection->getConfiguration(),
            ])
            ->onlyMethods(['delete'])
            ->getMock();

        $connection->method('delete')->willThrowException(new Exception('test'));

        $successSpy = $this->callbackSpy();
        $errorSpy = $this->callbackSpy();

        $spy = $this->eventListenerCalledSpy(function DEntityDeleteEvent $event) use ($successSpy$errorSpy): void {
            

  protected function assertOrderInPage(array $items): void {
    $session = $this->getSession();
    $text = $session->getPage()->getHtml();
    $strings = [];
    foreach ($items as $item) {
      if (($pos = strpos($text$item)) === FALSE) {
        throw new ExpectationException("Cannot find '$item' in the page", $session->getDriver());
      }
      $strings[$pos] = $item;
    }
    ksort($strings);
    $ordered = implode(', ', array_map(function D$item) {
      return "'$item'";
    }$items));
    $this->assertSame($itemsarray_values($strings), "Found strings, ordered as: $ordered.");
  }

  /** * Tests book outline AJAX request. */
$this->assertContains($position_type['top', 'bottom'], 'Expected position type.');
    return (int) $this->getSession()->evaluateScript("document.querySelector('$css_selector').getBoundingClientRect().$position_type + window.pageYOffset");
  }

  /** * Moves mouse pointer to location of $selector. * * @param string $selector * CSS selector. */
  protected function movePointerTo($selector) {
    $driver_session = $this->getSession()->getDriver()->getWebDriverSession();
    $element = $driver_session->element('css selector', $selector);
    $driver_session->moveto(['element' => $element->getID()]);
  }

}
// GET a URL that was cached by Page Cache before, it should not be now.     $this->drupalGet('/respond-cacheable-response');
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
  }

  /** * Tests that HEAD requests are treated the same as GET requests. */
  public function testHead() {
    /** @var \GuzzleHttp\ClientInterface $client */
    $client = $this->getSession()->getDriver()->getClient()->getClient();

    // GET, then HEAD.     $url_a = $this->buildUrl('system-test/set-header', ['query' => ['name' => 'Foo', 'value' => 'bar']]);
    $response_body = $this->drupalGet($url_a);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
    $this->assertSession()->responseHeaderEquals('Foo', 'bar');
    $this->assertEquals('The following header was set: <em class="placeholder">Foo</em>: <em class="placeholder">bar</em>', $response_body);
    $response = $client->request('HEAD', $url_a);
    $this->assertEquals('HIT', $response->getHeaderLine('X-Drupal-Cache'), 'Page was cached.');
    $this->assertEquals('bar', $response->getHeaderLine('Foo'), 'Custom header was sent.');
    $this->assertEquals('', $response->getBody()->getContents());

    
// Test click a contextual link that uses ajax.     $this->drupalGet('user');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $current_page_string = 'NOT_RELOADED_IF_ON_PAGE';
    $this->getSession()->executeScript('document.body.appendChild(document.createTextNode("' . $current_page_string . '"));');

    // Move the pointer over the branding block so the contextual link appears     // as it would with a real user interaction. Otherwise clickContextualLink()     // does not open the dialog in a manner that is opener-aware, and it isn't     // possible to reliably test focus management.     $driver_session = $this->getSession()->getDriver()->getWebDriverSession();
    $element = $driver_session->element('css selector', '#block-branding');
    $driver_session->moveto(['element' => $element->getID()]);
    $this->clickContextualLink('#block-branding', 'Test Link with Ajax', FALSE);
    $this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '#drupal-modal'));
    $this->assertSession()->elementContains('css', '#drupal-modal', 'Everything is contextual!');
    $this->getSession()->executeScript('document.querySelector("#block-branding .trigger").addEventListener("focus", (e) => e.target.classList.add("i-am-focused"))');
    $this->getSession()->getPage()->pressButton('Close');
    $this->assertSession()->assertNoElementAfterWait('css', 'ui.dialog');

    // When the dialog is closed, the opening contextual link is now inside a     // collapsed container, so focus should be routed to the contextual link
{$item}', '{$to}') JS;

    $options = [
      'script' => $script,
      'args'   => [],
    ];

    $this->getSession()->getDriver()->getWebDriverSession()->execute($options);
    $this->sortableUpdate($item$from$to);
  }

  /** * Simulates a drag moving an element after its sibling in the same container. * * @param string $item * The HTML selector for the element to be moved. * @param string $target * The HTML selector for the sibling element. * @param string $from * The HTML selector for the element container. */
    // NOT ANYMORE yield the value we set.     $core_normalization = $this->container->get('serializer')->normalize($this->entity);
    $core_normalization['field_test'][0]['value'] = static::VALUE_OVERRIDDEN;
    $denormalized_entity = $this->container->get('serializer')->denormalize($core_normalization, EntityTest::class, 'json', []);
    $this->assertInstanceOf(EntityTest::class$denormalized_entity);
    $this->assertSame(static::VALUE_ORIGINAL, $denormalized_entity->field_test->value);

    // Asserts the expected JSON:API normalization.     // @todo Remove line below in favor of commented line in https://www.drupal.org/project/drupal/issues/2878463.     $url = Url::fromRoute('jsonapi.entity_test--entity_test.individual', ['entity' => $this->entity->uuid()]);
    // $url = $this->entity->toUrl('jsonapi');     $client = $this->getSession()->getDriver()->getClient()->getClient();
    $response = $client->request('GET', $url->setAbsolute(TRUE)->toString());
    $document = Json::decode((string) $response->getBody());
    $this->assertSame($expected_value_jsonapi_normalization$document['data']['attributes']['field_test']);

    // Asserts the expected JSON:API denormalization.     $request_options = [];
    $request_options[RequestOptions::BODY] = Json::encode([
      'data' => [
        'type' => 'entity_test--entity_test',
        'attributes' => [
          'field_test' => static::VALUE_OVERRIDDEN,
        ],
$this->assertSession()->responseContains($test_element);

    // Test that the feed icon exists for the term.     $this->drupalGet("taxonomy/term/{$term1->id()}");
    $this->assertSession()->linkByHrefExists("taxonomy/term/{$term1->id()}/feed");

    // Test that the feed page exists for the term.     $this->drupalGet("taxonomy/term/{$term1->id()}/feed");
    $assert = $this->assertSession();
    $assert->responseHeaderContains('Content-Type', 'application/rss+xml');
    // Ensure the RSS version is 2.0.     $rss_array = $this->getSession()->getDriver()->find('rss');
    $this->assertEquals('2.0', reset($rss_array)->getAttribute('version'));

    // Check that the "Exception value" is disabled by default.     $this->drupalGet('taxonomy/term/all/feed');
    $this->assertSession()->statusCodeEquals(404);
    // Set the exception value to 'all'.     $view = Views::getView('taxonomy_term');
    $arguments = $view->getDisplay()->getOption('arguments');
    $arguments['tid']['exception']['value'] = 'all';
    $view->getDisplay()->overrideOption('arguments', $arguments);
    $view->storage->save();
    
$this->insecureSessionName = $this->getSessionName();
    }
  }

  /** * Tests HTTPS sessions. */
  public function testHttpsSession() {
    $user = $this->drupalCreateUser(['access administration pages']);

    /** @var \Symfony\Component\BrowserKit\CookieJar $browser_kit_cookie_jar */
    $browser_kit_cookie_jar = $this->getSession()->getDriver()->getClient()->getCookieJar();

    // Test HTTPS session handling by submitting the login form through     // https.php, which creates a mock HTTPS request.     $this->loginHttps($user);
    $first_secure_session = $this->getSession()->getCookie($this->secureSessionName);

    // Test a second concurrent session.     $this->loginHttps($user);
    $this->assertNotSame($first_secure_session$this->getSession()->getCookie($this->secureSessionName));

    // Check secure cookie is set.

  protected function makeApiRequest($method, Url $url, array $request_options) {
    $this->refreshVariables();
    $request_options[RequestOptions::HTTP_ERRORS] = FALSE;
    $request_options[RequestOptions::ALLOW_REDIRECTS] = FALSE;
    $request_options = $this->decorateWithXdebugCookie($request_options);
    $client = $this->getSession()->getDriver()->getClient()->getClient();
    return $client->request($method$url->setAbsolute(TRUE)->toString()$request_options);
  }

  /** * Adds the Xdebug cookie to the request options. * * @param array $request_options * The request options. * * @return array * Request options updated with the Xdebug cookie if present. */
$i'></p>"); jQuery('.csrf$i').html(response); }, error: function() { jQuery('body').append('Nothing'); } }); EOT;
    }
    $this->getSession()->getDriver()->executeScript($script);
    $token0 = $this->assertSession()->waitForElement('css', '.csrf0')->getHtml();
    $token1 = $this->assertSession()->waitForElement('css', '.csrf1')->getHtml();
    $this->assertNotNull($token0);
    $this->assertNotNull($token1);
    $this->assertEquals($token0$token1);
  }

}
// 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);
    $this->assertSameSize($upload_files_node_creation$node->{$field_name}, 'Node was successfully saved with multiple files.');

    

  protected function assertOrder(array $items): void {
    $session = $this->getSession();
    $text = $session->getPage()->getHtml();
    $strings = [];
    foreach ($items as $item) {
      if (($pos = strpos($text$item)) === FALSE) {
        throw new ExpectationException("Cannot find '$item' in the page", $session->getDriver());
      }
      $strings[$pos] = $item;
    }
    ksort($strings);
    $this->assertSame($itemsarray_values($strings), "Strings found on the page but incorrectly ordered.");
  }

  /** * Tests nested draggable tables through keyboard. */
  public function testNestedDraggableTables() {
    
$cached_id = 'block:block=' . $cached_block->id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
    $cached_id_token = Crypt::hmacBase64($cached_id, Settings::getHashSalt() . $this->container->get('private_key')->get());
    // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()     // Check existence of the contextual link placeholders.     $this->assertSession()->responseContains('<div' . new Attribute(['data-contextual-id' => $id, 'data-contextual-token' => $id_token, 'data-drupal-ajax-container' => '']) . '></div>');
    $this->assertSession()->responseContains('<div' . new Attribute(['data-contextual-id' => $cached_id, 'data-contextual-token' => $cached_id_token, 'data-drupal-ajax-container' => '']) . '></div>');

    // Get server-rendered contextual links.     // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()     $post = ['ids[0]' => $id, 'ids[1]' => $cached_id, 'tokens[0]' => $id_token, 'tokens[1]' => $cached_id_token];
    $url = 'contextual/render?_format=json,destination=test-page';
    $this->getSession()->getDriver()->getClient()->request('POST', $url$post);
    $this->assertSession()->statusCodeEquals(200);
    $json = Json::decode($this->getSession()->getPage()->getContent());
    $this->assertSame('<ul class="contextual-links"><li><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '/delete">Remove block</a></li><li><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>', $json[$id]);
    $this->assertSame('<ul class="contextual-links"><li><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '">Configure block</a></li><li><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '/delete">Remove block</a></li><li><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>', $json[$cached_id]);
  }

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