[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/cases/inc/ -> html_hilight.test.php (source)

   1  <?php
   2  
   3  require_once  DOKU_INC.'inc/html.php';
   4  
   5  if ( !extension_loaded('runkit') &&
   6       !@dl('runkit.dll') &&
   7       !@dl('runkit.so' ) ){
   8      SimpleTestOptions::ignore('html_hilight_test');
   9      trigger_error('Skipping html_hilight_test - http://www.php.net/runkit required');
  10  }
  11  
  12  function html_hilight_test_unslash($string,$char="'"){
  13    $str= str_replace('\\'.$char,$char,$string);
  14    return $str;
  15  }
  16  
  17  class html_hilight_test extends UnitTestCase{
  18  
  19    function setup() {
  20      if ( function_exists('unslash') ) {
  21          runkit_function_rename('unslash','html_hilight_test_unslash_real');
  22      }
  23      runkit_function_rename('html_hilight_test_unslash','unslash');
  24    }
  25  
  26    function teardown() {
  27      runkit_function_rename('unslash','html_hilight_test_unslash');
  28      if ( function_exists('html_hilight_test_unslash_real') ) {
  29          runkit_function_rename('html_hilight_test_unslash_real','unslash');
  30      }
  31    }
  32  
  33    function testHighlightOneWord() {
  34      $html = 'Foo bar Foo';
  35      $this->assertPattern(
  36        '/Foo <span.*>bar<\/span> Foo/',
  37        html_hilight($html,'bar')
  38        );
  39    }
  40  
  41    function testHighlightTwoWords() {
  42      $html = 'Foo bar Foo php Foo';
  43      $this->assertPattern(
  44        '/Foo <span.*>bar<\/span> Foo <span.*>php<\/span> Foo/',
  45        html_hilight($html,array('bar','php'))
  46        );
  47    }
  48  
  49    function testHighlightTwoWordsHtml() {
  50      $html = 'Foo <b>bar</b> <i>Foo</i> php Foo';
  51      $this->assertPattern(
  52        '/Foo <b><span.*>bar<\/span><\/b> <i>Foo<\/i> <span.*>php<\/span> Foo/',
  53        html_hilight($html,array('bar','php'))
  54        );
  55    }
  56  
  57    function testNoHighlight() {
  58      $html = 'Foo bar Foo';
  59      $this->assertPattern(
  60        '/Foo bar Foo/',
  61        html_hilight($html,'php')
  62        );
  63    }
  64  
  65    function testHighlightPHP() {
  66      $html = 'Foo $_GET[\'bar\'] Foo';
  67      $this->assertEqual(
  68        'Foo <span class="search_hit">$_GET[\'bar\']</span> Foo',
  69        html_hilight($html,'$_GET[\'bar\']')
  70        );
  71    }
  72  
  73    function testMatchAttribute() {
  74      $html = 'Foo <b class="x">bar</b> Foo';
  75      $this->assertPattern(
  76        '/Foo <b class="x">bar<\/b> Foo/',
  77        html_hilight($html,'class="x"')
  78        );
  79    }
  80  
  81    function testMatchAttributeWord() {
  82      $html = 'Foo <b class="x">bar</b> Foo';
  83      $this->assertEqual(
  84        'Foo <b class="x">bar</b> Foo',
  85        html_hilight($html,'class="x">bar')
  86        );
  87    }
  88  
  89    function testRegexInjection() {
  90      $html = 'Foo bar Foo';
  91      $this->assertPattern(
  92        '/Foo bar Foo/',
  93        html_hilight($html,'*')
  94        );
  95    }
  96  
  97    function testRegexInjectionSlash() {
  98      $html = 'Foo bar Foo';
  99      $this->assertPattern(
 100        '/Foo bar Foo/',
 101        html_hilight($html,'x/')
 102        );
 103    }
 104  
 105  }
 106  


Generated: Wed Dec 3 01:30:02 2008 Cross-referenced by PHPXref 0.7