PHP Classes

File: XidelTest.php

Recommend this page to a friend!
  Classes of Alliaume Hugo   PHP Xidel   XidelTest.php   Download  
File: XidelTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PHP Xidel
Extract information from HTML using the Xidel tool
Author: By
Last change:
Date: 8 years ago
Size: 1,183 bytes
 

Contents

Class file image Download
<?php
require 'class.Xidel.php';

class
XidelTest extends PHPUnit_Framework_TestCase {

    private
$xidel = null;

    public function
__construct() {
       
$this->xidel = new Xidel('https://www.4chan.org/');
       
$this->xidel->setInputFormat(Xidel::INPUT_FORMAT_HTML);
       
$this->xidel->setOutputEncoding(Xidel::OUTPUT_ENCODING_UTF8);
       
$this->xidel->setOutputFormat(Xidel::OUTPUT_FORMAT_ADHOC);
    }

    public function
testLinkCSS() {
       
$this->xidel->setExtract('a[title="Home"]');
       
$content = $this->xidel->process();

       
$this->assertEquals("4chan", $content);
    }

    public function
testLinkXPath() {
       
$this->xidel->reset();
       
$this->xidel->setExtract('//a[@href="/contact"]', Xidel::EXTRACT_KIND_XPATH);
       
$content = $this->xidel->process();

       
$this->assertEquals("Contact", $content);
    }

    public function
testLinksXPath() {
       
$this->xidel->reset();
       
$this->xidel->setExtract('//*[@id="ft"]/ul/li/a', Xidel::EXTRACT_KIND_XPATH);
       
$content = $this->xidel->process();

       
$this->assertEquals(array("Home", "News", "Blog", "FAQ", "Rules", "Advertise", "Press"), $content);
    }
}