/** * @covers Openbuildings\Kohana\DB::select */ public function test_select() { $result = DB::select('name', 'id'); $this->assertInstanceOf('Openbuildings\\Kohana\\Database_Query_Builder_Select', $result); $this->assertEquals(Database::SELECT, $result->type()); $this->assertEquals('SELECT `name`, `id`', $result->compile()); }
/** * @covers Openbuildings\Kohana\Database_Query_Builder_Insert::compile */ public function test_compile() { $query = new Database_Query_Builder_Insert('table1', array('name', 'price')); $this->assertEquals("INSERT INTO `table1` (`name`, `price`) VALUES ('one', 10), ('two', 20)", $query->values(array('one', 10), array('two', 20))->compile()); $this->assertEquals("INSERT INTO `table1` (`name`, `price`) VALUES ('one', 10), ('two', 20)", $query->compile($this->database)); $query = new Database_Query_Builder_Insert('table1', array('name', 'price')); $this->assertEquals("INSERT INTO `table1` (`name`, `price`) SELECT `name` AS `price` FROM `table2`", $query->select(DB::select(array('name', 'price'))->from('table2'))->compile()); }
/** * @covers Openbuildings\Kohana\Database_Query_Builder_Select::union */ public function test_union() { $query = new Database_Query_Builder_Select(); $this->assertEquals("SELECT * FROM `table1` UNION ALL SELECT * FROM `table2`", $query->from('table1')->union('table2')->compile()); $this->assertEquals("SELECT * FROM `table1` UNION ALL SELECT * FROM `table2` UNION ALL SELECT `name` FROM `table2`", $query->from('table1')->union(DB::select('name')->from('table2'))->compile()); }
/** * @covers Openbuildings\Kohana\Database::quote */ public function test_quote() { $this->assertSame('NULL', $this->database->quote(NULL)); $this->assertSame(10, $this->database->quote(10)); $this->assertSame("'1'", $this->database->quote(TRUE)); $this->assertSame("'0'", $this->database->quote(FALSE)); $this->assertSame("'test to string'", $this->database->quote(new Test_ToString_Class())); $this->assertSame("test", $this->database->quote(DB::expr('test'))); $this->assertSame("(SELECT name, id)", $this->database->quote(DB::select('name', 'id'))); $this->assertSame("'free text'", $this->database->quote('free text')); $this->assertSame("('1', 20)", $this->database->quote(array('1', 20))); $this->assertSame("5.123000", $this->database->quote(5.123)); }