Source for file utf8_validation.test.php

Documentation is available at utf8_validation.test.php

  1. <?php
  2. /**
  3. @version $Id: utf8_validation.test.php,v 1.1 2007/09/09 20:39:50 pitlinz Exp $
  4. @package utf8
  5. @subpackage Tests
  6. */
  7.  
  8. //--------------------------------------------------------------------
  9. /**
  10. * Includes
  11. @package utf8
  12. @subpackage Tests
  13. */
  14. require_once(dirname(__FILE__).'/../config.php');
  15. require_once UTF8 '/utils/validation.php';
  16.  
  17. //--------------------------------------------------------------------
  18. /**
  19. @package utf8
  20. @subpackage Tests
  21. */
  22. class test_utf8_is_valid extends UnitTestCase {
  23.  
  24.     function test_utf8_is_valid({
  25.         $this->UnitTestCase('utf8_is_valid()');
  26.     }
  27.     
  28.     function testValidUtf8({
  29.         $str 'Iñtërnâtiônàlizætiøn';
  30.         $this->assertTrue(utf8_is_valid($str));
  31.     }
  32.     
  33.     function testValidUtf8Ascii({
  34.         $str 'ABC 123';
  35.         $this->assertTrue(utf8_is_valid($str));
  36.     }
  37.     
  38.     function testInvalidUtf8({
  39.         $str "Iñtërnâtiôn\xe9àlizætiøn";
  40.         $this->assertFalse(utf8_is_valid($str));
  41.     }
  42.     
  43.     function testInvalidUtf8Ascii({
  44.         $str "this is an invalid char '\xe9' here";
  45.         $this->assertFalse(utf8_is_valid($str));
  46.     }
  47.     
  48.     function testEmptyString({
  49.         $str '';
  50.         $this->assertTrue(utf8_is_valid($str));
  51.     }
  52.     
  53.     function testValidTwoOctetId({
  54.         $str "\xc3\xb1";
  55.         $this->assertTrue(utf8_is_valid($str));
  56.     }
  57.     
  58.     function testInvalidTwoOctetSequence({
  59.         $str "Iñtërnâtiônàlizætiøn \xc3\x28 Iñtërnâtiônàlizætiøn";
  60.         $this->assertFalse(utf8_is_valid($str));
  61.     }
  62.     
  63.     function testInvalidIdBetweenTwoAndThree({
  64.         $str "Iñtërnâtiônàlizætiøn\xa0\xa1Iñtërnâtiônàlizætiøn";
  65.         $this->assertFalse(utf8_is_valid($str));
  66.     }
  67.     
  68.     function testValidThreeOctetId({
  69.         $str "Iñtërnâtiônàlizætiøn\xe2\x82\xa1Iñtërnâtiônàlizætiøn";
  70.         $this->assertTrue(utf8_is_valid($str));
  71.     }
  72.     
  73.         $str "Iñtërnâtiônàlizætiøn\xe2\x28\xa1Iñtërnâtiônàlizætiøn";
  74.         $this->assertFalse(utf8_is_valid($str));
  75.     }
  76.     
  77.     function testInvalidThreeOctetSequenceThird({
  78.         $str "Iñtërnâtiônàlizætiøn\xe2\x82\x28Iñtërnâtiônàlizætiøn";
  79.         $this->assertFalse(utf8_is_valid($str));
  80.     }
  81.     
  82.     function testValidFourOctetId({
  83.         $str "Iñtërnâtiônàlizætiøn\xf0\x90\x8c\xbcIñtërnâtiônàlizætiøn";
  84.         $this->assertTrue(utf8_is_valid($str));
  85.     }
  86.     
  87.     function testInvalidFourOctetSequence({
  88.         $str "Iñtërnâtiônàlizætiøn\xf0\x28\x8c\xbcIñtërnâtiônàlizætiøn";
  89.         $this->assertFalse(utf8_is_valid($str));
  90.     }
  91.     
  92.     function testInvalidFiveOctetSequence({
  93.         $str "Iñtërnâtiônàlizætiøn\xf8\xa1\xa1\xa1\xa1Iñtërnâtiônàlizætiøn";
  94.         $this->assertFalse(utf8_is_valid($str));
  95.     }
  96.     
  97.     function testInvalidSixOctetSequence({
  98.         $str "Iñtërnâtiônàlizætiøn\xfc\xa1\xa1\xa1\xa1\xa1Iñtërnâtiônàlizætiøn";
  99.         $this->assertFalse(utf8_is_valid($str));
  100.     }
  101.     
  102. }
  103.  
  104. //--------------------------------------------------------------------
  105. /**
  106. @package utf8
  107. @subpackage Tests
  108. */
  109. class test_utf8_compliant extends UnitTestCase {
  110.  
  111.     function test_utf8_compliant({
  112.         $this->UnitTestCase('utf8_compliant()');
  113.     }
  114.     
  115.     function testValidUtf8({
  116.         $str 'Iñtërnâtiônàlizætiøn';
  117.         $this->assertTrue(utf8_compliant($str));
  118.     }
  119.     
  120.     function testValidUtf8Ascii({
  121.         $str 'ABC 123';
  122.         $this->assertTrue(utf8_compliant($str));
  123.     }
  124.     
  125.     function testInvalidUtf8({
  126.         $str "Iñtërnâtiôn\xe9àlizætiøn";
  127.         $this->assertFalse(utf8_compliant($str));
  128.     }
  129.     
  130.     function testInvalidUtf8Ascii({
  131.         $str "this is an invalid char '\xe9' here";
  132.         $this->assertFalse(utf8_compliant($str));
  133.     }
  134.     
  135.     function testEmptyString({
  136.         $str '';
  137.         $this->assertTrue(utf8_compliant($str));
  138.     }
  139.     
  140.     function testValidTwoOctetId({
  141.         $str "\xc3\xb1";
  142.         $this->assertTrue(utf8_compliant($str));
  143.     }
  144.     
  145.     function testInvalidTwoOctetSequence({
  146.         $str "Iñtërnâtiônàlizætiøn \xc3\x28 Iñtërnâtiônàlizætiøn";
  147.         $this->assertFalse(utf8_compliant($str));
  148.     }
  149.     
  150.     function testInvalidIdBetweenTwoAndThree({
  151.         $str "Iñtërnâtiônàlizætiøn\xa0\xa1Iñtërnâtiônàlizætiøn";
  152.         $this->assertFalse(utf8_compliant($str));
  153.     }
  154.     
  155.     function testValidThreeOctetId({
  156.         $str "Iñtërnâtiônàlizætiøn\xe2\x82\xa1Iñtërnâtiônàlizætiøn";
  157.         $this->assertTrue(utf8_compliant($str));
  158.     }
  159.     
  160.         $str "Iñtërnâtiônàlizætiøn\xe2\x28\xa1Iñtërnâtiônàlizætiøn";
  161.         $this->assertFalse(utf8_compliant($str));
  162.     }
  163.     
  164.     function testInvalidThreeOctetSequenceThird({
  165.         $str "Iñtërnâtiônàlizætiøn\xe2\x82\x28Iñtërnâtiônàlizætiøn";
  166.         $this->assertFalse(utf8_compliant($str));
  167.     }
  168.     
  169.     function testValidFourOctetId({
  170.         $str "Iñtërnâtiônàlizætiøn\xf0\x90\x8c\xbcIñtërnâtiônàlizætiøn";
  171.         $this->assertTrue(utf8_compliant($str));
  172.     }
  173.     
  174.     function testInvalidFourOctetSequence({
  175.         $str "Iñtërnâtiônàlizætiøn\xf0\x28\x8c\xbcIñtërnâtiônàlizætiøn";
  176.         $this->assertFalse(utf8_compliant($str));
  177.     }
  178.     
  179.     function testInvalidFiveOctetSequence({
  180.         $str "Iñtërnâtiônàlizætiøn\xf8\xa1\xa1\xa1\xa1Iñtërnâtiônàlizætiøn";
  181.         $this->assertTrue(utf8_compliant($str));
  182.     }
  183.     
  184.     function testInvalidSixOctetSequence({
  185.         $str "Iñtërnâtiônàlizætiøn\xfc\xa1\xa1\xa1\xa1\xa1Iñtërnâtiônàlizætiøn";
  186.         $this->assertTrue(utf8_compliant($str));
  187.     }
  188.     
  189. }
  190.  
  191. //--------------------------------------------------------------------
  192. /**
  193. @package utf8
  194. @subpackage Tests
  195. */
  196. if (!defined('TEST_RUNNING')) {
  197.     define('TEST_RUNNING'true);
  198.     $test &new GroupTest('utf8_validation');
  199.     $test->addTestCase(new test_utf8_is_valid());
  200.     $test->addTestCase(new test_utf8_compliant());
  201.     $reporter getTestReporter();
  202.     $test->run($reporter);
  203. }

Documentation generated on Thu, 08 Jan 2009 17:49:23 +0100 by phpDocumentor 1.4.0a2