[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tests/classes/ -> eztestcase.php (source)

   1  <?php
   2  //
   3  // Definition of eZTestCase class
   4  //
   5  // Created on: <30-Jan-2004 08:44:55 >
   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 eztestcase.php
  30  */
  31  
  32  /*!
  33    \class eZTestCase eztestcase.php
  34    \ingroup eZTest
  35    \brief eZTestCase provides a base class for doing automated test cases
  36  
  37    eZTestCase inherits from eZTestUnit and can be used in all
  38    test suites and test runners. It provides an easy way of registering
  39    test method using addTest().
  40  
  41    To create a test case inherit this class and create some test methods
  42    that takes one parameter \a $tr which is the current test runner.
  43    The constructor must call the eZTestCase constructor with a useful
  44    name and setup some test methods with addTest().
  45  
  46    For running the tests you must pass the case to an eZTestRunner instance
  47    or add it to a eZTestSuite object.
  48  
  49    \code
  50  include_once( 'tests/classes/eztestcase.php' );
  51  class MyTest extends eZTest
  52  {
  53      function MyTest()
  54      {
  55          $this->eZTest( 'My test case' );
  56          $this->addTest( 'testFunctionA', 'Addition test' );
  57          $this->addFunctionTest( 'MyFunctionTest', 'Addition test 2' );
  58      }
  59  
  60      function testFunctionA( &$tr )
  61      {
  62          $tr->assertEquals( 2 + 2, 4, '2+2 equals 4' );
  63      }
  64  }
  65  
  66  function MyFunctionTest( &$tr )
  67  {
  68      $tr->assertEquals( 2 + 2, 4, '2+2 equals 4' );
  69  }
  70  
  71  $case = new MyTest();
  72  $runner = new eZCLITestRunner();
  73  $runner->run( $case );
  74    \endcode
  75  
  76  */
  77  
  78  include_once ( 'lib/ezutils/classes/ezdebug.php' );
  79  include_once ( 'tests/classes/eztestunit.php' );
  80  
  81  class eZTestCase extends eZTestUnit
  82  {
  83      /*!
  84       Initializes the case with the name \a $name which passed to eZTestUnit::eZTestUnit.
  85      */
  86      function eZTestCase( $name = false )
  87      {
  88          $this->eZTestUnit( $name );
  89      }
  90  
  91      /*!
  92       Adds a new test method \a $method. If \a $name is empty the method name is used as name.
  93       \note If the method does not exist a warning is issued and the test will not be added the case.
  94      */
  95      function addTest( $method, $name = false, $parameter = false )
  96      {
  97          if ( !method_exists( $this, $method ) )
  98          {
  99              eZDebug::writeWarning( "Test method $method in test " . $this->Name . " does not exist, cannot add",
 100                                     'eZTestCase::addTest' );
 101          }
 102          if ( !$name )
 103              $name = $method;
 104          $this->addTestEntry( array( 'name' => $name,
 105                                      'object' => &$this,
 106                                      'method' => $method,
 107                                      'parameter' => $parameter) );
 108      }
 109  
 110      /*!
 111       Adds a new test function \a $function. If \a $name is empty the function name is used as name.
 112       \note If the function does not exist a warning is issued and the test will not be added the unit.
 113      */
 114      function addFunctionTest( $function, $name = false, $parameter = false )
 115      {
 116          if ( !function_exists( $function ) )
 117          {
 118              eZDebug::writeWarning( "Test function $functuion in test " . $this->Name . " does not exist, cannot add",
 119                                     'eZTestCase::addFunctionTest' );
 120          }
 121          if ( !$name )
 122              $name = $function;
 123          $this->addTestEntry( array( 'name' => $name,
 124                                      'function' => $function,
 125                                      'parameter' => $parameter ) );
 126      }
 127  }
 128  
 129  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7