From 57b75c5c63a7fec56a62fc531e5e1569fa0f442c Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 7 Oct 2019 15:09:50 +0200 Subject: [PATCH] dev/financial#72 Make is_template=0 the default for api get requests. We are planning on adding is_template to the civicrm_contribution table - following the precedent from event. By default it is NOT desirable to get template entities returned in a get request - this fixes that at the generic apiv4 level and means that it will be a default filter when present --- .../Provider/GetActionDefaultsProvider.php | 5 ++ tests/phpunit/api/v4/Action/EventTest.php | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/phpunit/api/v4/Action/EventTest.php diff --git a/Civi/Api4/Service/Spec/Provider/GetActionDefaultsProvider.php b/Civi/Api4/Service/Spec/Provider/GetActionDefaultsProvider.php index f532e35609..58c59e47f6 100644 --- a/Civi/Api4/Service/Spec/Provider/GetActionDefaultsProvider.php +++ b/Civi/Api4/Service/Spec/Provider/GetActionDefaultsProvider.php @@ -56,6 +56,11 @@ class GetActionDefaultsProvider implements Generic\SpecProviderInterface { if ($isTestField) { $isTestField->setDefaultValue('0'); } + + $isTemplateField = $spec->getFieldByName('is_template'); + if ($isTemplateField) { + $isTemplateField->setDefaultValue('0'); + } } /** diff --git a/tests/phpunit/api/v4/Action/EventTest.php b/tests/phpunit/api/v4/Action/EventTest.php new file mode 100644 index 0000000000..052629c6f0 --- /dev/null +++ b/tests/phpunit/api/v4/Action/EventTest.php @@ -0,0 +1,53 @@ +setValues(['template_title' => 'Big Event', 'is_template' => 1, 'start_date' => 'now', 'event_type_id' => 'Meeting'])->execute(); + Event::create()->setValues(['title' => 'Bigger Event', 'start_date' => 'now', 'event_type_id' => 'Meeting'])->execute(); + $this->assertEquals(1, Event::get()->selectRowCount()->execute()->count()); + } + +} -- 2.25.1