diff --git a/src/DonationForms/Repositories/DonationFormRepository.php b/src/DonationForms/Repositories/DonationFormRepository.php index 4fa3babc0b..bae1625f7a 100644 --- a/src/DonationForms/Repositories/DonationFormRepository.php +++ b/src/DonationForms/Repositories/DonationFormRepository.php @@ -265,6 +265,7 @@ private function validateProperties(DonationForm $donationForm) } /** + * @unreleased Prevent returning forms without the "formBuilderSettings" and "formBuilderFields" meta keys * @since 3.0.0 * * @return ModelQueryBuilder @@ -288,6 +289,8 @@ public function prepareQuery(): ModelQueryBuilder 'form_id', ...DonationFormMetaKeys::getColumnsForAttachMetaQuery() ) + ->whereIsNotNull("give_formmeta_attach_meta_settings.meta_value") + ->whereIsNotNull("give_formmeta_attach_meta_fields.meta_value") ->where('post_type', 'give_forms'); } diff --git a/tests/Unit/DonationForms/Repositories/TestDonationFormRepository.php b/tests/Unit/DonationForms/Repositories/TestDonationFormRepository.php index c476a602ae..ce3ae49e23 100644 --- a/tests/Unit/DonationForms/Repositories/TestDonationFormRepository.php +++ b/tests/Unit/DonationForms/Repositories/TestDonationFormRepository.php @@ -376,4 +376,34 @@ public function testShouldGetTotalRevenueFromSubscriptions(): void $this->assertEquals($amount->formatToDecimal(), $this->repository->getTotalInitialAmountFromSubscriptions($form->id)); } + + /** + * @unreleased + * + * @throws Exception + */ + public function testShouldNotReturnDonationFormWithoutSettingsMetaKey() + { + $donationForm = $this->modelFactory->create(); + + give()->form_meta->delete_meta($donationForm->id, 'formBuilderSettings'); + $donationFormFromDatabase = $this->repository->getById($donationForm->id); + + $this->assertNull($donationFormFromDatabase); + } + + /** + * @unreleased + * + * @throws Exception + */ + public function testShouldNotReturnDonationFormWithoutFieldsMetaKey() + { + $donationForm = $this->modelFactory->create(); + + give()->form_meta->delete_meta($donationForm->id, 'formBuilderFields'); + $donationFormFromDatabase = $this->repository->getById($donationForm->id); + + $this->assertNull($donationFormFromDatabase); + } }