Show
Ignore:
Timestamp:
05/09/06 19:21:16 (3 years ago)
Author:
stefan
Message:

Minor progress on tags:

  • implemented a "urlify_tag" function that currently just calls rawurlencode()
  • implemented unit tests for that function and added a few tests for the parse_tags function.
  • whitespace changes (replacing tabs for spaces).
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/plogger-with-tags/unittests/tag-tests.php

    r395 r400  
    22   require_once 'lib/phpunit/PHPUnit.php'; 
    33   require_once 'lib/phpunit/PHPUnit/GUI/HTML.php'; 
    4     
    54   require_once '../plog-tag-functions.php'; 
    65 
    76   function implode_with_key($assoc, $inglue = '=', $outglue = ' & ') 
    87   { 
    9            foreach ($assoc as $tk => $tv) { 
    10                 $return = (isset($return) ? $return . $outglue : '') . $tk . $inglue . $tv; 
    11            } 
    12            return $return; 
     8      foreach ($assoc as $tk => $tv) { 
     9         $return = (isset($return) ? $return . $outglue : '') . $tk . $inglue . $tv; 
     10      } 
     11      return $return; 
    1312   } 
    14              
     13 
    1514   class TagTests extends PHPUnit_TestCase { 
    16        function test_parse_tags() { 
     15      function test_parse_tags() { 
    1716         $stuff = array(); 
    18           
     17 
    1918         $stuff = parse_tags("one    two"); 
    2019         $res_content = "{ ".implode(", ", $stuff)." }"; 
     
    5352         $this->assertContains("ten", $stuff, "Could not find tag 'ten' in: ".$res_content); 
    5453         $this->assertEquals(count($stuff), 5, "parse_tags result contains too many elements: ".$res_content); 
    55           
    56          //More ideas: 
    57          // "text containing <html> symbols & ;" 
    58          // "text containing UTF characters áéÊðöß" 
    59        } 
     54 
     55         // text containing HTML symbols 
     56         $stuff = parse_tags("<html> & ;"); 
     57         $res_content = "{ ".implode(", ", $stuff)." }"; 
     58         $this->assertContains("<html>", $stuff, "Could not find tag '<html>' in: ".$res_content); 
     59         $this->assertContains("&", $stuff, "Could not find tag '&' in: ".$res_content); 
     60         $this->assertContains(";", $stuff, "Could not find tag ';' in: ".$res_content); 
     61         $this->assertEquals(count($stuff), 3, "parse_tags result contains too many elements: ".$res_content); 
     62 
     63         // text containing UTF symbols 
     64         $stuff = parse_tags("áé íó úÜ Êß ðö"); 
     65         $res_content = "{ ".implode(", ", $stuff)." }"; 
     66         $this->assertContains("áé", $stuff, "Could not find tag 'áé' in: ".$res_content ); 
     67         $this->assertContains("íó", $stuff, "Could not find tag 'íó' in: ".$res_content); 
     68         $this->assertContains("úÜ", $stuff, "Could not find tag 'úÜ' in: ".$res_content); 
     69         $this->assertContains("Êß", $stuff, "Could not find tag 'Êß' in: ".$res_content); 
     70         $this->assertContains("ðö", $stuff, "Could not find tag 'ðö' in: ".$res_content); 
     71         $this->assertEquals(count($stuff), 5, "parse_tags result contains too many elements: ".$res_content); 
     72      } 
     73 
     74      function test_urlify_tag() 
     75      { 
     76         $this->assertEquals("%3Chtml%3E",urlify_tag("<html>")); 
     77         $this->assertEquals("this%26that",urlify_tag("this&that")); 
     78         $this->assertEquals("this%20%26%20that",urlify_tag("this & that")); 
     79         $this->assertEquals("here%20%2F%20there",urlify_tag("here / there")); 
     80      } 
    6081   } 
    6182?>