Skip to content

Commit

Permalink
Use template for _getSortSelectCell
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
  • Loading branch information
MauricioFauth committed Nov 11, 2017
1 parent 10b8730 commit 7586c29
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
31 changes: 13 additions & 18 deletions libraries/classes/Database/Qbe.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,28 +385,23 @@ private function _showColumnSelectCell($column_number, $selected = '')
/**
* Provides select options list containing sort options (ASC/DESC)
*
* @param integer $column_number Column Number (0,1,2) or more
* @param string $asc_selected Selected criteria 'Ascending'
* @param string $desc_selected Selected criteria 'Descending'
* @param integer $columnNumber Column Number (0,1,2) or more
* @param string $ascSelected Selected criteria 'Ascending'
* @param string $descSelected Selected criteria 'Descending'
*
* @return string HTML for select options
*/
private function _getSortSelectCell($column_number, $asc_selected = '',
$desc_selected = ''
private function _getSortSelectCell(
$columnNumber,
$ascSelected = '',
$descSelected = ''
) {
$html_output = '<td class="center">';
$html_output .= '<select style="width: ' . $this->_realwidth
. '" name="criteriaSort[' . $column_number . ']" size="1">';
$html_output .= '<option value="">&nbsp;</option>';
$html_output .= '<option value="ASC"' . $asc_selected . '>'
. __('Ascending')
. '</option>';
$html_output .= '<option value="DESC"' . $desc_selected . '>'
. __('Descending')
. '</option>';
$html_output .= '</select>';
$html_output .= '</td>';
return $html_output;
return Template::get('database/qbe/sort_select_cell')->render([
'real_width' => $this->_realwidth,
'column_number' => $columnNumber,
'asc_selected' => $ascSelected,
'desc_selected' => $descSelected,
]);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions templates/database/qbe/sort_select_cell.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<td class="center">
<select style="width:{{ real_width }}" name="criteriaSort[{{ column_number }}]" size="1">
<option value="">&nbsp;</option>
<option value="ASC"{{ asc_selected|raw }}>{% trans 'Ascending' %}</option>
<option value="DESC"{{ desc_selected|raw }}>{% trans 'Descending' %}</option>
</select>
</td>
56 changes: 39 additions & 17 deletions test/classes/Database/QbeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,27 @@ private function _callProtectedFunction($name, $params)
*/
public function testGetSortSelectCell()
{
$this->assertEquals(
'<td class="center"><select style="width: 12ex" name="criteriaSort[1]" '
. 'size="1"><option value="">&nbsp;</option><option value="ASC">'
. 'Ascending</option><option value="DESC">Descending</option>'
. '</select></td>',
$this->assertContains(
'style="width:12ex" name="criteriaSort[1]"',
$this->_callProtectedFunction(
'_getSortSelectCell',
array(1)
)
);
$this->assertNotContains(
'selected="selected"',
$this->_callProtectedFunction(
'_getSortSelectCell',
array(1)
)
);
$this->assertContains(
'value="ASC" selected="selected">',
$this->_callProtectedFunction(
'_getSortSelectCell',
array(1, ' selected="selected"')
)
);
}

/**
Expand All @@ -113,18 +124,29 @@ public function testGetSortSelectCell()
*/
public function testGetSortRow()
{
$this->assertEquals(
'<tr class="noclick"><th>Sort:</th><td class="center">'
. '<select style="width: 12ex" name="criteriaSort[0]" size="1">'
. '<option value="">&nbsp;</option><option value="ASC">Ascending'
. '</option><option value="DESC">Descending</option></select></td>'
. '<td class="center"><select style="width: 12ex" '
. 'name="criteriaSort[1]" size="1"><option value="">&nbsp;</option>'
. '<option value="ASC">Ascending</option><option value="DESC">'
. 'Descending</option></select></td><td class="center">'
. '<select style="width: 12ex" name="criteriaSort[2]" size="1">'
. '<option value="">&nbsp;</option><option value="ASC">Ascending'
. '</option><option value="DESC">Descending</option></select></td></tr>',
$this->assertContains(
'<th>Sort:</th>',
$this->_callProtectedFunction(
'_getSortRow',
array()
)
);
$this->assertContains(
'name="criteriaSort[0]"',
$this->_callProtectedFunction(
'_getSortRow',
array()
)
);
$this->assertContains(
'name="criteriaSort[1]"',
$this->_callProtectedFunction(
'_getSortRow',
array()
)
);
$this->assertContains(
'name="criteriaSort[2]"',
$this->_callProtectedFunction(
'_getSortRow',
array()
Expand Down

0 comments on commit 7586c29

Please sign in to comment.