cakephp-filter-plugin
cakephp-filter-plugin copied to clipboard
FilteredBehavior and CakePHP 2.3.x
CakePHP v2.3, PHP v5.4
The FilteredBehavior returns an empty $query['conditions']-array. A little research learned me this:
function beforeFind(Model $Model, $query) { ... $settings = $this->settings[$Model->alias]; $values = $this->_filterValues[$Model->alias];
foreach ($settings as $field => $options)
{
$this->addFieldToFilter($Model, $query, $settings, $values, $field, $options);
}
...
return $query;
}
Inhere, the methodcall $this->addFieldToFilter($Model, $query, $settings, $values, $field, $options); returns an empty $query['conditions']-array.
Some new investigations:
protected function buildFilterConditions(array $query, $field, $options, $value) { ...
}
The method creates the $query['conditions'] well, but after the transfer to beforeFind, it is empty. The only place where the $query['conditions']-array is properly set is after switch{ ... }.
any suggestions?
Hi there,
Would it be possible for you to create a small unit test for this? I'm curious to see what kind of data will recreate this bug.
Sure,
I'm enjoing web-design, which means that I'm learning it, just form personal enrichment. So, an amateur-webdesigner pur sang :) if you can give me some instructions and your expectations, I surely will setup this test.
In the meantime I ran the testsuite of cake, with the following results (maybe a start). Good Luck
Running All FilterPlugin tests Running FilterTestCase
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'name' => 'Document.title' 'options' => Array (...)
-
'attributes' => Array () ) 1 => Array ( 'name' => 'DocumentCategory.id' 'options' => Array (...) -
'attributes' => Array () ))
Test case: FilterTestCase(testBasicViewInfo) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Controller\Component\FilterComponentTest.php : 374 FilterTestCase::testBasicViewInfo D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'name' => 'Document.title' 'options' => Array (...)
-
'attributes' => Array () ) 1 => Array ( 'name' => 'DocumentCategory.id' 'options' => Array (...) -
'attributes' => Array () ))
Test case: FilterTestCase(testAdditionalInputOptions) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Controller\Component\FilterComponentTest.php : 437 FilterTestCase::testAdditionalInputOptions D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'name' => 'DocumentCategory.id' 'options' => Array (...)
-
'attributes' => Array () ))
Test case: FilterTestCase(testCustomSelector) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Controller\Component\FilterComponentTest.php : 487 FilterTestCase::testCustomSelector D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'name' => 'Document.is_private' 'options' => Array (...)
-
'attributes' => Array () ))
Test case: FilterTestCase(testCheckboxOptions) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Controller\Component\FilterComponentTest.php : 530 FilterTestCase::testCheckboxOptions D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'name' => 'DocumentCategory.title' 'options' => Array (...)
-
'attributes' => Array () ))
Test case: FilterTestCase(testBelongsToFilteringByText) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Controller\Component\FilterComponentTest.php : 604 FilterTestCase::testBelongsToFilteringByText D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94 Running FilteredTestCase
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array (...) 1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testFilteringBelongsTo) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 171 FilteredTestCase::testFilteringBelongsTo D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 5 -
'title' => 'Father Ted' -
'document_category_id' => 2 -
'owner_id' => 2 -
'is_private' => 0 -
'created' => '2009-01-13 05:15:03' -
'updated' => '2010-12-05 03:24:15' -
'id' => '1' -
'title' => 'Testing Doc' -
'document_category_id' => '1' -
'owner_id' => '1' -
'is_private' => '0' -
'created' => '2010-06-28 10:39:23' -
'updated' => '2010-06-29 11:22:48' ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testFilteringBelongsToTextField) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 194 FilteredTestCase::testFilteringBelongsToTextField D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array (...) 1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testFilteringBelongsToFilterFieldTest) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 224 FilteredTestCase::testFilteringBelongsToFilterFieldTest D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 4 -
'title' => 'Illegal explosives DIY' -
'document_category_id' => 1 -
'owner_id' => 1 -
'is_private' => 1 -
'created' => '2010-01-08 05:15:03' -
'updated' => '2010-05-22 03:15:24' -
'id' => '1' -
'title' => 'Testing Doc' -
'document_category_id' => '1' -
'owner_id' => '1' -
'is_private' => '0' -
'created' => '2010-06-28 10:39:23' -
'updated' => '2010-06-29 11:22:48' ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testFilteringBelongsToDifferentConditions) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 252 FilteredTestCase::testFilteringBelongsToDifferentConditions D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 2 -
'title' => 'Imaginary Spec' -
'document_category_id' => 1 -
'owner_id' => 1 -
'is_private' => 0 -
'created' => '2010-03-28 12:19:13' -
'updated' => '2010-04-29 11:23:44' -
'id' => '1' -
'title' => 'Testing Doc' -
'document_category_id' => '1' -
'owner_id' => '1' -
'is_private' => '0' -
'created' => '2010-06-28 10:39:23' -
'updated' => '2010-06-29 11:22:48' ) 'DocumentCategory' => Array (...) 'Metadata' => Array ( -
'id' => 2 -
'document_id' => 2 -
'weight' => 0 -
'size' => 45 -
'permissions' => 'rw-------' -
'id' => '1' -
'document_id' => '1' -
'weight' => '5' -
'size' => '256' -
'permissions' => 'rw-r--r--' ) 'Item' => Array ( 0 => Array ( -
'id' => 4 -
'document_id' => 2 -
'id' => '1' -
'document_id' => '1' 'code' => 'The item #01' ) 1 => Array ( -
'id' => 5 -
'document_id' => 2 -
'id' => '2' -
'document_id' => '1' 'code' => 'The item #02' ) 2 => Array ( -
'id' => 6 -
'document_id' => 2 -
'id' => '3' -
'document_id' => '1' 'code' => 'The item #03' ) -
3 => Array (...) ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testFilteringBelongsToAndHasMany) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 318 FilteredTestCase::testFilteringBelongsToAndHasMany D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 5 -
'title' => 'Father Ted' -
'document_category_id' => 2 -
'owner_id' => 2 -
'is_private' => 0 -
'created' => '2009-01-13 05:15:03' -
'updated' => '2010-12-05 03:24:15' -
'id' => '1' -
'title' => 'Testing Doc' -
'document_category_id' => '1' -
'owner_id' => '1' -
'is_private' => '0' -
'created' => '2010-06-28 10:39:23' -
'updated' => '2010-06-29 11:22:48' ) 'Metadata' => Array ( -
'id' => 5 -
'document_id' => 5 -
'weight' => 4 -
'size' => 790 -
'permissions' => 'rw-rw-r--' -
'id' => null -
'document_id' => null -
'weight' => null -
'size' => null -
'permissions' => null ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testCustomJoinConditions) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 384 FilteredTestCase::testCustomJoinConditions D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 2 -
'title' => 'Imaginary Spec' -
'document_category_id' => 1 -
'owner_id' => 1 -
'is_private' => 0 -
'created' => '2010-03-28 12:19:13' -
'updated' => '2010-04-29 11:23:44' -
'id' => '1' -
'title' => 'Testing Doc' -
'document_category_id' => '1' -
'owner_id' => '1' -
'is_private' => '0' -
'created' => '2010-06-28 10:39:23' -
'updated' => '2010-06-29 11:22:48' ) 'DocumentCategory' => Array (...) 'Item' => Array ( 0 => Array ( -
'id' => 4 -
'document_id' => 2 -
'id' => '1' -
'document_id' => '1' 'code' => 'The item #01' ) 1 => Array ( -
'id' => 5 -
'document_id' => 2 -
'id' => '2' -
'document_id' => '1' 'code' => 'The item #02' ) 2 => Array ( -
'id' => 6 -
'document_id' => 2 -
'id' => '3' -
'document_id' => '1' 'code' => 'The item #03' ) -
3 => Array (...) ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testFilteringBelongsToAndHasManyWithContainable) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 435 FilteredTestCase::testFilteringBelongsToAndHasManyWithContainable D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 2 -
'title' => 'Imaginary Spec' -
'id' => '1' -
'title' => 'Testing Doc' ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testHasOneAndHasManyWithTextSearch) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 495 FilteredTestCase::testHasOneAndHasManyWithTextSearch D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 2 -
'title' => 'Imaginary Spec' -
'document_category_id' => 1 -
'owner_id' => 1 -
'is_private' => 0 -
'created' => '2010-03-28 12:19:13' -
'updated' => '2010-04-29 11:23:44' -
'id' => '1' -
'title' => 'Testing Doc' -
'document_category_id' => '1' -
'owner_id' => '1' -
'is_private' => '0' -
'created' => '2010-06-28 10:39:23' -
'updated' => '2010-06-29 11:22:48' ) 'Metadata' => Array ( -
'id' => 2 -
'document_id' => 2 -
'weight' => 0 -
'size' => 45 -
'permissions' => 'rw-------' -
'id' => '1' -
'document_id' => '1' -
'weight' => '5' -
'size' => '256' -
'permissions' => 'rw-r--r--' ) 'Item' => Array ( 0 => Array ( -
'id' => 4 -
'document_id' => 2 -
'id' => '1' -
'document_id' => '1' 'code' => 'The item #01' ) 1 => Array ( -
'id' => 5 -
'document_id' => 2 -
'id' => '2' -
'document_id' => '1' 'code' => 'The item #02' ) 2 => Array ( -
'id' => 6 -
'document_id' => 2 -
'id' => '3' -
'document_id' => '1' 'code' => 'The item #03' ) -
3 => Array (...) ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testHasOneWithContainable) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 538 FilteredTestCase::testHasOneWithContainable D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 2 -
'title' => 'Imaginary Spec' -
'document_category_id' => 1 -
'owner_id' => 1 -
'is_private' => 0 -
'created' => '2010-03-28 12:19:13' -
'updated' => '2010-04-29 11:23:44' -
'id' => '1' -
'title' => 'Testing Doc' -
'document_category_id' => '1' -
'owner_id' => '1' -
'is_private' => '0' -
'created' => '2010-06-28 10:39:23' -
'updated' => '2010-06-29 11:22:48' ) 'DocumentCategory' => Array (...) 'Metadata' => Array ( -
'id' => 2 -
'document_id' => 2 -
'weight' => 0 -
'size' => 45 -
'permissions' => 'rw-------' -
'id' => '1' -
'document_id' => '1' -
'weight' => '5' -
'size' => '256' -
'permissions' => 'rw-r--r--' ) 'Item' => Array ( 0 => Array ( -
'id' => 4 -
'document_id' => 2 -
'id' => '1' -
'document_id' => '1' 'code' => 'The item #01' ) 1 => Array ( -
'id' => 5 -
'document_id' => 2 -
'id' => '2' -
'document_id' => '1' 'code' => 'The item #02' ) 2 => Array ( -
'id' => 6 -
'document_id' => 2 -
'id' => '3' -
'document_id' => '1' 'code' => 'The item #03' ) -
3 => Array (...) ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...)
-
5 => Array (...)
-
6 => Array (...)
-
7 => Array (...)
-
8 => Array (...)
-
9 => Array (...) )
Test case: FilteredTestCase(testJoinAlreadyPresent) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 599 FilteredTestCase::testJoinAlreadyPresent D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
-
Failed
Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( 0 => Array ( 'Document' => Array (
-
'id' => 5 -
'title' => 'Father Ted' -
'document_category_id' => 2 -
'owner_id' => 2 -
'is_private' => 0 -
'created' => '2009-01-13 05:15:03' -
'updated' => '2010-12-05 03:24:15' -
'id' => '1' -
'title' => 'Testing Doc' -
'document_category_id' => '1' -
'owner_id' => '1' -
'is_private' => '0' -
'created' => '2010-06-28 10:39:23' -
'updated' => '2010-06-29 11:22:48' ) ) -
1 => Array (...)
-
2 => Array (...)
-
3 => Array (...)
-
4 => Array (...) )
Test case: FilteredTestCase(testNofilterFindParam) Stack trace: D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 2134 D:\xampp\php\pear\PHPUnit\Framework\Assert.php : 475 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 538 D:\xampp\htdocs\myKGM\Plugin\Filter\Test\Case\Model\Behaviors\FilteredTest.php : 633 FilteredTestCase::testNofilterFindParam D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 976 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 831 D:\xampp\php\pear\PHPUnit\Framework\TestResult.php : 648 D:\xampp\php\pear\PHPUnit\Framework\TestCase.php : 776 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestCase.php : 83 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 775 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 745 D:\xampp\php\pear\PHPUnit\Framework\TestSuite.php : 705 D:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php : 349 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestRunner.php : 62 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 115 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 247 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 100 D:\xampp\htdocs\cakePHP\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 117 D:\xampp\htdocs\myKGM\webroot\test.php : 94
33/33 test methods complete: 17 passes, 16 fails, 38 assertions and *0
- exceptions.
Time: 2.2565364837646 seconds
Peak memory: 14,554,024 bytes
Run more testshttp://localhost/myKGM/webroot/test.php?show=cases&plugin=Filter| Show Passeshttp://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&show_passes=1| Enable Debug Outputhttp://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&debug=1| Analyze Code Coveragehttp://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&code_coverage=true Code coverage results Toggle all fileshttp://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&code_coverage=true# AllTest.php Code coverage: 0% http://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&code_coverage=true#coverage-AllTest.php
1<?php 2/** 3 CakePHP Filter Plugin 4 5 Copyright (C) 2009-3827 dr. Hannibal Lecter / lecterror 6 http://lecterror.com/ 7 8 Multi-licensed under: 9 MPL http://www.mozilla.org/MPL/MPL-1.1.html 10 LGPL http://www.gnu.org/licenses/lgpl.html 11 GPL http://www.gnu.org/licenses/gpl.html 12*/ 13 14class AllFilterTests extends CakeTestSuite 15{ 16 public static function suite() 17 { 18 $suite = new CakeTestSuite('All FilterPlugin tests'); 19 20 $suite->addTestDirectoryRecursive(App::pluginPath('Filter').'Test'.DS.'Case'); 21 22 return $suite; 23 } 24}
FilterComponent.php Code coverage: 77.23% http://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&code_coverage=true#coverage-FilterComponent.php
1<?php 2/** 3 CakePHP Filter Plugin 4 5 Copyright (C) 2009-3827 dr. Hannibal Lecter / lecterror 6 http://lecterror.com/ 7 8 Multi-licensed under: 9 MPL http://www.mozilla.org/MPL/MPL-1.1.html 10 LGPL http://www.gnu.org/licenses/lgpl.html 11 GPL http://www.gnu.org/licenses/gpl.html 12_/ 13 14/_* 15 * @property RequestHandlerComponent $RequestHandler 16 * @property SessionComponent $Session 17 */ 18 19App::import('Component', 'Session'); 20App::import('Behavior', 'Filter.Filtered'); 21 22class FilterComponent extends Component { 23 var $components = array('Session'); 24 25 var $settings = array(); 26 var $nopersist = array(); 27 var $formData = array(); 28 var $_request_settings = array(); 29 30 public function __construct(ComponentCollection $collection, $settings = array()){ 31 parent::__construct($collection, $settings); 32 $this->_request_settings = $settings; 33 } 34 35 function initialize(Controller $controller){ 36 if (!isset($controller->filters)){ 37 return; 38 } 39 $this->updatePersistence($controller, $this->_request_settings); 40 $this->settings[$controller->name] = $controller->filters; 41 42 if (!isset($this->settings[$controller->name][$controller->action])) 43 { 44 return; 45 } 46 47 $settings = $this->settings[$controller->name][$controller->action]; 48 49 foreach ($settings as $model => $filter){ 50 if (!isset($controller->{$model})) 51 { 52 trigger_error(('Filter model not found: %s', $model)); 53 continue; 54 } 55 56 $controller->$model->Behaviors->attach('Filter.Filtered', $filter); 57 } 58 } 59 60 function startup(Controller $controller){ 61 if (!isset($this->settings[$controller->name][$controller->action])){ 62 return; 63 } 64 65 $settings = $this->settings[$controller->name][$controller->action]; 66 67 if (!in_array('Filter.Filter', $controller->helpers)) 68 { 69 $controller->helpers[] = 'Filter.Filter'; 70 } 71 72 $sessionKey = sprintf('FilterPlugin.Filters.%s.%s', $controller->name, $controller->action); 73 74 if (!$controller->request->is('post') || !isset($controller->request->data['Filter']['filterFormId'])) 75 { 76 $persistedData = array(); 77 78 if ($this->Session->check($sessionKey)) 79 { 80 $persistedData = $this->Session->read($sessionKey); 81 } 82 83 if (empty($persistedData)) 84 { 85 return; 86 } 87 88 $this->formData = $persistedData; 89 } 90 else 91 { 92 $this->formData = $controller->request->data; 93 $this->Session->write($sessionKey, $this->formData); 94 $controller->redirect($controller->referer()); 95 } 96 97 foreach ($settings as $model => $options) 98 { 99 if (!isset($controller->{$model})) 100 { 101 trigger_error(('Filter model not found: %s', $model)); 102 continue; 103 } 104 105 $controller->$model->setFilterValues($this->formData); 106 } 107 } 108 109function beforeRender(Controller $controller) 110 { 111 if (!isset($this->settings[$controller->name][$controller->action])) 112 { 113 return; 114 } 115 116 $models = $this->settings[$controller->name][$controller->action]; 117 $viewFilterParams = array(); 118 119 foreach ($models as $model => $fields) 120 { 121 if (!isset($controller->$model)) 122 { 123 trigger_error(('Filter model not found: %s', $model)); 124 continue; 125 } 126 127 foreach ($fields as $field => $settings) 128 { 129 if (!is_array($settings)) 130 { 131 $field = $settings; 132 $settings = array(); 133 } 134 135 if (!isset($settings['required'])) 136 { 137 $settings['required'] = false; 138 } 139 140 if (!isset($settings['type'])) 141 { 142 $settings['type'] = 'text'; 143 } 144 145 $options = array(); 146 $attributes = array(); 147 $fieldName = $field; 148 $fieldModel = $model; 149 150 if (strpos($field, '.') !== false) 151 { 152 list($fieldModel, $fieldName) = explode('.', $field); 153 } 154 155 if (!empty($this->formData)) 156 { 157 if (isset($this->formData[$fieldModel][$fieldName])) 158 { 159 $options['value'] = $this->formData[$fieldModel][$fieldName]; 160 } 161 } 162 163 if (isset($settings['inputOptions'])) 164 { 165 if (!is_array($settings['inputOptions'])) 166 { 167 $settings['inputOptions'] = array($settings['inputOptions']); 168 } 169 170 $options = array_merge($options, $settings['inputOptions']); 171 } 172 173 if (isset($settings['label'])) 174 { 175 $options['label'] = $settings['label']; 176 } 177 178 switch ($settings['type']) 179 { 180 case 'text': 181 $options['type'] = 'text'; 182 break; 183 184 case 'radio': 185 186 $options['type'] = 'radio'; 187 if (isset($settings['label'])){ 188 $attributes=array('legend'=>true); 189 $options['legend']=$settings['label']; 190 } 191 else if(!isset($settings['legend'])) $attributes=array('legend'=>false); 192 unset($options['label']); 193 break; 194 195 case 'date': 196 $options['type'] = 'date'; 197 break; 198 199 case 'select': 200 $options['type'] = 'select'; 201 $selectOptions = array(); 202 $workingModel = ClassRegistry::init($fieldModel); 203 204 if (isset($settings['selectOptions'])) 205 { 206 $selectOptions = $settings['selectOptions']; 207 } 208 209 if (isset($settings['selector'])) 210 { 211 if (!method_exists($workingModel, $settings['selector'])) 212 { 213 trigger_error 214 ( 215 __( 216 'Selector method "%s" not found in model "%s" for field "%s"!', 217 $settings['selector'], 218 $fieldModel, 219 $fieldName 220 ) 221 ); 222 return; 223 } 224 $selectorName = $settings['selector']; 225 $options['options'] = $workingModel->$selectorName($selectOptions); 226 //debug($options); 227 } 228 else 229 { 230 //debug($selectOptions); 231 //list choises in the dropdown, option 'nofilter' is added. 232 $options['options'] = $workingModel->find('list', array_merge($selectOptions, array('nofilter' => true))); 233 //if(isset($settings['options'])) $options['options']=$settings['options']; 234 } 235 236 if (!$settings['required']) 237 { 238 $options['empty'] = ''; 239 } 240 break; 241 242 case 'checkbox': 243 $options['type'] = 'checkbox'; 244 245 if (isset($options['value'])) 246 { 247 $options['checked'] = !!$options['value']; 248 unset($options['value']); 249 } 250 else if (isset($settings['default'])) 251 { 252 $options['checked'] = !!$settings['default']; 253 } 254 break; 255 256 default: 257 continue; 258 } 259 260 // if no value has been set, show the default one 261 if (!isset($options['value']) && 262 isset($settings['default']) && 263 $options['type'] != 'checkbox') 264 { 265 $options['value'] = $settings['default']; 266 } 267 268 //debug($options); 269 $viewFilterParams[] = array 270 ( 271 'name' => sprintf('%s.%s', $fieldModel, $fieldName), 272 'options' => $options, 273 'attributes'=> $attributes 274 ); 275 } 276 } 277 278 $controller->set('viewFilterParams', $viewFilterParams); 279 } 280 281 function __updatePersistence($controller, $settings) 282 { 283 if ($this->Session->check('FilterPlugin.NoPersist')) 284 { 285 $this->nopersist = $this->Session->read('FilterPlugin.NoPersist'); 286 } 287 288 if (isset($settings['nopersist'])) 289 { 290 $this->nopersist[$controller->name] = $settings['nopersist']; 291 $this->Session->write('FilterPlugin.NoPersist', $this->nopersist); 292 } 293 else if (isset($this->nopersist[$controller->name])) 294 { 295 unset($this->nopersist[$controller->name]); 296 $this->Session->write('FilterPlugin.NoPersist', $this->nopersist); 297 } 298 299 if (!empty($this->nopersist)) 300 { 301 foreach ($this->nopersist as $nopersistController => $actions) 302 { 303 if (is_string($actions)) 304 { 305 $actions = array($actions); 306 } 307 else if (is_bool($actions) && $actions == true) 308 { 309 $actions = array(); 310 } 311 312 if (empty($actions) && $controller->name != $nopersistController) 313 { 314 if ($this->Session->check(sprintf('FilterPlugin.Filters.%s', $nopersistController))) 315 { 316 $this->Session->delete(sprintf('FilterPlugin.Filters.%s', $nopersistController)); 317 continue; 318 } 319 } 320 321 foreach ($actions as $action) 322 { 323 if ($controller->name == $nopersistController && $action == $controller->action) 324 { 325 continue; 326 } 327 328 if ($this->Session->check(sprintf('FilterPlugin.Filters.%s.%s', $nopersistController, $action))) 329 { 330 $this->Session->delete(sprintf('FilterPlugin.Filters.%s.%s', $nopersistController, $action)); 331 } 332 } 333 } 334 } 335 } 336 337 function shutdown(Controller $controller){ 338 } 339}
bootstrap.php Code coverage: 0% http://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&code_coverage=true#coverage-bootstrap.php
1url('/', true)); 39 } 40 41 42 /_ 43 set true if new registrations are allowed 44 _/ 45 if (!defined("SITE_REGISTRATION")) { 46 define("SITE_REGISTRATION", true); 47 } 48 49 /_ 50 set true if you want send registration mail to user 51 _/ 52 /_ if(!defined("SEND_REGISTRATION_MAIL")) { 53 define("SEND_REGISTRATION_MAIL", true); 54 } _/ 55 if (!defined("SEND_REGISTRATION_MAIL")) { 56 define("SEND_REGISTRATION_MAIL", false); 57 } 58 59 /_ 60 set true if you want verify user's email id, site will send email confirmation link to user's email id 61 sett false you do not want verify user's email id, in this case user becomes active after registration with out email verification 62 _/ 63 /_ if(!defined("EMAIL_VERIFICATION")) { 64 define("EMAIL_VERIFICATION", true); 65 } 66 _/ 67 if (!defined("EMAIL_VERIFICATION")) { 68 define("EMAIL_VERIFICATION", false); 69 } 70 /_ 71 set email address for sending emails 72 _/ 73 if (!defined("EMAIL_FROM_ADDRESS")) { 74 define("EMAIL_FROM_ADDRESS", '[email protected]'); 75 } 76 77 /_ 78 set site name for sending emails 79 _/ 80 if (!defined("EMAIL_FROM_NAME")) { 81 define("EMAIL_FROM_NAME", 'User Management Plugin'); 82 } 83 84 /_ 85 set login redirect url, it means when user gets logged in then site will redirect to this url. 86 _/ 87 if (!defined("LOGIN_REDIRECT_URL")) { 88 //define("LOGIN_REDIRECT_URL", '/viewUser'); 89 define("LOGIN_REDIRECT_URL", '/'); 90 } 91 92 /_ 93 set logout redirect url, it means when user gets logged out then site will redirect to this url. 94 _/ 95 if (!defined("LOGOUT_REDIRECT_URL")) { 96 define("LOGOUT_REDIRECT_URL", '/login'); 97 } 98 99 /_ 100 set true if you want to enable permissions on your site 101 _/ 102 if (!defined("PERMISSIONS")) { 103 define("PERMISSIONS", true); 104 } 105 106 /_ 107 set true if you want to check permissions for admin also 108 _/ 109 if (!defined("ADMIN_PERMISSIONS")) { 110 define("ADMIN_PERMISSIONS", false); 111 } 112 113 /_ 114 set default group id here for registration 115 _/ 116 if (!defined("DEFAULT_GROUP_ID")) { 117 define("DEFAULT_GROUP_ID", 2); 118 } 119 120 /_ 121 set Admin group id here 122 _/ 123 if (!defined("ADMIN_GROUP_ID")) { 124 define("ADMIN_GROUP_ID", 1); 125 } 126 127 /_ 128 set Guest group id here 129 _/ 130 if (!defined("GUEST_GROUP_ID")) { 131 define("GUEST_GROUP_ID", 3); 132 } 133 /_ 134 set true if you want captcha support on register form 135 _/ 136 if (!defined("USE_RECAPTCHA")) { 137 define("USE_RECAPTCHA", false); 138 } 139 /_ 140 set Admin group id here 141 _/ 142 if (!defined("PRIVATE_KEY_FROM_RECAPTCHA")) { 143 define("PRIVATE_KEY_FROM_RECAPTCHA", ''); 144 } 145 /_ 146 set Admin group id here 147 _/ 148 if (!defined("PUBLIC_KEY_FROM_RECAPTCHA")) { 149 define("PUBLIC_KEY_FROM_RECAPTCHA", ''); 150 } 151 /_ 152 set login cookie name 153 */ 154 if (!defined("LOGIN_COOKIE_NAME")) { 155 define("LOGIN_COOKIE_NAME", 'UsermgmtCookie'); 156 } 157 Cache::config('UserMgmt', array( 158 'engine' => 'File', 159 'duration' => '+3 months', 160 'path' => CACHE, 161 'prefix' => 'UserMgmt_'.'myKGM_' 162 )); 163} 164?>
MockObjects.php Code coverage: 71.43% http://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&code_coverage=true#coverage-MockObjects.php
1<?php 2/** 3 CakePHP Filter Plugin 4 5 Copyright (C) 2009-3827 dr. Hannibal Lecter / lecterror 6 http://lecterror.com/ 7 8 Multi-licensed under: 9 MPL http://www.mozilla.org/MPL/MPL-1.1.html 10 LGPL http://www.gnu.org/licenses/lgpl.html 11 GPL http://www.gnu.org/licenses/gpl.html 12*/ 13 14App::uses('Behavior', 'Filter.Filtered'); 15App::uses('Controller', 'Controller'); 16 17class DocumentCategory extends CakeTestModel 18{ 19 var $name = 'DocumentCategory'; 20 var $hasMany = array('Document'); 21 22 function customSelector($options = array()) 23 { 24 $options['conditions']['DocumentCategory.title LIKE'] = '%T%'; 25 $options['nofilter'] = true; 26 27 return $this->find('list', $options); 28 } 29} 30 31class Document extends CakeTestModel 32{ 33 var $name = 'Document'; 34 var $belongsTo = array('DocumentCategory'); 35 var $hasMany = array('Item'); 36 var $hasOne = array('Metadata'); 37} 38 39class Document2 extends CakeTestModel 40{ 41 var $name = 'Document'; 42 var $alias = 'Document'; 43 var $belongsTo = array('DocumentCategory'); 44 var $hasMany = array('Item'); 45 46 var $returnValue = false; 47 48 function beforeDataFilter($query, $options) 49 { 50 return $this->returnValue; 51 } 52} 53 54class Document3 extends CakeTestModel 55{ 56 var $name = 'Document'; 57 var $alias = 'Document'; 58 var $belongsTo = array('DocumentCategory'); 59 var $hasMany = array('Item'); 60 61 var $itemToUnset = null; 62 63 function afterDataFilter($query, $options) 64 { 65 if (!is_string($this->itemToUnset)) 66 { 67 return $query; 68 } 69 70 if (isset($query['conditions'][$this->itemToUnset])) 71 { 72 unset($query['conditions'][$this->itemToUnset]); 73 } 74 75 return $query; 76 } 77} 78 79class Metadata extends CakeTestModel 80{ 81 var $name = 'Metadata'; 82 var $hasOne = array('Document'); 83} 84 85class Item extends CakeTestModel 86{ 87 var $name = 'Item'; 88 var $belongsTo = array('Document'); 89} 90 91class DocumentTestsController extends Controller 92{ 93 var $name = 'DocumentTests'; 94 95 function index() 96 { 97 } 98 99 // must override this or the tests never complete.. 100 // @TODO: mock partial? 101 function redirect() 102 { 103 } 104}
FilteredBehavior.php Code coverage: 95.59% http://localhost/myKGM/webroot/test.php?plugin=Filter&case=All&code_coverage=true#coverage-FilteredBehavior.php
2013/6/17 dr. Hannibal Lecter [email protected]
Hi there,
Would it be possible for you to create a small unit test for this? I'm curious to see what kind of data will recreate this bug.
Reply to this email directly or view it on GitHubhttps://github.com/lecterror/cakephp-filter-plugin/issues/10#issuecomment-19577541 .
I ran the tests with Cake 2.3.6 and PHP 5.3.3 (unfortunately, no PHP 5.4.x at the moment), and all the tests are passing on my machine.
Can you confirm that you are running unmodified version of the plugin?
This may be happening because of the PHP difference, but it's difficult to tell without a real test.
If you still have the will to write a test, you can look at the existing tests in the plugin, and simply copy and modify one of them to reproduce the error you're getting. It's either that, or waiting until I upgrade my OS and test it myself (which may take a while!).