diff --git a/languages/onoffice-for-wp-websites-de_DE.mo b/languages/onoffice-for-wp-websites-de_DE.mo index 6ca46cf0f..cda39afe2 100644 Binary files a/languages/onoffice-for-wp-websites-de_DE.mo and b/languages/onoffice-for-wp-websites-de_DE.mo differ diff --git a/languages/onoffice-for-wp-websites-de_DE.po b/languages/onoffice-for-wp-websites-de_DE.po index 3a111fe40..85be615ab 100644 --- a/languages/onoffice-for-wp-websites-de_DE.po +++ b/languages/onoffice-for-wp-websites-de_DE.po @@ -840,6 +840,12 @@ msgstr "Pflichtangabe" #: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:401 #: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:415 +#: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:345 +msgid "Contact Type of New Address" +msgstr "Kontaktart der neuen Adresse" + +#: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:390 +#: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:404 msgid "Add language" msgstr "Sprache hinzufügen" diff --git a/plugin/DataFormConfiguration/DataFormConfiguration.php b/plugin/DataFormConfiguration/DataFormConfiguration.php index 13cbeeefe..54bf152af 100644 --- a/plugin/DataFormConfiguration/DataFormConfiguration.php +++ b/plugin/DataFormConfiguration/DataFormConfiguration.php @@ -67,6 +67,9 @@ class DataFormConfiguration /** @var bool */ private $_showEstateContext = false; + /** @var bool */ + private $_contactType = ''; + /** * * Override to set default fields for new, empty forms @@ -128,7 +131,9 @@ public function addAvailableOptionsField(string $availableOptionsField) public function setShowEstateContext(bool $showEstateContext) { $this->_showEstateContext = $showEstateContext; } - + /** @param string $contactTypeField */ + public function setContactTypeField(string $contactTypeField) + { $this->_contactType = $contactTypeField; } /** * * @param string $input @@ -182,4 +187,8 @@ public function setId(int $id) /** @return bool */ public function getShowEstateContext(): bool { return $this->_showEstateContext; } + + /** @return string */ + public function getContactType(): string + { return $this->_contactType; } } diff --git a/plugin/DataFormConfiguration/DataFormConfigurationFactory.php b/plugin/DataFormConfiguration/DataFormConfigurationFactory.php index 37ed583b5..9c9dafac6 100644 --- a/plugin/DataFormConfiguration/DataFormConfigurationFactory.php +++ b/plugin/DataFormConfiguration/DataFormConfigurationFactory.php @@ -269,6 +269,7 @@ private function configureContact(array $row, DataFormConfigurationContact $pCon $pConfig->setCheckDuplicateOnCreateAddress((bool)$row['checkduplicates']); $pConfig->setNewsletterCheckbox((bool)$row['newsletter']); $pConfig->setShowEstateContext((bool)$row['show_estate_context']); + $pConfig->setContactTypeField($row['contact_type'] ?? ''); } @@ -320,6 +321,7 @@ private function configureOwner(array $row, DataFormConfigurationOwner $pConfig) $pConfig->setPages($row['pages']); $pConfig->setCreateOwner((bool)$row['createaddress']); $pConfig->setCheckDuplicateOnCreateAddress((bool)$row['checkduplicates']); + $pConfig->setContactTypeField($row['contact_type'] ?? ''); } @@ -336,6 +338,7 @@ private function configureInterest(array $row, DataFormConfigurationInterest $pC $pConfig->setSubject($row['subject']); $pConfig->setCreateInterest((bool)$row['createaddress']); $pConfig->setCheckDuplicateOnCreateAddress($row['checkduplicates']); + $pConfig->setContactTypeField($row['contact_type'] ?? ''); } diff --git a/plugin/Form/FormAddressCreator.php b/plugin/Form/FormAddressCreator.php index dd0941a61..039278e26 100644 --- a/plugin/Form/FormAddressCreator.php +++ b/plugin/Form/FormAddressCreator.php @@ -68,10 +68,13 @@ public function __construct( * @throws NotFoundException */ public function createOrCompleteAddress( - FormData $pFormData, bool $mergeExisting = false): int + FormData $pFormData, bool $mergeExisting = false, string $contactType = ''): int { $requestParams = $this->getAddressDataForApiCall($pFormData); $requestParams['checkDuplicate'] = $mergeExisting; + if (!empty($contactType)) { + $requestParams['ArtDaten'] = $contactType; + } $pApiClientAction = new APIClientActionGeneric ($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_CREATE, 'address'); diff --git a/plugin/FormPostContact.php b/plugin/FormPostContact.php index 6c908f6bb..4a5fe907e 100644 --- a/plugin/FormPostContact.php +++ b/plugin/FormPostContact.php @@ -134,8 +134,9 @@ private function createAddress(FormData $pFormData) { $pFormConfig = $pFormData->getDataFormConfiguration(); $checkDuplicate = $pFormConfig->getCheckDuplicateOnCreateAddress(); + $contactType = $pFormConfig->getContactType(); $addressId = $this->_pFormPostContactConfiguration->getFormAddressCreator() - ->createOrCompleteAddress($pFormData, $checkDuplicate); + ->createOrCompleteAddress($pFormData, $checkDuplicate, $contactType); if (!$this->_pFormPostContactConfiguration->getNewsletterAccepted()) { // No subscription for newsletter, which is ok @@ -166,6 +167,8 @@ private function createAddress(FormData $pFormData) private function sendContactRequest(FormData $pFormData, string $recipient = '', $subject = null) { + $pFormConfig = $pFormData->getDataFormConfiguration(); + $contactType = $pFormConfig->getContactType(); $values = $pFormData->getValues(); $pWPQuery = $this->_pFormPostContactConfiguration->getWPQueryWrapper()->getWPQuery(); $pWPWrapper = $this->_pFormPostContactConfiguration->getWPWrapper(); @@ -180,6 +183,9 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '', 'estatedata' => ["objekttitel", "ort", "plz", "land"], 'estateurl' => home_url($pWPWrapper->getRequest()), ]; + if (isset($addressData['ArtDaten']) && !empty($contactType)) { + $requestParams['addressdata']['ArtDaten'] = $contactType; + } if (isset($addressData['newsletter'])) { $requestParams['addressdata']['newsletter_aktiv'] = $this->_pFormPostContactConfiguration ->getNewsletterAccepted(); @@ -188,7 +194,6 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '', if ($recipient !== '') { $requestParams['recipient'] = $recipient; } - $pSDKWrapper = $this->_pFormPostContactConfiguration->getSDKWrapper(); $pAPIClientAction = new APIClientActionGeneric ($pSDKWrapper, onOfficeSDK::ACTION_ID_DO, 'contactaddress'); @@ -199,4 +204,4 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '', throw new ApiClientException($pAPIClientAction); } } -} \ No newline at end of file +} diff --git a/plugin/FormPostInterest.php b/plugin/FormPostInterest.php index aeb60cc9b..8909efc01 100644 --- a/plugin/FormPostInterest.php +++ b/plugin/FormPostInterest.php @@ -83,9 +83,10 @@ protected function analyseFormContentByPrefix(FormData $pFormData) try { if ( $pFormConfiguration->getCreateInterest() ) { $checkduplicate = $pFormConfiguration->getCheckDuplicateOnCreateAddress(); + $contactType = $pFormConfiguration->getContactType(); $addressId = $this->_pFormPostInterestConfiguration->getFormAddressCreator() ->createOrCompleteAddress( $pFormData, - $checkduplicate ); + $checkduplicate, $contactType); $this->createSearchcriteria( $pFormData, $addressId ); } } finally { @@ -192,4 +193,4 @@ private function createSearchcriteria(FormData $pFormData, int $addressId) throw new ApiClientException($pApiClientAction); } } -} \ No newline at end of file +} diff --git a/plugin/FormPostOwner.php b/plugin/FormPostOwner.php index 7482d07fb..e5f3e3891 100644 --- a/plugin/FormPostOwner.php +++ b/plugin/FormPostOwner.php @@ -91,9 +91,10 @@ protected function analyseFormContentByPrefix(FormData $pFormData) try { if ( $pDataFormConfiguration->getCreateOwner() ) { $checkduplicate = $pDataFormConfiguration->getCheckDuplicateOnCreateAddress(); + $contactType = $pDataFormConfiguration->getContactType(); $addressId = $this->_pFormPostOwnerConfiguration->getFormAddressCreator() ->createOrCompleteAddress( $pFormData, - $checkduplicate ); + $checkduplicate, $contactType); $estateData = $this->getEstateData(); $estateId = $this->createEstate( $estateData ); $this->createOwnerRelation( $estateId, $addressId ); @@ -244,4 +245,4 @@ private function sendContactRequest(string $recipient, int $estateId, array $est throw new ApiClientException($pApiClientAction); } } -} \ No newline at end of file +} diff --git a/plugin/Gui/AdminPageFormSettingsContact.php b/plugin/Gui/AdminPageFormSettingsContact.php index 5b5ecb85e..e0171eb56 100644 --- a/plugin/Gui/AdminPageFormSettingsContact.php +++ b/plugin/Gui/AdminPageFormSettingsContact.php @@ -77,6 +77,9 @@ class AdminPageFormSettingsContact /** @var bool */ private $_showEstateContextCheckbox = false; + /** @var bool */ + private $_showContactTypeSelect = false; + /** * @@ -141,6 +144,11 @@ protected function buildForms() $pFormModelFormSpecific->addInputModel($pInputModel); } + if ($this->_showContactTypeSelect) { + $pInputModelContactType = $pFormModelBuilder->createInputModelContactType(); + $pFormModelFormSpecific->addInputModel($pInputModelContactType); + } + if ($this->_showCheckDuplicatesInterestOwner) { $pInputModel = $pInputModelBuilder->build(InputModelDBFactoryConfigForm::INPUT_FORM_CHECKDUPLICATES_INTEREST_OWNER); $pFormModelFormSpecific->addInputModel($pInputModel); @@ -277,6 +285,10 @@ public function setShowGeoPositionSettings(bool $showGeoPositionSettings) public function setShowEstateContextCheckbox(bool $showEstateContextCheckbox) { $this->_showEstateContextCheckbox = $showEstateContextCheckbox; } + /** @param bool $showContactTypeSelect */ + public function setShowContactTypeSelect(bool $showContactTypeSelect) + { $this->_showContactTypeSelect = $showContactTypeSelect; } + /** * @param bool $showCreateInterest */ diff --git a/plugin/Gui/AdminPageFormSettingsMain.php b/plugin/Gui/AdminPageFormSettingsMain.php index 1def5bf62..3ab9e0eea 100644 --- a/plugin/Gui/AdminPageFormSettingsMain.php +++ b/plugin/Gui/AdminPageFormSettingsMain.php @@ -121,6 +121,7 @@ private function configureAdminPage(AdminPageFormSettingsBase $pAdminPage, strin $pAdminPage->setShowCreateInterest(true); $pAdminPage->setShowCheckDuplicatesInterestOwner(true); $pAdminPage->setShowGeoPositionSettings(true); + $pAdminPage->setShowContactTypeSelect(true); break; case Form::TYPE_OWNER: /* @var $pAdminPage AdminPageFormSettingsInquiry */ @@ -129,6 +130,7 @@ private function configureAdminPage(AdminPageFormSettingsBase $pAdminPage, strin $pAdminPage->setShowCreateOwner(true); $pAdminPage->setShowCheckDuplicatesInterestOwner(true); $pAdminPage->setShowMessageInput(true); + $pAdminPage->setShowContactTypeSelect(true); break; case Form::TYPE_CONTACT: /* @var $pAdminPage AdminPageFormSettingsContact */ @@ -138,6 +140,7 @@ private function configureAdminPage(AdminPageFormSettingsBase $pAdminPage, strin $pAdminPage->setShowMessageInput(true); $pAdminPage->setShowNewsletterCheckbox(true); $pAdminPage->setShowEstateContextCheckbox(true); + $pAdminPage->setShowContactTypeSelect(true); break; case Form::TYPE_APPLICANT_SEARCH: /* @var $pAdminPage AdminPageFormSettingsApplicantSearch */ diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index da281b08d..eb4df3356 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -34,7 +34,7 @@ class DatabaseChanges implements DatabaseChangesInterface { /** @var int */ - const MAX_VERSION = 22; + const MAX_VERSION = 23; /** @var WPOptionWrapperBase */ private $_pWpOption; @@ -169,6 +169,11 @@ public function install() $dbversion = 22; } + if ($dbversion == 22) { + dbDelta($this->getCreateQueryForms()); + $dbversion = 23; + } + $this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true); } @@ -280,13 +285,13 @@ private function getCreateQueryForms() `radius` INT( 10 ) NULL DEFAULT NULL, `geo_order` VARCHAR( 255 ) NOT NULL DEFAULT 'street,zip,city,country,radius', `show_estate_context` tinyint(1) NOT NULL DEFAULT '0', + `contact_type` varchar(255) NULL DEFAULT NULL, PRIMARY KEY (`form_id`), UNIQUE KEY `name` (`name`) ) $charsetCollate;"; return $sql; } - /** * * @return string @@ -599,7 +604,6 @@ private function deleteCommentFieldApplicantSearchForm() } } - /** * */ diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php b/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php index b0f3b1d12..be68ac836 100644 --- a/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php +++ b/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php @@ -26,8 +26,12 @@ use DI\DependencyException; use DI\NotFoundException; use Exception; +use onOffice\SDK\onOfficeSDK; +use onOffice\WPlugin\API\APIClientCredentialsException; use onOffice\WPlugin\DataFormConfiguration\DataFormConfiguration; use onOffice\WPlugin\DataFormConfiguration\DataFormConfigurationFactory; +use onOffice\WPlugin\Field\Collection\FieldLoaderGeneric; +use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilder; use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilderShort; use onOffice\WPlugin\Model\FormModel; use onOffice\WPlugin\Model\InputModel\InputModelDBFactory; @@ -334,6 +338,45 @@ public function createInputModelResultLimit() return $pInputModelFormLimitResult; } + /** + * @return InputModelDB + */ + public function createInputModelContactType() + { + $labelContactType = __('Contact Type of New Address', 'onoffice-for-wp-websites'); + $pInputModelFormContactType = $this->getInputModelDBFactory()->create + (InputModelDBFactoryConfigForm::INPUT_FORM_CONTACT_TYPE, $labelContactType); + $field = $pInputModelFormContactType->getField(); + $pInputModelFormContactType->setHtmlType(InputModelOption::HTML_TYPE_SELECT); + $availableContactType = array('' => 'No contact type') + $this->getDataContactType(onOfficeSDK::MODULE_ADDRESS); + $pInputModelFormContactType->setValuesAvailable($availableContactType); + $selectedValue = $this->getValue($field); + $pInputModelFormContactType->setValue($selectedValue); + + return $pInputModelFormContactType; + } + + public function getDataContactType($module) + { + try { + $pFieldLoader = $this->_pContainer->get(FieldLoaderGeneric::class); + $pFieldCollectionAddressEstate = $this->_pContainer->get(FieldsCollectionBuilder::class) + ->buildFieldsCollection($pFieldLoader); + $fields = $pFieldCollectionAddressEstate->getFieldsByModule($module); + $result = []; + if (!empty($fields['ArtDaten']->getPermittedvalues())) { + foreach ($fields['ArtDaten']->getPermittedvalues() as $field => $type) { + $result[$field] = !empty($type) ? $type: $field; + } + } + + return $result; + } catch (APIClientCredentialsException $pCredentialsException) { + return []; + } + + } + /** * @return InputModelDB */ diff --git a/plugin/Model/InputModel/InputModelDBFactoryConfigForm.php b/plugin/Model/InputModel/InputModelDBFactoryConfigForm.php index bb733ecec..ced30c5d4 100644 --- a/plugin/Model/InputModel/InputModelDBFactoryConfigForm.php +++ b/plugin/Model/InputModel/InputModelDBFactoryConfigForm.php @@ -89,6 +89,9 @@ class InputModelDBFactoryConfigForm /** */ const INPUT_FORM_ESTATE_CONTEXT_AS_HEADING = 'show_estate_context'; + /** */ + const INPUT_FORM_CONTACT_TYPE = 'contactType'; + /** @var array */ private $_inputConfig = [ @@ -152,6 +155,10 @@ class InputModelDBFactoryConfigForm self::KEY_TABLE => 'oo_plugin_forms', self::KEY_FIELD => 'show_estate_context', ], + self::INPUT_FORM_CONTACT_TYPE => [ + self::KEY_TABLE => 'oo_plugin_forms', + self::KEY_FIELD => 'contact_type', + ], InputModelDBFactory::INPUT_FIELD_CONFIG => [ self::KEY_TABLE => 'oo_plugin_form_fieldconfig', diff --git a/tests/TestClassDataFormConfigurationFactory.php b/tests/TestClassDataFormConfigurationFactory.php index 73a9c8b33..00f4d889f 100644 --- a/tests/TestClassDataFormConfigurationFactory.php +++ b/tests/TestClassDataFormConfigurationFactory.php @@ -362,6 +362,7 @@ private function getBasicFieldsArray(int $formId, string $formType): array 'individual_fieldname' => '0', 'availableOptions' => '0', 'required' => '1', + 'contact_type' => '', ], [ 'form_fieldconfig_id' => '2', @@ -373,6 +374,7 @@ private function getBasicFieldsArray(int $formId, string $formType): array 'individual_fieldname' => '0', 'availableOptions' => '0', 'required' => '1', + 'contact_type' => '', ], [ 'form_fieldconfig_id' => '3', @@ -384,6 +386,7 @@ private function getBasicFieldsArray(int $formId, string $formType): array 'individual_fieldname' => '0', 'availableOptions' => '1', 'required' => '0', + 'contact_type' => '', ], ]; @@ -436,6 +439,7 @@ private function getBaseRow(int $formId, string $formType): array 'newsletter' => '1', 'availableOptions' => '1', 'show_estate_context' => '0', + 'contact_type' => '', ]; } } diff --git a/tests/TestClassDatabaseChanges.php b/tests/TestClassDatabaseChanges.php index 016d6ac9d..9c904fff7 100644 --- a/tests/TestClassDatabaseChanges.php +++ b/tests/TestClassDatabaseChanges.php @@ -111,7 +111,7 @@ public function testInstall(): array $this->assertGreaterThanOrEqual(self::NUM_NEW_TABLES, count($this->_createQueries)); $dbversion = $this->_pDbChanges->getDbVersion(); - $this->assertEquals(22, $dbversion); + $this->assertEquals(23, $dbversion); return $this->_createQueries; } @@ -191,7 +191,7 @@ public function testDeleteCommentFieldApplicantSearchForm() */ public function testMaxVersion() { - $this->assertEquals(22, DatabaseChanges::MAX_VERSION); + $this->assertEquals(23, DatabaseChanges::MAX_VERSION); } diff --git a/tests/TestClassFormAddressCreator.php b/tests/TestClassFormAddressCreator.php index 472ea3170..c11c5b621 100644 --- a/tests/TestClassFormAddressCreator.php +++ b/tests/TestClassFormAddressCreator.php @@ -153,6 +153,14 @@ public function testGetAddressDataForEmail() $this->assertEquals($expectedValues, $this->_pSubject->getAddressDataForEmail($pFormData)); } + public function testCreateOrCompleteAddressWithContactType() + { + $this->configureSDKWrapperMockerForAddressCreationWithContactType(1); + $pFormData = $this->createFormData(); + $result = $this->_pSubject->createOrCompleteAddress($pFormData, false, 'Admin'); + $this->assertEquals(1, $result); + } + /** * @@ -171,6 +179,30 @@ private function createFormData(): FormData return $pFormData; } + /** + * + */ + + private function configureSDKWrapperMockerForAddressCreationWithContactType(int $id) + { + $response = [ + 'actionid' => 'urn:onoffice-de-ns:smart:2.5:smartml:action:create', + 'resourceid' => '', + 'resourcetype' => 'address', + 'cacheable' => false, + 'identifier' => '', + 'data' => [ + 'meta' => ['cntabsolute' => null], + 'records' => [ + ['id' => $id, 'type' => 'address', 'elements' => []], + ], + ], + 'status' => ['errorcode' => 0, 'message' => 'OK'], + ]; + + $this->addCreateAddressResponseToSKDWrapperWithContactType($response); + } + /** * @@ -211,4 +243,14 @@ private function addCreateAddressResponseToSKDWrapper(array $response) 'checkDuplicate' => false ], null, $response); } + + private function addCreateAddressResponseToSKDWrapperWithContactType(array $response) + { + $this->_pSDKWrapper->addResponseByParameters(onOfficeSDK::ACTION_ID_CREATE, 'address', '', [ + 'testaddressfield1varchar' => 'testValue', + 'testaddressfield1multiselect' => ['hut','tut'], + 'checkDuplicate' => false, + 'ArtDaten' => 'Admin' + ], null, $response); + } } diff --git a/tests/TestClassFormModelBuilderDBForm.php b/tests/TestClassFormModelBuilderDBForm.php index c6e3f57f4..af9a178e4 100644 --- a/tests/TestClassFormModelBuilderDBForm.php +++ b/tests/TestClassFormModelBuilderDBForm.php @@ -23,16 +23,24 @@ namespace onOffice\tests; +use DI\Container; +use DI\ContainerBuilder; +use onOffice\SDK\onOfficeSDK; +use onOffice\WPlugin\API\APIClientCredentialsException; +use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilder; use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBForm; use onOffice\WPlugin\Model\InputModel\InputModelDBFactory; use onOffice\WPlugin\Model\InputModel\InputModelDBFactoryConfigForm; use onOffice\WPlugin\Model\InputModelDB; +use onOffice\WPlugin\Types\Field; +use onOffice\WPlugin\Types\FieldsCollection; use WP_UnitTestCase; class TestClassFormModelBuilderDBForm extends WP_UnitTestCase { - + /** @var Container */ + private $_pContainer; /** @var InputModelDBFactory */ private $_pInputModelFactoryDBEntry; @@ -43,9 +51,11 @@ class TestClassFormModelBuilderDBForm public function prepare() { $this->_pInputModelFactoryDBEntry = new InputModelDBFactory(new InputModelDBFactoryConfigForm); + $pContainerBuilder = new ContainerBuilder; + $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH); + $this->_pContainer = $pContainerBuilder->build(); } - /** * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBForm::createInputModelRecipientContactForm */ @@ -64,5 +74,82 @@ public function testCreateInputModelRecipientContactForm() $this->assertEquals($pInputModelDB->getHtmlType(), 'text'); } + /** + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBForm::createInputModelContactType + */ + public function testCreateInputModelContactType() + { + $pInstance = $this->getMockBuilder(FormModelBuilderDBForm::class) + ->disableOriginalConstructor() + ->setMethods(['getInputModelDBFactory', 'getValue', 'getDataContactType']) + ->getMock(); + + $pInstance->method('getInputModelDBFactory')->willReturn($this->_pInputModelFactoryDBEntry); + $pInstance->method('getValue')->willReturn('1'); + $pInstance->method('getDataContactType')->willReturn([]); + + $pInputModelDB = $pInstance->createInputModelContactType(); + $this->assertInstanceOf(InputModelDB::class, $pInputModelDB); + $this->assertEquals($pInputModelDB->getHtmlType(), 'select'); + } + + /** + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBForm::getDataContactType + */ + public function testGetDataContactType() + { + $fieldCollectionBuilder = $this->getMockBuilder(FieldsCollectionBuilder::class) + ->disableOriginalConstructor() + ->setMethods([ 'buildFieldsCollection']) + ->getMock(); + + $pFieldsCollection = $this->getMockBuilder(FieldsCollection::class) + ->disableOriginalConstructor() + ->setMethods(['getFieldsByModule']) + ->getMock(); -} \ No newline at end of file + $mockData = [ + 'test' => 'abc' + ]; + $mockField = new Field('ArtDaten', onOfficeSDK::MODULE_ADDRESS, 'Type of contact'); + $mockField->setPermittedvalues($mockData); + + $pFieldsCollection->method('getFieldsByModule')->willReturn(['ArtDaten' => $mockField]); + + $fieldCollectionBuilder->method('buildFieldsCollection')->willReturn($pFieldsCollection); + + + + $this->_pContainer->set(FieldsCollectionBuilder::class, $fieldCollectionBuilder); + + $pInstance = $this->_pContainer->get(FormModelBuilderDBForm::class); + + $result = $pInstance->getDataContactType('address'); + + $this->assertEquals($mockData, $result); + } + + /** + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBForm::getDataContactType + */ + public function testGetDataContactTypeThrowException() + { + $fieldCollectionBuilder = $this->getMockBuilder(FieldsCollectionBuilder::class) + ->disableOriginalConstructor() + ->setMethods([ 'buildFieldsCollection']) + ->getMock(); + + $ex = $this->_pContainer->get(APIClientCredentialsException::class); + + + $fieldCollectionBuilder->method('buildFieldsCollection')->will($this->throwException($ex)); + + $this->_pContainer->set(FieldsCollectionBuilder::class, $fieldCollectionBuilder); + + $pInstance = $this->_pContainer->get(FormModelBuilderDBForm::class); + + $result = $pInstance->getDataContactType('address'); + + $this->assertEquals([], $result); + } +} diff --git a/tests/TestClassFormPostContact.php b/tests/TestClassFormPostContact.php index 6fca29bbe..77bbe9b5e 100644 --- a/tests/TestClassFormPostContact.php +++ b/tests/TestClassFormPostContact.php @@ -429,6 +429,7 @@ private function getNewDataFormConfiguration(): DataFormConfigurationContact $pDataFormConfiguration->setFormName('contactForm'); $pDataFormConfiguration->setSubject('¡A new Contact!'); $pDataFormConfiguration->setRequiredFields(['Vorname', 'Name', 'Email']); + $pDataFormConfiguration->setContactTypeField(''); $this->mockNewsletterCall(); return $pDataFormConfiguration;