<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[GlotPress] [480] trunk/t:
  Wrap tests into a transaction and rollback it in the end.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>480</dd>
<dt>Author</dt> <dd>nbachiyski</dd>
<dt>Date</dt> <dd>2010-04-27 11:04:17 +0000 (Tue, 27 Apr 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Wrap tests into a transaction and rollback it in the end. This way we don't need to install GlotPress before each test. Sped up tests 10 times</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkttest_builtin_warningsphp">trunk/t/test_builtin_warnings.php</a></li>
<li><a href="#trunkttest_noop_translationsphp">trunk/t/test_noop_translations.php</a></li>
<li><a href="#trunkttest_thingphp">trunk/t/test_thing.php</a></li>
<li><a href="#trunkttest_urlsphp">trunk/t/test_urls.php</a></li>
<li><a href="#trunkttest_warningsphp">trunk/t/test_warnings.php</a></li>
<li><a href="#trunkttestcasephp">trunk/t/testcase.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkttest_builtin_warningsphp"></a>
<div class="modfile"><h4>Modified: trunk/t/test_builtin_warnings.php (479 => 480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/t/test_builtin_warnings.php        2010-04-23 22:30:00 UTC (rev 479)
+++ trunk/t/test_builtin_warnings.php        2010-04-27 11:04:17 UTC (rev 480)
</span><span class="lines">@@ -4,6 +4,7 @@
</span><span class="cx"> class GP_Test_Builtin_Translation_Warnings extends GP_UnitTestCase {
</span><span class="cx">         
</span><span class="cx">         function setUp() {
</span><ins>+                parent::setUp();
</ins><span class="cx">                 $this-&gt;w = new GP_Builtin_Translation_Warnings;
</span><span class="cx">                 $this-&gt;bg = GP_Locales::by_slug( 'bg' );
</span><span class="cx">                 $this-&gt;longer_than_20 = 'The little boy hid behind the counter and then came the wizard of all green wizards!';
</span></span></pre></div>
<a id="trunkttest_noop_translationsphp"></a>
<div class="modfile"><h4>Modified: trunk/t/test_noop_translations.php (479 => 480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/t/test_noop_translations.php        2010-04-23 22:30:00 UTC (rev 479)
+++ trunk/t/test_noop_translations.php        2010-04-27 11:04:17 UTC (rev 480)
</span><span class="lines">@@ -3,10 +3,10 @@
</span><span class="cx"> 
</span><span class="cx"> class GP_Test_NOOP_Translations extends GP_UnitTestCase {
</span><span class="cx">         function setUp() {
</span><ins>+                parent::setUp();
</ins><span class="cx">                 $this-&gt;noop = new NOOP_Translations;
</span><span class="cx">                 $this-&gt;entry = new Translation_Entry( array( 'singular' =&gt; 'baba' ) );
</span><span class="cx">                 $this-&gt;plural_entry = new Translation_Entry(array('singular' =&gt; 'dyado', 'plural' =&gt; 'dyados', 'translations' =&gt; array('dyadox', 'dyadoy')));
</span><del>-                parent::setUp();
</del><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         function test_get_header() {
</span></span></pre></div>
<a id="trunkttest_thingphp"></a>
<div class="modfile"><h4>Modified: trunk/t/test_thing.php (479 => 480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/t/test_thing.php        2010-04-23 22:30:00 UTC (rev 479)
+++ trunk/t/test_thing.php        2010-04-27 11:04:17 UTC (rev 480)
</span><span class="lines">@@ -11,6 +11,7 @@
</span><span class="cx"> class GP_Test_Thing extends GP_UnitTestCase {
</span><span class="cx">         
</span><span class="cx">         function setUp() {
</span><ins>+                parent::setUp();
</ins><span class="cx">                 $this-&gt;t = new GP_My_Table;
</span><span class="cx">         }
</span><span class="cx">         
</span></span></pre></div>
<a id="trunkttest_urlsphp"></a>
<div class="modfile"><h4>Modified: trunk/t/test_urls.php (479 => 480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/t/test_urls.php        2010-04-23 22:30:00 UTC (rev 479)
+++ trunk/t/test_urls.php        2010-04-27 11:04:17 UTC (rev 480)
</span><span class="lines">@@ -4,7 +4,7 @@
</span><span class="cx"> class GP_Test_Urls extends GP_UnitTestCase {
</span><span class="cx">         
</span><span class="cx">         function setUp() {
</span><del>-        parent::setUp();
</del><ins>+                parent::setUp();
</ins><span class="cx">                 $this-&gt;url = '/gp/';
</span><span class="cx">                 gp_update_option( 'uri', 'http://example.org'.$this-&gt;url );
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkttest_warningsphp"></a>
<div class="modfile"><h4>Modified: trunk/t/test_warnings.php (479 => 480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/t/test_warnings.php        2010-04-23 22:30:00 UTC (rev 479)
+++ trunk/t/test_warnings.php        2010-04-27 11:04:17 UTC (rev 480)
</span><span class="lines">@@ -3,6 +3,7 @@
</span><span class="cx"> 
</span><span class="cx"> class GP_Test_Translation_Warnings extends GP_UnitTestCase {
</span><span class="cx">         function setUp() {
</span><ins>+                parent::setUp();
</ins><span class="cx">                 $this-&gt;is_baba = create_function('$o, $t, $l', 'return $t == &quot;баба&quot;? true : &quot;error&quot;;');
</span><span class="cx">                 $this-&gt;is_equal = create_function('$o, $t, $l', 'return $t == $o? true : &quot;error&quot;;');
</span><span class="cx">                 $this-&gt;w = new GP_Translation_Warnings;
</span></span></pre></div>
<a id="trunkttestcasephp"></a>
<div class="modfile"><h4>Modified: trunk/t/testcase.php (479 => 480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/t/testcase.php        2010-04-23 22:30:00 UTC (rev 479)
+++ trunk/t/testcase.php        2010-04-27 11:04:17 UTC (rev 480)
</span><span class="lines">@@ -6,26 +6,50 @@
</span><span class="cx"> class GP_UnitTestCase extends PHPUnit_Framework_TestCase {
</span><span class="cx">     
</span><span class="cx">         function setUp() {
</span><del>-                global $gpdb;
-                error_reporting(E_ALL);
-                $gpdb-&gt;query(&quot;DROP DATABASE &quot;.GPDB_NAME.&quot;;&quot;);
-                $gpdb-&gt;query(&quot;CREATE DATABASE &quot;.GPDB_NAME.&quot;;&quot;);
-                $gpdb-&gt;select( GPDB_NAME, $gpdb-&gt;dbh );
-                gp_install();
</del><ins>+                global $gpdb, $wp_auth_object, $wp_users_object;
+                error_reporting( E_ALL );
+                ini_set('display_errors', 1);
+                if ( !gp_const_get( 'GP_IS_TEST_DB_INSTALLED' ) ) {
+                        $gpdb-&gt;query( 'DROP DATABASE '.GPDB_NAME.&quot;;&quot; );
+                        $gpdb-&gt;query( 'CREATE DATABASE '.GPDB_NAME.&quot;;&quot; );
+                        $gpdb-&gt;select( GPDB_NAME, $gpdb-&gt;dbh );
+                        add_filter( 'gp_schema_pre_charset', array( &amp;$this, 'force_innodb' ) );
+                        gp_install();
+                        define( 'GP_IS_TEST_DB_INSTALLED', true );
+                } else {
+                        // cleanup the global scope after previous tests
+                        $wp_users_object = new WP_Users( $gpdb );
+                        $wp_auth_object-&gt;users = $wp_users_object;
+                }
+                $gpdb-&gt;query( 'SET autocommit = 0;' );
+                $gpdb-&gt;query( 'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;' );
+                $gpdb-&gt;query( 'START TRANSACTION;' );
</ins><span class="cx">                 wp_cache_flush();
</span><del>-                ini_set('display_errors', 1);
</del><ins>+                ini_set( 'display_errors', 1 );
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+        function tearDown() {
+                global $gpdb;
+                $gpdb-&gt;query( 'ROLLBACK' );
+        }
+
+        function force_innodb( $schema ) {
+                foreach( $schema as &amp;$sql ) {
+                        $sql = str_replace( ');', ') TYPE=InnoDB;', $sql );
+                }
+                return $schema;
+        }
+
</ins><span class="cx">         function temp_filename() {
</span><span class="cx">                 $tmp_dir = '';
</span><del>-                $dirs = array('TMP', 'TMPDIR', 'TEMP');
-                foreach($dirs as $dir)
-                        if (isset($_ENV[$dir]) &amp;&amp; !empty($_ENV[$dir])) {
</del><ins>+                $dirs = array( 'TMP', 'TMPDIR', 'TEMP' );
+                foreach( $dirs as $dir )
+                        if ( isset( $_ENV[$dir] ) &amp;&amp; !empty( $_ENV[$dir] ) ) {
</ins><span class="cx">                                 $tmp_dir = $dir;
</span><span class="cx">                                 break;
</span><span class="cx">                         }
</span><span class="cx">                 if (empty($dir)) $dir = '/tmp';
</span><del>-                $dir = realpath($dir);
-                return tempnam($dir, 'testpomo');
</del><ins>+                $dir = realpath( $dir );
+                return tempnam( $dir, 'testpomo' );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>