Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AgelxNash committed Nov 7, 2018
1 parent 5a08dd3 commit 5fb5347
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions assets/snippets/DocLister/core/DocLister.abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ protected function getFilters($filter_string)
{
$this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1);
// the filter parameter tells us, which filters can be used in this query
$filter_string = trim($filter_string, ' ;');
$filter_string = ltrim(trim($filter_string, ';'));
if (!$filter_string) {
return;
}
Expand All @@ -1652,7 +1652,7 @@ protected function getFilters($filter_string)
/**
* С правой стороны не выполняется trim, т.к. там находятся значения. А они могу быть чувствительны к пробелам
*/
$subfilter = $this->getFilters(ltrim($filter) . $lastFilter);
$subfilter = $this->getFilters(ltrim($filter) . ltrim($lastFilter));
if (!$subfilter) {
$lastFilter = explode(';', $filter, 2);
$subfilter = isset($lastFilter[1]) ? $this->getFilters($lastFilter[1]) : '';
Expand Down
57 changes: 57 additions & 0 deletions tests/DL/Filters/Issue333Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php namespace DocLister\Tests\DL\Filters;

use DocLister\Tests\DL\DLAbstract;

class Issue333Test extends DLAbstract
{
/**
* @see: https://github.com/AgelxNash/DocLister/issues/333
*/
public function testA()
{
$method = $this->getMethod($this->DL, 'getFilters');
$filters = $method->invoke($this->DL, 'testA:is:no');

$this->assertEquals(false, $filters);
}


public function testB()
{
$out = array(
'join' => 'LEFT JOIN site_tmplvar_contentvalues as `dltv_testA_1` ON `dltv_testA_1`.`contentid`=`c`.`id` AND `dltv_testA_1`.`tmplvarid`=1',
'where' => "(`dltv_testA_1`.`value` = 'no ')"
);

$method = $this->getMethod($this->DL, 'getFilters');
$filters = $method->invoke($this->DL, 'AND( tv:testA:is:no )');

$this->assertEquals($out, $filters);
}

public function testC()
{
$out = array(
'join' => 'LEFT JOIN site_tmplvar_contentvalues as `dltv_testA_1` ON `dltv_testA_1`.`contentid`=`c`.`id` AND `dltv_testA_1`.`tmplvarid`=1',
'where' => "(`dltv_testA_1`.`value` = 'no')"
);

$method = $this->getMethod($this->DL, 'getFilters');
$filters = $method->invoke($this->DL, 'AND( tv:testA:is:no; )');

$this->assertEquals($out, $filters);
}

public function testD()
{
$out = array(
'join' => 'LEFT JOIN site_tmplvar_contentvalues as `dltv_testA_2` ON `dltv_testA_2`.`contentid`=`c`.`id` AND `dltv_testA_2`.`tmplvarid`=1 LEFT JOIN site_tmplvars as `d_dltv_testA_2` on `d_dltv_testA_2`.`id` = 1 LEFT JOIN site_tmplvar_contentvalues as `dltv_testB_1` ON `dltv_testB_1`.`contentid`=`c`.`id` AND `dltv_testB_1`.`tmplvarid`=2',
'where' => "(IFNULL(`dltv_testA_2`.`value`, `d_dltv_testA_2`.`default_text`) = 'no ' AND `dltv_testB_1`.`value` = 'yes')"
);

$method = $this->getMethod($this->DL, 'getFilters');
$filters = $method->invoke($this->DL, 'AND( tvd:testA:is:no ; tv:testB:is:yes; )');

$this->assertEquals($out, $filters);
}
}

0 comments on commit 5fb5347

Please sign in to comment.