Example #1
0
 public function testDatabaseRollback()
 {
     $GWC = new green_web_controller($debug = true);
     $GWC->handleRequest(array('database' => true));
     // Make sure this doesn't exist before doing any further tests
     $rs = $GWC->DBWrite('DROP TABLE IF EXISTS user_test');
     $this->assertEquals($rs, true);
     $rs = $GWC->DBWrite('CREATE TABLE IF NOT EXISTS user_test (id int PRIMARY KEY auto_increment,name varchar(64) NOT NULL,value varchar(64) NOT NULL,last_updated datetime NOT NULL) CHARACTER SET utf8;');
     $this->assertEquals($rs, true);
     $GWC->DBStartTransaction();
     $rs = $GWC->DBWrite('INSERT INTO user_test (name,value,last_updated) VALUES (:name, :value, NOW())', array(':name' => 'Green Framework Author', ':value' => "Adrian Green"));
     $this->assertEquals($rs, true);
     $GWC->DBRollback();
     $rs = $GWC->DBRead('SELECT * FROM user_test WHERE value = :value', array(':value' => 'Adrian Green'));
     $this->assertEmpty($rs);
     $rs = $GWC->DBWrite('DROP TABLE IF EXISTS user_test');
     $this->assertTrue($rs);
 }