Example #1
0
 function test_prefixNodeAttr()
 {
     $doc = phpQuery::newDocument('<img src="img0.jpg" srcset="img1.jpg 1000w, img2.jpg" href="link.html"/>');
     $img = phpQuery::pq('img', $doc)->elements[0];
     $img = HtmlUtils::prefixNodeAttr($img, 'src', 'p1/');
     $img = HtmlUtils::prefixNodeAttr($img, 'srcset', 'p2/');
     $img = HtmlUtils::prefixNodeAttr($img, 'href', 'p3/');
     $this->assertEquals('p1/img0.jpg', $img->getAttribute('src'));
     $this->assertEquals('p2/img1.jpg 1000w, p2/img2.jpg', $img->getAttribute('srcset'));
     $this->assertEquals('p3/link.html', $img->getAttribute('href'));
     $doc = phpQuery::newDocument('<img src="img0.jpg" srcset="img1.jpg 1000w, img2.jpg" href="link.html"/>');
     $img = phpQuery::pq('img', $doc)->elements[0];
     $test = function ($val) {
         return $val === 'img0.jpg' || $val === 'img2.jpg';
     };
     $img = HtmlUtils::prefixNodeAttr($img, 'src', 'p1/', $test);
     $img = HtmlUtils::prefixNodeAttr($img, 'srcset', 'p2/', $test);
     $img = HtmlUtils::prefixNodeAttr($img, 'href', 'p3/', $test);
     $this->assertEquals('p1/img0.jpg', $img->getAttribute('src'));
     $this->assertEquals('img1.jpg 1000w, p2/img2.jpg', $img->getAttribute('srcset'));
     $this->assertEquals('link.html', $img->getAttribute('href'));
 }