Commit 6199d05b authored by efalcy's avatar efalcy

dev#93032 : add search custom fields agenda

parent d859c91f
Pipeline #7659 passed with stage
in 38 minutes and 29 seconds
......@@ -66,19 +66,23 @@ class Class_RendezVous_SearchCriteriaAll extends Class_SearchCriteria {
protected function _buildSearchParams() {
$this->_adoptSearchParams($this->_rendez_vous_criteria);
return $this
->_adoptSearchParams($this->_rendez_vous_criteria)
->_buildAgendaParams();
}
$agenda_array = $this->_agenda_criteria->findPage(1, static::PAGE_NO_LIMIT);
$agendas = new Storm_Model_Collection($agenda_array);
$this->addParam('group_id', $agendas->collect('id')->getArrayCopy());
return $this;
}
protected function _buildAgendaParams() {
if (!$this->_agenda_criteria->isFiltering())
return $this;
$agendas = new Storm_Model_Collection($this->_agenda_criteria
->findPage(1, static::PAGE_NO_LIMIT));
protected function _adoptSearchParams($other) {
$other->_buildSearchParams();
$this->_search_params = $other->_search_params;
$this->_has_no_result = $other->_has_no_result;
if ($agendas->isEmpty())
return $this->hasNoResult();
$this->addParam('group_id', $agendas->collect('id')->getArrayCopy());
return $this;
}
}
......@@ -147,6 +147,12 @@ abstract class Class_SearchCriteria {
}
public function isFiltering() {
$this->_buildSearchParams();
return $this->_has_no_result || $this->_search_params;
}
public function describeOn($view) {
return array_filter((new Storm_Collection($this->_criteria))
->collect(function($c) use($view) { return $c->describeOn($view); })
......@@ -158,5 +164,16 @@ abstract class Class_SearchCriteria {
$model = Class_CustomField_Model::getModel($class_name);
foreach($model->getFields() as $field)
$this->_criteria[] = Class_SearchCriteria_CustomField::newWith($params, $field);
return $this;
}
protected function _adoptSearchParams($other) {
$other->_buildSearchParams();
$this->_search_params = $other->_search_params;
$this->_has_no_result = $other->_has_no_result;
return $this;
}
}
......@@ -1108,7 +1108,6 @@ class UsergroupAgendaAdminSearchCustomFieldsMultiTest
class UsergroupAgendaAdminSearchCustomFieldsSelectTest
extends UsergroupAgendaAdminSearchCustomFieldsActionTestCase {
public function setUp() {
parent::setUp();
$this->dispatch($this->urlWithParams([])
......@@ -1139,6 +1138,47 @@ class UsergroupAgendaAdminSearchCustomFieldsSelectTest
class UsergroupAgendaAdminSearchCustomFieldsSelectWithoutResultTest
extends UsergroupAgendaAdminSearchCustomFieldsActionTestCase {
public function setUp() {
parent::setUp();
Class_CustomField_Value::whenCalled('findAllBy')->answers([]);
$this->dispatch($this->urlWithParams([])
. '&search_field_3[]=fromage&search_field_3[]=dessert&search_field_3[]=l\'association');
}
public function values() {
return [['fromage'], ['dessert'], ['l\'association']];
}
/**
* @test
* @dataProvider values
*/
public function inputValueShouldBeChecked($value) {
$this->assertXPath('//input[@name="search_field_3[]"][@value="' . $value . '"][@checked]');
}
/** @test */
public function queryalueShouldBeFromageDessertLassociation() {
$this->assertEquals(['fromage','dessert','l\'association'],
$this->lastCustomFieldValueClause('value'));
}
/** @test */
public function rendezVousShouldNotBeQueried() {
$this->assertTrue(Class_RendezVous::methodHasNotBeenCalled('findAllBy'));
}
}
class UsergroupAgendaAdminSearchCustomFieldDateRangeTest
extends UsergroupAgendaAdminSearchCustomFieldsActionTestCase {
......@@ -1200,6 +1240,37 @@ class UsergroupAgendaAdminSearchCustomFieldOfAgendaTest
class UsergroupAgendaAdminSearchCustomFieldOfAgendaWithoutResultTest
extends UsergroupAgendaAdminSearchCustomFieldsActionTestCase {
public function setUp() {
parent::setUp();
Class_CustomField_Value::whenCalled('findAllBy')->answers([]);
$this->dispatchWithQuery(['search_field_5' => 'nord']);
}
/** @test */
public function inputValueShouldBeNord() {
$this->assertXPath('//input[@name="search_field_5"][@value="nord"]');
}
/** @test */
public function lastValueQueryShouldBeLikeNord() {
$this->assertEquals('value like "%nord%"', $this->lastCustomFieldValueClause('where'));
}
/** @test */
public function rendezVousShouldNotBeQueried() {
$this->assertTrue(Class_RendezVous::methodHasNotBeenCalled('findAllBy'));
}
}
class UsergroupAgendaAdminExportActionTest
extends UsergroupAgendaAdminModoPortailLoggedTestCase {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment