[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZTestI18NTransformations class 4 // 5 // Created on: <22-Nov-2004 13:48:38 jb> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file eztesti18ntransformations.php 30 */ 31 32 /*! 33 \class eZTestI18NTransformations eztesti18ntransformations.php 34 \brief The class eZTestI18NTransformations does 35 36 */ 37 38 class eZTestI18NTransformations extends eZTestCase 39 { 40 /*! 41 Constructor 42 */ 43 function eZTestI18NTransformations( $name = false ) 44 { 45 $this->eZTestCase( $name ); 46 include_once ( 'lib/ezi18n/classes/ezchartransform.php' ); 47 48 $charsets = array( 'latin1' ); 49 50 foreach ( $charsets as $charset ) 51 { 52 foreach ( glob( 'tests/ezi18n/trans/latin1/*.src' ) as $file ) 53 { 54 $name = str_replace( 'tests/ezi18n/trans/' . $charset . '/', '', $file ); 55 $name = str_replace( '.src', '', $name ); 56 $name = ucwords( $charset ) . '-' . ucwords( $name ); 57 $this->addTest( 'testTransformation', $name, array( 'file' => $file, 58 'charset' => $charset ) ); 59 } 60 } 61 } 62 63 /*! 64 */ 65 function testTransformation( &$tr, $params ) 66 { 67 $file = $params['file']; 68 $charset = $params['charset']; 69 70 if ( !file_exists( $file ) ) 71 { 72 $tr->assert( false, 'Missing source test file ' . $file ); 73 return; 74 } 75 76 $expectedFileName = str_replace( '.src', '.exp', $file ); 77 if ( !file_exists( $file ) ) 78 { 79 $tr->assert( false, 'Missing expected test file ' . $file ); 80 return; 81 } 82 83 $source = file_get_contents( $file ); 84 $expected = file_get_contents( $expectedFileName ); 85 86 if ( !preg_match( "#^((g:([a-zA-Z0-9_-]+))|(r:([a-zA-Z0-9_,-]+)))#", $source, $matches ) ) 87 { 88 $tr->assert( false, 'No group or rule defined in transformation file ' . $file ); 89 return; 90 } 91 $pos = strpos( $source, "\n" ); 92 if ( $pos !== false ) 93 $source = substr( $source, $pos + 1 ); 94 95 $ct =& eZCharTransform::instance(); 96 if ( isset( $matches[2] ) ) 97 { 98 $group = $matches[3]; 99 $actual = $ct->transformByGroup( $source, $group, $charset ); 100 } 101 else if ( isset( $matches[4] ) ) 102 { 103 $rules = explode( ',', $matches[5] ); 104 $actual = $ct->transform( $source, $rules, $charset ); 105 } 106 107 $actualFileName = str_replace( '.src', '.out', $file ); 108 $fp = fopen( $actualFileName, 'w' ); 109 fwrite( $fp, $actual ); 110 fclose( $fp ); 111 112 $tr->assert( strcmp( $actual, $expected ) == 0, 'String compare of transformed text' ); 113 } 114 115 } 116 117 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |