/**
  * Test the append method.
  *
  * @param   array   $element   base element values
  * @param   array   $append    append element values
  * @param   array   $expected  expected element values for elements field after append
  * @param   string  $string    expected value of toString (not used in this test)
  *
  * @return  void
  *
  * @since   11.1
  * @dataProvider dataTestAppend
  */
 public function testAppend($element, $append, $expected, $string)
 {
     $baseElement = new JDatabaseQueryElement($element['name'], $element['elements'], $element['glue']);
     $appendElement = new JDatabaseQueryElement($append['name'], $append['elements'], $append['glue']);
     $expectedElement = new JDatabaseQueryElement($expected['name'], $expected['elements'], $expected['glue']);
     $baseElement->append($appendElement);
     $this->assertAttributeEquals(array($expectedElement), 'elements', $baseElement);
 }
	/**
	 * test__toString()
	 *
	 * @param	array 	base element values
	 * @param	array 	append element values
	 * @param	array	expected element values for _elements field after append
	 * @param	string	expected value of toString
	 *
	 * @return void
	 * @dataProvider casesAppend
	 */
	public function test__toString($element, $append, $expected, $string) {
		$baseElement = new JDatabaseQueryElement($element['name'], $element['elements'], $element['glue']);
		$appendElement = new JDatabaseQueryElement($append['name'], $append['elements'], $append['glue']);
		$baseElement->append($appendElement);
		$this->assertEquals($string, $baseElement->__toString());
	}
Example #3
0
 /**
  * Get the select part of the query
  *
  * @param   string                      $mode   List/form - effects which elements are selected
  * @param   JDatabaseQueryElement|bool  $query  QueryBuilder (false to return string)
  *
  * @return  mixed  string if $query = false, otherwise $query
  */
 public function buildQuerySelect($mode = 'list', $query = false)
 {
     $profiler = JProfiler::getInstance('Application');
     JDEBUG ? $profiler->mark('queryselect: start') : null;
     $db = $this->getDb();
     $form = $this->getFormModel();
     $table = $this->getTable();
     $form->getGroupsHiarachy();
     JDEBUG ? $profiler->mark('queryselect: fields load start') : null;
     $fields = $this->getAsFields($mode);
     $pk = FabrikString::safeColName($table->db_primary_key);
     $params = $this->getParams();
     $this->selectSlug($fields);
     JDEBUG ? $profiler->mark('queryselect: fields loaded') : null;
     $sFields = empty($fields) ? '' : implode(", \n ", $fields) . "\n ";
     /**
      * Testing potential fix for FOUND_ROWS performance issue on large tables.  If merging,
      * we never do a SELECT FOUND_ROWS(), so no need to use SQL_CALC_FOUND_ROWS.
      */
     $calcFoundRows = $this->mergeJoinedData() ? '' : 'SQL_CALC_FOUND_ROWS';
     /**
      * Distinct creates a temporary table which may slow down queries.
      * Added advanced option to toggle it on/off
      * http://fabrikar.com/forums/index.php?threads/bug-distinct.39160/#post-196739
      */
     $distinct = $params->get('distinct', true) ? 'DISTINCT' : '';
     // $$$rob added raw as an option to fix issue in saving calendar data
     if (trim($table->db_primary_key) != '' && in_array($this->outputFormat, array('partial', 'raw', 'html', 'feed', 'pdf', 'phocapdf', 'csv', 'word', 'yql', 'oai'))) {
         $sFields .= ', ';
         $strPKey = $pk . ' AS ' . $db->qn('__pk_val') . "\n";
         if ($query) {
             $query->select($calcFoundRows . ' ' . $distinct . ' ' . $sFields . $strPKey);
         } else {
             $sql = 'SELECT ' . $calcFoundRows . ' ' . $distinct . ' ' . $sFields . $strPKey;
         }
     } else {
         if ($query) {
             $query->select($calcFoundRows . ' ' . $distinct . ' ' . $sFields);
         } else {
             $sql = 'SELECT ' . $calcFoundRows . ' ' . $distinct . ' ' . trim($sFields, ", \n") . "\n";
         }
     }
     if ($query) {
         $query->from($db->qn($table->db_table_name));
     } else {
         $sql .= ' FROM ' . $db->qn($table->db_table_name) . " \n";
     }
     $pluginManager = FabrikWorker::getPluginManager();
     $pluginManager->runPlugins('onBuildQuerySelect', $this, 'list', $query);
     return $query ? $query : $sql;
 }
 /**
  * Tests the JDatabaseQueryElement::getElements method.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function testGetElements()
 {
     $e = new JDatabaseQueryElement('foo', 'bar');
     $this->assertThat($e->getElements(), $this->equalTo(array('bar')));
 }