addDocument example


    public function addHtmlContent(string $content, string $charset = 'UTF-8')
    {
        $dom = $this->parseHtmlString($content$charset);
        $this->addDocument($dom);

        $base = $this->filterRelativeXPath('descendant-or-self::base')->extract(['href']);

        $baseHref = current($base);
        if (\count($base) && !empty($baseHref)) {
            if ($this->baseHref) {
                $linkNode = $dom->createElement('a');
                $linkNode->setAttribute('href', $baseHref);
                $link = new Link($linkNode$this->baseHref);
                $this->baseHref = $link->getUri();
            } else {
                
$filenameIdMap[$filename] = $document['id'];
            }
        }

        foreach ($mail->getParts() as $part) {
            if (isset($filenameIdMap[$part->filename])) {
                $document = $this->entityManager->getPartialReference(
                    Document::class,
                    $filenameIdMap[$part->filename]
                );
                if ($document instanceof Document) {
                    $logEntry->addDocument($document);
                }
            }
        }
    }

    protected function getDocumentFilename(array $document): ?string
    {
        if (!isset($document['type']['name'])) {
            return null;
        }

        

    public function testAddContentNonUtf8()
    {
        $crawler = $this->createCrawler();
        $crawler->addContent(iconv('UTF-8', 'SJIS', $this->getDoctype().'<html><head><meta charset="Shift_JIS"></head><body>日本語</body></html>'));
        $this->assertEquals('日本語', $crawler->filterXPath('//body')->text(), '->addContent() can recognize "Shift_JIS" in html5 meta charset tag');
    }

    public function testAddDocument()
    {
        $crawler = $this->createCrawler();
        $crawler->addDocument($this->createDomDocument());

        $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->addDocument() adds nodes from a \DOMDocument');
    }

    public function testAddNodeList()
    {
        $crawler = $this->createCrawler();
        $crawler->addNodeList($this->createNodeList());

        $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->addNodeList() adds nodes from a \DOMNodeList');
    }

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