/** * Tests the JDatabaseQuery::select method. * * @return void * * @since 11.3 */ public function testSelect() { $q = new JDatabaseQueryInspector($this->dbo); $this->assertThat($q->select('foo'), $this->identicalTo($q), 'Tests chaining.'); $this->assertThat($q->type, $this->equalTo('select'), 'Tests the type property is set correctly.'); $this->assertThat(trim($q->select), $this->equalTo('SELECT foo'), 'Tests the select element is set correctly.'); $q->select('bar'); $this->assertThat(trim($q->select), $this->equalTo('SELECT foo,bar'), 'Tests the second use appends correctly.'); $q->select(array('goo', 'car')); $this->assertThat(trim($q->select), $this->equalTo('SELECT foo,bar,goo,car'), 'Tests the second use appends correctly.'); }
/** * Tests the JDatabaseQuery::union method when passed two query objects in an array. * * @return void * * @since 12.?? */ public function testUnionObjectsArray() { $this->_instance->select('name')->from('foo')->where('a=1'); $q2 = new JDatabaseQueryInspector($this->dbo); $q2->select('name')->from('bar')->where('b=2'); $q3 = new JDatabaseQueryInspector($this->dbo); $q3->select('name')->from('baz')->where('c=3'); TestReflection::setValue($this->_instance, 'union', null); $this->_instance->union(array($q2, $q3)); $this->assertThat((string) $this->_instance, $this->equalTo(PHP_EOL . "SELECT name" . PHP_EOL . "FROM foo" . PHP_EOL . "WHERE a=1" . PHP_EOL . "UNION (" . PHP_EOL . "SELECT name" . PHP_EOL . "FROM bar" . PHP_EOL . "WHERE b=2)" . PHP_EOL . "UNION (" . PHP_EOL . "SELECT name" . PHP_EOL . "FROM baz" . PHP_EOL . "WHERE c=3)")); }
/** * Test for INSERT INTO clause with subquery. * * @return void * * @since 11.3 */ public function test__toStringInsert_subquery() { $subq = new JDatabaseQueryInspector($this->dbo); $subq->select('col2')->where('a=1'); $this->_instance->insert('table')->columns('col')->values($subq); $this->assertThat((string) $this->_instance, $this->equalTo(PHP_EOL . "INSERT INTO table" . PHP_EOL . "(col)" . PHP_EOL . "(" . PHP_EOL . "SELECT col2" . PHP_EOL . "WHERE a=1)")); $this->_instance->clear(); $this->_instance->insert('table')->columns('col')->values('3'); $this->assertThat((string) $this->_instance, $this->equalTo(PHP_EOL . "INSERT INTO table" . PHP_EOL . "(col) VALUES " . PHP_EOL . "(3)")); }