dbType != 'mysql' ) { $this->markTestSkipped('Only applies to MySQL'); } $this->_db = new MysqlManager(); } public function testQuote() { $string = "'dog eat "; if(!$this->_db->valid()) $this->markTestSkipped("MySQL not enabled"); $this->assertEquals($this->_db->quote($string),"\\'dog eat "); } public function testArrayQuote() { if(!$this->_db->valid()) $this->markTestSkipped("MySQL not enabled"); $string = array("'dog eat "); $this->_db->arrayQuote($string); $this->assertEquals($string,array("\\'dog eat ")); } public function providerConvert() { $returnArray = array( array( array('foo','nothing'), 'foo' ), array( array('foo','today'), 'CURDATE()' ), array( array('foo','left'), 'LEFT(foo)' ), array( array('foo','left',array('1','2','3')), 'LEFT(foo,1,2,3)' ), array( array('foo','date_format'), 'DATE_FORMAT(foo,\'%Y-%m-%d\')' ), array( array('foo','date_format',array('1','2','3')), 'DATE_FORMAT(foo,\'1\')' ), array( array('foo','date_format',array("'1'","'2'","'3'")), 'DATE_FORMAT(foo,\'1\')' ), array( array('foo','datetime',array("'%Y-%m'")), 'foo' ), array( array('foo','IFNULL'), 'IFNULL(foo,\'\')' ), array( array('foo','IFNULL',array('1','2','3')), 'IFNULL(foo,1,2,3)' ), array( array('foo','CONCAT',array('1','2','3')), 'CONCAT(foo,1,2,3)' ), array( array(array('1','2','3'),'CONCAT'), 'CONCAT(1,2,3)' ), array( array(array('1','2','3'),'CONCAT',array('foo', 'bar')), 'CONCAT(1,2,3,foo,bar)' ), array( array('foo','text2char'), 'foo' ), array( array('foo','length'), "LENGTH(foo)" ), array( array('foo','month'), "MONTH(foo)" ), array( array('foo','quarter'), "QUARTER(foo)" ), array( array('foo','add_date',array(1,'day')), "DATE_ADD(foo, INTERVAL 1 day)" ), array( array('foo','add_date',array(2,'week')), "DATE_ADD(foo, INTERVAL 2 week)" ), array( array('foo','add_date',array(3,'month')), "DATE_ADD(foo, INTERVAL 3 month)" ), array( array('foo','add_date',array(4,'quarter')), "DATE_ADD(foo, INTERVAL 4 quarter)" ), array( array('foo','add_date',array(5,'year')), "DATE_ADD(foo, INTERVAL 5 year)" ), ); return $returnArray; } /** * @ticket 33283 * @dataProvider providerConvert */ public function testConvert(array $parameters, $result) { $this->assertEquals($result, call_user_func_array(array($this->_db, "convert"), $parameters)); } /** * @ticket 33283 */ public function testConcat() { $ret = $this->_db->concat('foo',array('col1','col2','col3')); $this->assertEquals("LTRIM(RTRIM(CONCAT(IFNULL(foo.col1,''),' ',IFNULL(foo.col2,''),' ',IFNULL(foo.col3,''))))", $ret); } public function providerFromConvert() { $returnArray = array( array( array('foo','nothing'), 'foo' ), array( array('2009-01-01 12:00:00','date'), '2009-01-01 12:00:00' ), array( array('2009-01-01 12:00:00','time'), '2009-01-01 12:00:00' ) ); return $returnArray; } /** * @ticket 33283 * @dataProvider providerFromConvert */ public function testFromConvert( array $parameters, $result ) { $this->assertEquals( $this->_db->fromConvert($parameters[0],$parameters[1]), $result); } public function providerFullTextQuery() { return array( array(array('word1'), array(), array(), "MATCH(unittest) AGAINST('word1' IN BOOLEAN MODE)"), array(array("'word1'"), array(), array(), "MATCH(unittest) AGAINST('\'word1\'' IN BOOLEAN MODE)"), array(array('word1', 'word2'), array(), array(), "MATCH(unittest) AGAINST('word1 word2' IN BOOLEAN MODE)"), array(array('word1', 'word2'), array('mustword'), array(), "MATCH(unittest) AGAINST('word1 word2 +mustword' IN BOOLEAN MODE)"), array(array('word1', 'word2'), array('mustword', 'mustword2'), array(), "MATCH(unittest) AGAINST('word1 word2 +mustword +mustword2' IN BOOLEAN MODE)"), array(array(), array('mustword', 'mustword2'), array(), "MATCH(unittest) AGAINST('+mustword +mustword2' IN BOOLEAN MODE)"), array(array('word1'), array(), array('notword'), "MATCH(unittest) AGAINST('word1 -notword' IN BOOLEAN MODE)"), array(array('word1'), array(), array('notword', 'notword2'), "MATCH(unittest) AGAINST('word1 -notword -notword2' IN BOOLEAN MODE)"), array(array('word1', 'word2'), array('mustword', 'mustword2'), array('notword', 'notword2'), "MATCH(unittest) AGAINST('word1 word2 +mustword +mustword2 -notword -notword2' IN BOOLEAN MODE)"), ); } /** * @ticket 37435 * @dataProvider providerFullTextQuery * @param array $terms * @param string $result */ public function testFullTextQuery($terms, $must_terms, $exclude_terms, $result) { $this->assertEquals($result, $this->_db->getFulltextQuery('unittest', $terms, $must_terms, $exclude_terms)); } }