Advertisement
terorama

fb / testmods.php

Nov 5th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.04 KB | None | 0 0
  1. <?php
  2.  
  3. require 'fb.inc.php';
  4.  
  5.    $fb = fbManager::getInstance();  
  6.    $db = $fb->db;
  7.    
  8.    $fb->debug_mode=true;
  9.    $db->debug_mode=true;
  10.    
  11.    
  12.    if (!isset($_REQUEST['ajax'])) {
  13.       drawPage();
  14.       exit();
  15.    } else
  16.    {
  17.       $className = $_REQUEST['class4'];
  18.       $mtdName = $_REQUEST['mtdname4'];
  19.       $targs = $_REQUEST['targs4'];
  20.      
  21.      
  22.      
  23.       //$obj = call_user_func(array($className,'getInstance'));
  24.      
  25.       switch ($className) {
  26.          case 'fbManager': $obj=$fb;break;
  27.          case 'Baser':$obj=$db;break;
  28.       }
  29.      
  30.       $args = array_map('trim',explode('#ZZZ#',$targs));
  31.      
  32.       //-----------------------func to test method with debug
  33.       function dbt_call($obj, $mtdName, $args) {
  34.      
  35.          $res = call_user_func_array(array($obj, $mtdName), $args);
  36.          $testmes = call_user_func(array($obj,'deshow'));
  37.                  
  38.          $debug_info = '<pre>'.var_export(debug_backtrace(),true).'</pre>';
  39.          
  40.          $result = array();
  41.          $result['res']=$res;
  42.          $result['testmes']=$testmes;
  43.          $result['debug_info']=$debug_info;
  44.          
  45.          return $result;
  46.       }
  47.       //--------------------------------     
  48.       $result = dbt_call($obj, $mtdName, $args);
  49.       //--------------------------------
  50.      
  51.       echo $className.'<br/>'.$mtdName.'<br/>'.$targs.'<br/>';
  52.       echo str_repeat('-',30).'args<br/>';   
  53.       echo '<pre>'.print_r($args,true).'</pre>';
  54.       echo str_repeat('-',30).'result<br/>';
  55.      
  56.       if (!is_scalar($result['res'])) {
  57.          $result['res']= '<pre>'.print_r($result['res'],true).'</pre>';
  58.       }
  59.       echo $result['res'];
  60.       echo '<br/>'.str_repeat('-',30).'test mes<br/>';
  61.       echo $result['testmes'];
  62.       //echo $result['debug_info'];
  63.          
  64.    }
  65.    
  66.  //--------------------------------------------------------  
  67.    function drawMethods($obj) {
  68.    
  69.       $className = get_class($obj);
  70.      
  71.       $refl = new ReflectionClass($className);
  72.      
  73.       $methods = $refl->getMethods();
  74.      
  75.       echo '<form name="'.$className.'" >'.
  76.       '<table cellspacing="0" cellpadding="1" border="1" bordercolor="#888"><tr>'.
  77.       '<th>name</th><th>type</th><th>args</th><th></th><th></th></tr>';
  78.      
  79.       $i=0;
  80.       foreach ($methods as $method) {
  81.      
  82.          $args = $method->getParameters();
  83.          $inf=array();
  84.          foreach ($args as $arg) {
  85.             $inf[] = $arg->name.($arg->isOptional()?' optional':'');
  86.          }
  87.          
  88.          echo '<tr><td>'.$method->name.'</td><td>'.
  89.          ($method->isAbstract() ? 'abstract ':'').
  90.          ($method->isConstructor() ? 'constructor ':'').
  91.          ($method->isDestructor() ? 'destructor ':'').
  92.          ($method->isFinal() ? 'final ':'').
  93.          ($method->isPrivate() ? 'private ':'').
  94.          ($method->isProtected() ? 'protected ':'').
  95.          ($method->isPublic() ? 'public ':'').
  96.          ($method->isStatic() ? 'static ':'').
  97.          '</td><td>'.implode(', ',$inf).'</td>'.
  98.          '<td><input type="text" name="args'.$i.'"/></td>'.
  99.          '<td><input type="button" name="button'.$i.'" value="go" '.
  100.          'onclick="this.form.nam='.$i.';'.
  101.                   'sendtest(this.form);" /></td>'.
  102.          '</tr>';
  103.          
  104.          $i++;
  105.       }
  106.       echo '</table></form>';
  107.      
  108.    }
  109.  
  110. //------------------------------------------
  111. function drawPage() {
  112.    
  113.    global $fb;
  114.    global $db;
  115. ?>
  116.  
  117. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  118. <html xmlns="http://www.w3.org/1999/xhtml">
  119. <head>
  120.    <meta http-equiv="content-type" content="text/html; charset=windows-1251" />
  121.    <meta name="description" content="page for unit tests" />
  122.    
  123.    <title>page for unit tests</title>
  124.    
  125.    <script type="text/javascript" src="jquery.min.js"></script>
  126.    
  127.    <script type="text/javascript">
  128.    
  129.       function sendtest(el) {
  130.      
  131.          var tclass=el.name;
  132.          var targs = el.elements['args'+el.nam];
  133.          
  134.          var tbutton = el.elements['button'+el.nam];
  135.          var trow = tbutton.parentNode.parentNode;       
  136.          var tds = trow.childNodes;
  137.          var mtdName = tds[0].innerHTML;
  138.          
  139.          
  140.          //alert(mtdName);
  141.          //alert(targs.value);
  142.          
  143.          $('#content').empty();
  144.          
  145.          $.when (
  146.             $.get("<?php echo $_SERVER["PHP_SELF"];?>",
  147.               {ajax:'', class4: tclass, mtdname4: mtdName, targs4: targs.value}
  148.              
  149.               )
  150.          ).done(
  151.             function(inf) {
  152.                $('#content').html(inf);
  153.             }
  154.          )
  155.          
  156.       }
  157.       //--------------------------------------------
  158.       $(document).ready(function() {
  159.      
  160.          $('#ajaxstatus').ajaxStart(
  161.             function() {
  162.                $(this).html('Request started. Please wait...');
  163.             }
  164.          )
  165.          
  166.          $('#ajaxstatus').ajaxStop(
  167.             function() {
  168.                $(this).html('Request complete');
  169.             }
  170.          )
  171.       });
  172.      
  173.    </script>
  174.    
  175.    <style type="text/css">
  176.       #leftcol {
  177.          float:left;
  178.          width:50%;
  179.       }
  180.      
  181.       #rightcol {
  182.          position:absolute;
  183.          left:51%;
  184.          top:0;
  185.       }
  186.    </style>
  187. </head>
  188.  
  189. <body>
  190.  
  191. <div id="leftcol">
  192. <h3>Check fbManager methods</h3>
  193. <?php
  194.    drawMethods($fb);
  195. ?>
  196.  
  197. <h3>Check Baser methods</h3>
  198. <?php
  199.    drawMethods($db);
  200. ?>
  201. </div>
  202. <div id="rightcol">
  203.     <h1>check results</h1>
  204.    
  205.    <div id="ajaxstatus"></div>
  206.    <div id="content"></div>
  207. </div>
  208.  
  209.  
  210. </body>
  211. </html>
  212.  
  213. <?php
  214.  
  215. }
  216. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement