'mysql'); $this->object = new Query_Mysql_Driver($stub,'select'); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown() { } /** * @covers Query_Mysql_Driver::escape_field * @todo Implement testEscape_field(). */ public function testEscape_field() { $this->object->add_alias(); $this->assertEquals('test', $this->object->escape_field(new Expression_Database('test'))); $this->assertEquals('`a0`.*', $this->object->escape_field('*')); $this->assertEquals('`a0`.`test`', $this->object->escape_field('test')); $this->assertEquals('`test`.`test`',$this->object->escape_field('test.test')); } /** * @covers Query_Mysql_Driver::escape_value * @todo Implement testEscape_value(). */ public function testEscape_value() { $params=array(); $this->assertEquals('test', $this->object->escape_value(new Expression_Database('test'),$params)); $this->assertEquals('?', $this->object->escape_value('korova', $params)); $this->assertArrayHasKey(0, $params); $this->assertEquals('korova', $params[0]); } /** * @covers Query_Mysql_Driver::query * @todo Implement testQuery(). */ public function testQuerySelect1() { $query=$this->object ->table('fairies') ->where('a', 7) ->where('b', '<', 8) ->where('c', '>', 3) ->where('or', array('d', '>', 11)) ->where(array( array('e', 9), array('or', array( array('f', 10), array('g', 11), )), array('or', array( array('h', 12), array('or',array('i', 13)), )) )) ->order_by('id', 'desc') ->group_by('id') ->having('j', '<', new Expression_Database('korova')) ->having('or', array('l', '>', 11)) ->having(array( array('m', 9), array('or', array( array('n', 10), array('o', 11), )) )) ->limit(5) ->offset(6) ->query(); $this->assertEquals("SELECT * FROM `fairies` WHERE `fairies`.`a` = ? AND `fairies`.`b` < ? AND `fairies`.`c` > ? OR `fairies`.`d` > ? AND ( `fairies`.`e` = ? OR ( `fairies`.`f` = ? AND `fairies`.`g` = ? ) OR ( `fairies`.`h` = ? OR `fairies`.`i` = ? ) ) GROUP BY `fairies`.`id` HAVING `fairies`.`j` < korova OR `fairies`.`l` > ? AND ( `fairies`.`m` = ? OR ( `fairies`.`n` = ? AND `fairies`.`o` = ? ) ) ORDER BY `fairies`.`id` DESC LIMIT 5 OFFSET 6 ",current($query)); } /** * @covers Query_Mysql_Driver::query * @todo Implement testQuery(). */ public function testQuerySelect2() { $query=$this->object ->table('fairies') ->where('a', 7) ->join('test', array('fairies.test_id', 'test.id')) ->join('test2', array( array('fairies.test2_id', 'test.test_id'), array('fairies.test3_id', 'test.id') ),'inner') ->order_by('id','desc') ->query(); $this->assertEquals("SELECT * FROM `fairies` LEFT JOIN `test` ON `fairies`.`test_id` = `test`.`id` INNER JOIN `test2` ON ( `fairies`.`test2_id` = `test`.`test_id` AND `fairies`.`test3_id` = `test`.`id` ) WHERE `fairies`.`a` = ? ORDER BY `fairies`.`id` DESC ",current($query)); } /** * @covers Query_Mysql_Driver::query * @todo Implement testQuery(). */ public function testQueryDelete() { $query=$this->object ->type('delete') ->table('fairies') ->where('id',1) ->query(); $this->assertEquals("DELETE fairies.* FROM `fairies` WHERE `fairies`.`id` = ? ",current($query)); } /** * @covers Query_Mysql_Driver::query * @todo Implement testQuery(). */ public function testQueryInsert() { $query=$this->object ->type('insert') ->table('fairies') ->data(array('id'=>1,'name'=>'Trixie')) ->query(); $this->assertEquals("INSERT INTO `fairies` (`id`, `name`) VALUES(?, ?)",current($query)); } /** * @covers Query_Mysql_Driver::query * @todo Implement testQuery(). */ public function testQueryUpdate() { $query=$this->object ->type('update') ->table('fairies') ->data(array('id'=>1,'name'=>'Trixie')) ->query(); $this->assertEquals("UPDATE `fairies` SET `id` = ?, `name` = ? ",current($query)); } /** * @covers Query_Mysql_Driver::query * @todo Implement testQuery(). */ public function testQueryCount() { $query=$this->object ->type('count') ->table('fairies') ->where('id',8) ->query(); $this->assertEquals("SELECT COUNT(*) as `count` FROM `fairies` WHERE `fairies`.`id` = ? ",current($query)); } /** * @covers Query_Mysql_Driver::add_alias * @todo Implement testQuery(). */ public function testAlias() { $this->object->table('fairies'); $this->assertEquals('fairies', $this->object->last_alias()); $this->object->add_alias(); $this->assertEquals('a0',$this->object->last_alias()); } /** * @covers Query_Mysql_Driver::__call * @todo Implement testQuery(). */ public function testCall() { $this->object->table('fairies'); $this->assertEquals('fairies', $this->object->table()); $except = false; try { $this->object->limit('fairies'); }catch (Exception $e) { $except=true; } $this->assertEquals(true,$except); } }