ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

Functions
unit_tests_utilities.php File Reference

Go to the source code of this file.

## Functions
| find_html_content_in_file ($FilePath)
| get_function_entries ($Content)
| isalnum ($Letter)
| get_func_name ($Content, $Entry)
| get_func_start ($Content, $Entry)
| get_func_end ($Content, $Entry)
| get_function_bodies ($Content)
| count_lines ($Content)
| get_skip_files ()
| skip_file ($FilePath)

## Function Documentation

count_lines | ( |  | $Content | ) |

Function returns count of lines.

Parameters

  $Content | - Testing content.

Returns
  Lines count.

Author
  Dodonov A.A.

Definition at line 300 of file unit_tests_utilities.php.

{
$Content = str_replace( "\r" , "\n" , $Content );
$Content = str_replace( "\n\n" , "\n" , $Content );
$Content = explode( "\n" , $Content );
return( count( $Content ) );
}

find_html_content_in_file | ( |  | $FilePath | ) |

Testing html code presense in php file.

Parameters

  $FilePath | - Path to the file.

Returns
  Count of errors.

Author
  Dodonov A.A.

Definition at line 34 of file unit_tests_utilities.php.

{
$Errors = 0;
$FileContent = file( $FilePath );
$Patterns = array(
'<table' , '<a' , '<div' , '<span' , '<td' , '<tr' , '<li' , '<ul' , '<select' , '</a>' , '</div>' ,
'</span>' , '</select>' , '<script' , '<link' , '</ul>' , '</li>' , '<br>' , '<p>' , '<p ' , '<option'
);
for( $k = 0 ; $k < count( $FileContent ) ; $k++ )
{
for( $j = 0 ; $j < count( $Patterns ) ; $j++ )
{
if( strpos( $FileContent[ $k ] , $Patterns[ $j ] ) !== false )
{
$Errors++;
print( "<nobr>$FilePath($k)</nobr><br>" );
break;
}
}
}
return( $Errors );
}

get_func_end | ( |  | $Content,
|  |  | $Entry
| ) |  |

Function returns method body cursor.

Parameters

  $Content | - File content.
  $Entry | - Function start.

Returns
  Function body start cursor.

Author
  Dodonov A.A.

Definition at line 220 of file unit_tests_utilities.php.

{
if( $Entry === false )
{
return( false );
}
$Length = strlen( $Content );
$Counter = 1;
for( $i = $Entry + 1 ; $i < $Length ; $i++ )
{
$Counter = $Content[ $i ] == '{' ? $Counter + 1 : $Counter;
$Counter = $Content[ $i ] == '}' ? $Counter - 1 : $Counter;
if( $Counter === 0 )
{
return( $i );
}
}
return( false );
}

get_func_name | ( |  | $Content,
|  |  | $Entry
| ) |  |

Function returns method name.

Parameters

  $Content | - File content.
  $Entry | - Function start.

Returns
  Function name.

Author
  Dodonov A.A.

Definition at line 147 of file unit_tests_utilities.php.

{
$Length = strlen( $Content );
$FunctionName = false;
for( $i = $Entry + 8 ; $i < $Length ; $i++ )
{
if( $FunctionName === false && isalnum( $Content[ $i ] ) )
{
$FunctionName = $Content[ $i ];
continue;
}
elseif( $FunctionName !== false && isalnum( $Content[ $i ] ) )
{
$FunctionName .= $Content[ $i ];
continue;
}
elseif( $FunctionName !== false && isalnum( $Content[ $i ] ) === false )
{
return( $FunctionName );
}
}
return( false );
}

get_func_start | ( |  | $Content,
|  |  | $Entry
| ) |  |

Function returns method body cursor.

Parameters

  $Content | - File content.
  $Entry | - Function start.

Returns
  Function body start cursor.

Author
  Dodonov A.A.

Definition at line 193 of file unit_tests_utilities.php.

{
return( strpos( $Content , chr( 123 ) , $Entry ) );
}

get_function_bodies | ( |  | $Content | ) |

Function returns function bodies.

Parameters

  $Content | - File content.

Returns
  Function bodies.

Author
  Dodonov A.A.

Definition at line 262 of file unit_tests_utilities.php.

{
$Entries = get_function_entries( $Content );
$Bodies = array();
foreach( $Entries as $i => $Entry )
{
$FunctionName = get_func_name( $Content , $Entry );
$FunctionStart = get_func_start( $Content , $Entry );
$FunctionEnd = get_func_end( $Content , $FunctionStart );
if( $FunctionStart !== false && $FunctionEnd !== false )
{
$Bodies [ $FunctionName ] = substr( $Content , $FunctionStart , $FunctionEnd - $FunctionStart + 1 );
}
}
return( $Bodies );
}

get_function_entries | ( |  | $Content | ) |

Function returns function entries from the file.

Parameters

  $Content | - File content.

Returns
  Function starts cursors.

Author
  Dodonov A.A.

Definition at line 77 of file unit_tests_utilities.php.

{
$Start = 0;
$Entries = array();
for( ; $Start !== false ; )
{
$Start = strpos( $Content , 'function' , $Start );
if( $Start !== false )
{
$Entries [] = $Start;
$Start += 8;
}
}
return( $Entries );
}

get_skip_files | ( |  | ) |

Files to skip.

Returns
  Files to skip.

Author
  Dodonov A.A.

Definition at line 325 of file unit_tests_utilities.php.

{
return(
array(
'excel' , 'soap' , 'json.php' , 'xml_rpc' , 'jquery.layout.min.js' , 'jquery.jstree.js' ,
'jquery.media.js' , '.en.js' , '.ru.js' , 'jquery.tree.xml_nested.js' , 'jquery.tree.xml_flat.js' ,
'jquery.tree.themeroller.js' , 'jquery.tree.contextmenu.js' , 'sarissa.js' , 'jquery.jstree.js' ,
'jquery.corner.js' , '.min.js' , 'disable.text.select.js' , 'dropdown.block.js' , '/doc/en/html/' ,
'jquery.jqGrid.min.js' , 'grid.locale-' , 'jquery.colorbox' , 'swfupload.js' , 'jquery.cookie.js' ,
'packages/ckeditor/include/' , 'jquery.jstree.js' , 'jquery-1.7.1.min.js' , 'ui.datepicker-ru.js' ,
'file_input_view/include/plugins/' , 'jstree/include/js/' , 'paginator3000.js' , '/tmp/' )
);
}

isalnum | ( |  | $Letter | ) |

Is a letter of the function name.

Parameters

  $Letter | - Letter.

Returns
  true/false.

Author
  Dodonov A.A.

Definition at line 114 of file unit_tests_utilities.php.

{
if( ( $Letter >= 'a' && $Letter <= 'z' ) || ( $Letter >= 'A' && $Letter <= 'Z' ) ||
( $Letter >= '0' && $Letter <= '9' ) || $Letter == '_' )
{
return( true );
}
return( false );
}

skip_file | ( |  | $FilePath | ) |

Should the file be skipped.

Parameters

  $FilePath | - Path to the file.

Returns
  true/false.

Author
  Dodonov A.A.

Definition at line 357 of file unit_tests_utilities.php.

{
$Files = get_skip_files();
foreach( $Files as $k => $v )
{
if( strpos( $FilePath , $v ) !== false )
{
return( true );
}
}
return( false );
}