filterXPath example

// 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.');

    
public function testGetBaseHref()
    {
        $baseHref = 'http://symfony.com';
        $crawler = $this->createCrawler(null, null, $baseHref);
        $this->assertEquals($baseHref$crawler->getBaseHref());
    }

    public function testAdd()
    {
        $crawler = $this->createCrawler();
        $crawler->add($this->createDomDocument());
        $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->add() adds nodes from a \DOMDocument');

        $crawler = $this->createCrawler();
        $crawler->add($this->createNodeList());
        $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->add() adds nodes from a \DOMNodeList');

        $list = [];
        foreach ($this->createNodeList() as $node) {
            $list[] = $node;
        }
        $crawler = $this->createCrawler();
        $crawler->add($list);
        
// 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());
  }

}
$browser->request(
            'GET',
            '/checkout/offcanvas'
        );
        $response = $browser->getResponse();
        $contentReturn = $response->getContent();
        static::assertNotFalse($contentReturn);

        $crawler = new Crawler();
        $crawler->addHtmlContent($contentReturn);
        $errorContent = $crawler->filterXPath('//div[@class="alert-content"]')->text();
        foreach ($errorKeys as $errorKey) {
            static::assertStringContainsString($errorKey$errorContent);
        }
    }

    /** * @dataProvider errorDataProvider * * @param array<string> $errorKeys */
    public function testConfirmWithErrorsFlash(ErrorCollection $errors, array $errorKeys, bool $testSwitchToDefault = false, bool $orderShouldBeBlocked = false): void
    {


        $this->getContainer()->get('request_stack')->push($request);

        /** @var StorefrontResponse $response */
        $response = $controller->guestLoginPage($request$this->salesChannelContext);

        $contentReturn = $response->getContent();
        $crawler = new Crawler();
        $crawler->addHtmlContent((string) $contentReturn);

        $errorContent = $crawler->filterXPath('//div[@class="flashbags container"]//div[@class="alert-content"]')->text();

        static::assertStringContainsString($this->translator->trans('account.loginThrottled', ['%seconds%' => 5])$errorContent);
    }

    public function testAuthControllerLoginShowsRateLimit(): void
    {
        $loginRoute = $this->createMock(LoginRoute::class);
        $loginRoute->method('login')->willThrowException(CustomerException::customerAuthThrottledException(5));

        $controller = new AuthController(
            $this->getContainer()->get(AccountLoginPageLoader::class),
            
$this->browser = KernelLifecycleManager::createBrowser($this->getKernel());
    }

    public function testCookieGroupIncludeComfortFeatures(): void
    {
        $systemConfig = $this->getContainer()->get(SystemConfigService::class);

        $systemConfig->set('core.cart.wishlistEnabled', true);

        $response = $this->browser->request('GET', $_SERVER['APP_URL'] . '/cookie/offcanvas');

        static::assertCount(1, $response->filterXPath('//input[@id="cookie_Comfort features"]'));
        static::assertCount(1, $response->filterXPath('//input[@id="cookie_wishlist-enabled"]'));
        static::assertCount(1, $response->filterXPath('//input[@id="cookie_youtube-video"]'));
    }

    public function testCookieGroupNotIncludeWishlistInComfortFeatures(): void
    {
        $systemConfig = $this->getContainer()->get(SystemConfigService::class);

        $systemConfig->set('core.cart.wishlistEnabled', false);

        $response = $this->browser->request('GET', $_SERVER['APP_URL'] . '/cookie/offcanvas');

        

    public static function getDoctype(): string
    {
        return '<!DOCTYPE html>';
    }

    public function testAddHtml5()
    {
        // Ensure a bug specific to the DOM extension is fixed (see https://github.com/symfony/symfony/issues/28596)         $crawler = $this->createCrawler();
        $crawler->add($this->getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>');
        $this->assertEquals('Foo', $crawler->filterXPath('//h1')->text(), '->add() adds nodes from a string');
    }

    /** @dataProvider validHtml5Provider */
    public function testHtml5ParserParseContentStartingWithValidHeading(string $content)
    {
        $crawler = $this->createCrawler();
        $crawler->addHtmlContent($content);
        self::assertEquals(
            'Foo',
            $crawler->filterXPath('//h1')->text(),
            '->addHtmlContent() parses valid HTML with comment before doctype'
        );
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!");

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