[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/lib/simpletest/extensions/dom_tester/ -> dom_tester_test.php (source)

   1  <?php
   2  
   3  // $Id: dom_tester_test.php,v 1.3 2007/06/08 20:37:35 pp11 Exp $

   4  
   5  require_once(dirname(__FILE__) . '/../../autorun.php');
   6  require_once(dirname(__FILE__) . '/../dom_tester.php');
   7  
   8  class TestOfLiveCssSelectors extends DomTestCase {
   9      function setUp() {
  10          $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
  11      }
  12      
  13      function testGet() {
  14  //        $url = 'http://simpletest.org/live/extensions/dom_tester/dom_tester.html';

  15          $url = 'http://localhost/~perrick/simpletest/extensions/dom_tester/dom_tester.html';
  16          $this->assertTrue($this->get($url));
  17          $this->assertEqual($this->getUrl(), $url);
  18          $this->assertElementsBySelector('h1', array('Test page'));
  19          $this->assertElementsBySelector('ul#list li a[href]', array('link'));
  20          $this->assertElementsBySelector('body  h1', array('Test page'));
  21          $this->assertElementsBySelector('#mybar', array('myfoo bis'));
  22      }
  23  }
  24  
  25  class TestOfCssSelectors extends UnitTestCase {
  26  	function TestOfCssSelectors() {
  27          $html = file_get_contents(dirname(__FILE__) . '/dom_tester.html');
  28          $this->dom = new DomDocument('1.0', 'utf-8');
  29          $this->dom->validateOnParse = true;
  30          $this->dom->loadHTML($html);
  31      }
  32  
  33      function testBasicSelector() {
  34          $expectation = new CssSelectorExpectation($this->dom, 'h1');
  35          $this->assertTrue($expectation->test(array('Test page')));
  36  
  37          $expectation = new CssSelectorExpectation($this->dom, 'h2');
  38          $this->assertTrue($expectation->test(array('Title 1', 'Title 2')));
  39  
  40          $expectation = new CssSelectorExpectation($this->dom, '#footer');
  41          $this->assertTrue($expectation->test(array('footer')));
  42  
  43          $expectation = new CssSelectorExpectation($this->dom, 'div#footer');
  44          $this->assertTrue($expectation->test(array('footer')));
  45  
  46          $expectation = new CssSelectorExpectation($this->dom, '.header');
  47          $this->assertTrue($expectation->test(array('header')));
  48  
  49          $expectation = new CssSelectorExpectation($this->dom, 'p.header');
  50          $this->assertTrue($expectation->test(array('header')));
  51  
  52          $expectation = new CssSelectorExpectation($this->dom, 'div.header');
  53          $this->assertTrue($expectation->test(array()));
  54  
  55          $expectation = new CssSelectorExpectation($this->dom, 'ul#mylist ul li');
  56          $this->assertTrue($expectation->test(array('element 3', 'element 4')));
  57  
  58          $expectation = new CssSelectorExpectation($this->dom, '#nonexistant');
  59          $this->assertTrue($expectation->test(array()));
  60      }
  61      
  62      function testAttributeSelectors() {
  63          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[href]');
  64          $this->assertTrue($expectation->test(array('link')));
  65  
  66          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class~="foo1"]');
  67          $this->assertTrue($expectation->test(array('link')));
  68  
  69          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class~="bar1"]');
  70          $this->assertTrue($expectation->test(array('link')));
  71  
  72          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class~="foobar1"]');
  73          $this->assertTrue($expectation->test(array('link')));
  74  
  75          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class^="foo1"]');
  76          $this->assertTrue($expectation->test(array('link')));
  77  
  78          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class$="foobar1"]');
  79          $this->assertTrue($expectation->test(array('link')));
  80  
  81          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class*="oba"]');
  82          $this->assertTrue($expectation->test(array('link')));
  83  
  84          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[href="http://www.google.com/"]');
  85          $this->assertTrue($expectation->test(array('link')));
  86  
  87          $expectation = new CssSelectorExpectation($this->dom, 'ul#anotherlist li a[class|="bar1"]');
  88          $this->assertTrue($expectation->test(array('another link')));      
  89  
  90          $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class*="oba"][class*="ba"]');
  91          $this->assertTrue($expectation->test(array('link')));      
  92  
  93          $expectation = new CssSelectorExpectation($this->dom, 'p[class="myfoo"][id="mybar"]');
  94          $this->assertTrue($expectation->test(array('myfoo bis')));      
  95  
  96          $expectation = new CssSelectorExpectation($this->dom, 'p[onclick*="a . and a #"]');
  97          $this->assertTrue($expectation->test(array('works great')));      
  98      }
  99      
 100      function testCombinators() {
 101          $expectation = new CssSelectorExpectation($this->dom, 'body  h1');
 102          $this->assertTrue($expectation->test(array('Test page')));      
 103  
 104          $expectation = new CssSelectorExpectation($this->dom, 'div#combinators > ul  >   li');
 105          $this->assertTrue($expectation->test(array('test 1', 'test 2')));      
 106  
 107          $expectation = new CssSelectorExpectation($this->dom, 'div#combinators>ul>li');
 108          $this->assertTrue($expectation->test(array('test 1', 'test 2')));
 109          
 110          $expectation = new CssSelectorExpectation($this->dom, 'div#combinators li  +   li');
 111          $this->assertTrue($expectation->test(array('test 2', 'test 4')));
 112          
 113          $expectation = new CssSelectorExpectation($this->dom, 'div#combinators li+li');
 114          $this->assertTrue($expectation->test(array('test 2', 'test 4')));
 115  
 116          $expectation = new CssSelectorExpectation($this->dom, 'h1, h2');
 117          $this->assertTrue($expectation->test(array('Test page', 'Title 1', 'Title 2')));
 118  
 119          $expectation = new CssSelectorExpectation($this->dom, 'h1,h2');
 120          $this->assertTrue($expectation->test(array('Test page', 'Title 1', 'Title 2')));
 121  
 122          $expectation = new CssSelectorExpectation($this->dom, 'h1  ,   h2');
 123          $this->assertTrue($expectation->test(array('Test page', 'Title 1', 'Title 2')));
 124  
 125          $expectation = new CssSelectorExpectation($this->dom, 'h1, h1,h1');
 126          $this->assertTrue($expectation->test(array('Test page')));
 127  
 128          $expectation = new CssSelectorExpectation($this->dom, 'h1,h2,h1');
 129          $this->assertTrue($expectation->test(array('Test page', 'Title 1', 'Title 2')));
 130  
 131          $expectation = new CssSelectorExpectation($this->dom, 'p[onclick*="a . and a #"], div#combinators > ul > li + li');
 132          $this->assertTrue($expectation->test(array('works great', 'test 2')));
 133      }
 134  }
 135  
 136  class TestsOfChildAndAdjacentSelectors extends DomTestCase {
 137  	function TestsOfChildAndAdjacentSelectors() {
 138          $html = file_get_contents(dirname(__FILE__) . '/dom_tester_child_adjacent.html');
 139          $this->dom = new DomDocument('1.0', 'utf-8');
 140          $this->dom->validateOnParse = true;
 141          $this->dom->loadHTML($html);
 142      }
 143  
 144      function testFirstChild() {
 145          $expectation = new CssSelectorExpectation($this->dom, 'p:first-child');
 146          $this->assertTrue($expectation->test(array('First paragraph')));
 147  
 148          $expectation = new CssSelectorExpectation($this->dom, 'body > p:first-child');
 149          $this->assertTrue($expectation->test(array('First paragraph')));
 150  
 151          $expectation = new CssSelectorExpectation($this->dom, 'body > p > a:first-child');
 152          $this->assertTrue($expectation->test(array('paragraph')));
 153      }
 154  
 155      function testChildren() {
 156          $expectation = new CssSelectorExpectation($this->dom, 'body > p');
 157          $this->assertTrue($expectation->test(array('First paragraph', 'Second paragraph', 'Third paragraph')));
 158  
 159          $expectation = new CssSelectorExpectation($this->dom, 'body > p > a');
 160          $this->assertTrue($expectation->test(array('paragraph')));
 161      }
 162  
 163      function testAdjacents() {
 164          $expectation = new CssSelectorExpectation($this->dom, 'p + p');
 165          $this->assertTrue($expectation->test(array('Second paragraph', 'Third paragraph')));
 166  
 167          $expectation = new CssSelectorExpectation($this->dom, 'body > p + p');
 168          $this->assertTrue($expectation->test(array('Second paragraph', 'Third paragraph')));
 169  
 170          $expectation = new CssSelectorExpectation($this->dom, 'body > p + p > a');
 171          $this->assertTrue($expectation->test(array('paragraph')));
 172      }
 173  }
 174  
 175  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7