Пример #1
0
 /**
  * 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)"));
 }
 /**
  * Tests the JDatabaseQuery::format method.
  *
  * @return  void
  *
  * @since   12.3
  */
 public function testFormat()
 {
     $q = new JDatabaseQueryInspector($this->dbo);
     $result = $q->format('SELECT %n FROM %n WHERE %n = %a', 'foo', '#__bar', 'id', 10);
     $expected = 'SELECT ' . $q->qn('foo') . ' FROM ' . $q->qn('#__bar') . ' WHERE ' . $q->qn('id') . ' = 10';
     $this->assertThat($result, $this->equalTo($expected), 'Line: ' . __LINE__ . '.');
     $result = $q->format('SELECT %n FROM %n WHERE %n = %t OR %3$n = %Z', 'id', '#__foo', 'date');
     $expected = 'SELECT ' . $q->qn('id') . ' FROM ' . $q->qn('#__foo') . ' WHERE ' . $q->qn('date') . ' = ' . $q->currentTimestamp() . ' OR ' . $q->qn('date') . ' = ' . $q->nullDate(true);
     $this->assertThat($result, $this->equalTo($expected), 'Line: ' . __LINE__ . '.');
 }
 /**
  * Tests the JDatabaseQuery::rightJoin method.
  *
  * @return  void
  *
  * @covers  JDatabaseQuery::rightJoin
  * @since   11.3
  */
 public function testRightJoin()
 {
     $q1 = new JDatabaseQueryInspector($this->dbo);
     $q2 = new JDatabaseQueryInspector($this->dbo);
     $condition = 'foo ON foo.id = bar.id';
     $this->assertThat($q1->rightJoin($condition), $this->identicalTo($q1), 'Tests chaining.');
     $q2->join('RIGHT', $condition);
     $this->assertThat(TestReflection::getValue($q1, 'join'), $this->equalTo(TestReflection::getValue($q2, 'join')), 'Tests that rightJoin is an alias for join.');
 }
Пример #4
0
 /**
  * Tests the quoteName method.
  *
  * @return  void
  *
  * @since   11.1
  */
 public function testQuoteName()
 {
     $q = new JDatabaseQueryInspector($this->dbo);
     $this->assertThat($q->quoteName("test"), $this->equalTo("`test`"), 'The quoteName method should be a proxy for the JDatabase::escape method.');
 }
 /**
  * Tests the JDatabaseQuery::where method.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function testWhere()
 {
     $q = new JDatabaseQueryInspector($this->dbo);
     $this->assertThat($q->where('foo = 1'), $this->identicalTo($q), 'Tests chaining.');
     $this->assertThat(trim($q->where), $this->equalTo('WHERE foo = 1'), 'Tests rendered value.');
     // Add another column.
     $q->where(array('bar = 2', 'goo = 3'));
     $this->assertThat(trim($q->where), $this->equalTo('WHERE foo = 1 AND bar = 2 AND goo = 3'), 'Tests rendered value after second use and array input.');
     // Clear the where
     $q->where = null;
     $q->where(array('bar = 2', 'goo = 3'), 'OR');
     $this->assertThat(trim($q->where), $this->equalTo('WHERE bar = 2 OR goo = 3'), 'Tests rendered value with glue.');
 }
	/**
	 * Tests the JDatabaseQuery::unionDistinct method.
	 *
	 * @return  void
	 *
	 * @since   12.1
	 */
	public function testUnionDistinctArray()
	{

		$q = new JDatabaseQueryInspector($this->dbo);

		$q->union = null;
		$q->unionDistinct(array('SELECT name FROM foo', 'SELECT name FROM bar'));
		$teststring = (string) $q->union;
		$this->assertThat(
			$teststring,
			$this->equalTo("\nUNION DISTINCT (SELECT name FROM foo)\nUNION DISTINCT (SELECT name FROM bar)"),
			'Tests rendered query with two unions distinct.'
		);
	}