[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/t/lib/ -> testcase.php (source)

   1  <?php
   2  require_once dirname( __FILE__ ) . '/../../gp-includes/backpress/class.bp-sql-schema-parser.php';
   3  require_once dirname( __FILE__ ) . '/../../gp-includes/schema.php';
   4  require_once dirname( __FILE__ ) . '/../../gp-includes/install-upgrade.php';
   5  
   6  require_once dirname( __FILE__ ) . '/factory.php';
   7  
   8  class GP_UnitTestCase extends PHPUnit_Framework_TestCase {
   9  
  10      protected $backupGlobalsBlacklist = array( 'gpdb' );
  11  
  12      var $url = 'http://example.org/';
  13  
  14  	function setUp() {
  15          global $gpdb;
  16          $gpdb->suppress_errors = false;
  17          $gpdb->show_errors = false;
  18  
  19          if ( defined( 'GP_DEBUG' ) && GP_DEBUG ) {
  20              if ( defined( 'E_DEPRECATED' ) )
  21                  error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
  22              else
  23                  error_reporting( E_ALL );
  24          }
  25  
  26          ini_set('display_errors', 1);
  27  
  28          if ( !gp_const_get( 'GP_IS_TEST_DB_INSTALLED' ) ) {
  29              $gpdb->query( 'DROP DATABASE '.GPDB_NAME.";" );
  30              $gpdb->query( 'CREATE DATABASE '.GPDB_NAME.";" );
  31              $gpdb->select( GPDB_NAME, $gpdb->dbh );
  32              $gpdb->query( 'SET storage_engine = INNODB;' );
  33              $errors = gp_install();
  34              if ( $errors ) {
  35                  gp_error_log_dump($errors);
  36                  die();
  37              }
  38              define( 'GP_IS_TEST_DB_INSTALLED', true );
  39          }
  40          $this->factory = new GP_UnitTest_Factory;
  41          $this->clean_up_global_scope();
  42          $this->start_transaction();
  43          ini_set( 'display_errors', 1 );
  44          $this->url_filter = returner( $this->url );
  45          add_filter( 'gp_get_option_uri', $this->url_filter );
  46      }
  47  
  48  	function tearDown() {
  49          global $gpdb;
  50          $gpdb->query( 'ROLLBACK' );
  51          remove_filter( 'gp_get_option_uri', $this->url_filter );
  52      }
  53  
  54  	function clean_up_global_scope() {
  55          GP::$user->reintialize_wp_users_object();
  56          wp_cache_flush();
  57          $locales = &GP_Locales::instance();
  58          $locales->locales = array();
  59          $_GET = array();
  60          $_POST = array();
  61          /**
  62           * @todo re-initialize all thing objects
  63           */
  64          GP::$translation_set = new GP_Translation_Set;
  65          GP::$original = new GP_Original;
  66      }
  67  
  68  	function start_transaction() {
  69          global $gpdb;
  70          $gpdb->query( 'SET autocommit = 0;' );
  71          $gpdb->query( 'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;' );
  72          $gpdb->query( 'START TRANSACTION;' );
  73      }
  74  
  75  	function temp_filename() {
  76          $tmp_dir = '';
  77          $dirs = array( 'TMP', 'TMPDIR', 'TEMP' );
  78          foreach( $dirs as $dir )
  79              if ( isset( $_ENV[$dir] ) && !empty( $_ENV[$dir] ) ) {
  80                  $tmp_dir = $dir;
  81                  break;
  82              }
  83          if (empty($dir)) $dir = '/tmp';
  84          $dir = realpath( $dir );
  85          return tempnam( $dir, 'testpomo' );
  86      }
  87  
  88  	function set_normal_user_as_current() {
  89          $user = $this->factory->user->create();
  90          $user->set_as_current();
  91          return $user;
  92      }
  93  
  94  	function set_admin_user_as_current() {
  95          $admin = $this->factory->user->create_admin();
  96          $admin->set_as_current();
  97          return $admin;
  98      }
  99  
 100  	function assertWPError( $actual, $message = '' ) {
 101          $this->assertTrue( is_wp_error( $actual ), $message );
 102      }
 103  
 104  	function assertEqualFields( $object, $fields ) {
 105          foreach( $fields as $field_name => $field_value ) {
 106              if ( $object->$field_name != $field_value ) {
 107                  $this->fail();
 108              }
 109          }
 110      }
 111  
 112  	function assertDiscardWhitespace( $expected, $actual ) {
 113          $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ) );
 114      }
 115  }


Generated: Thu May 23 03:59:56 2013 Hosted by follow the white rabbit.