diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62c98605..4dd72637 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,11 +35,14 @@ jobs: with: fetch-depth: 1 + - name: Parse $MODULE_NAME from composer.json + run: echo "MODULE_NAME=$(cat composer.json | jq -r .name | awk -F/ '{print $NF}')" >> $GITHUB_ENV + - name: Set Drupal root run: echo "DRUPAL_ROOT=$HOME/drupal" >> $GITHUB_ENV - name: Set module folder - run: echo "MODULE_FOLDER=$DRUPAL_ROOT/modules/contrib/${{ secrets.MODULE_NAME }}" >> $GITHUB_ENV + run: echo "MODULE_FOLDER=$DRUPAL_ROOT/modules/contrib/$MODULE_NAME" >> $GITHUB_ENV - name: Clone drupal run: git clone --depth 1 --branch "$DRUPAL_CORE_VERSION" http://git.drupal.org/project/drupal.git/ $DRUPAL_ROOT @@ -50,7 +53,7 @@ jobs: composer config platform.php ${{ matrix.php-versions }} composer config repositories.4 composer https://repository.drupal.hel.ninja/ composer config repositories.5 path $GITHUB_WORKSPACE - composer require drupal/${{ secrets.MODULE_NAME }} -W + composer require drupal/$MODULE_NAME -W composer run-script drupal-phpunit-upgrade composer require "drush/drush ^11.0" composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true @@ -61,7 +64,7 @@ jobs: run: | cd $DRUPAL_ROOT php -d sendmail_path=$(which true); vendor/bin/drush --yes -v site-install minimal --db-url="$SIMPLETEST_DB" - vendor/bin/drush en ${{ secrets.MODULE_NAME }} -y + vendor/bin/drush en $MODULE_NAME -y - name: Run PHPCS run: | diff --git a/config/language/fi/views.view.unit_services.yml b/config/language/fi/views.view.unit_services.yml index 948e192c..d128c043 100644 --- a/config/language/fi/views.view.unit_services.yml +++ b/config/language/fi/views.view.unit_services.yml @@ -18,4 +18,3 @@ display: items_per_page_options_all_label: '- Kaikki -' views_infinite_scroll: button_text: 'Lataa lisää palveluita' - diff --git a/config/schema/helfi_tpr.schema.yml b/config/schema/helfi_tpr.schema.yml index 1a32fa01..8d98767d 100644 --- a/config/schema/helfi_tpr.schema.yml +++ b/config/schema/helfi_tpr.schema.yml @@ -40,6 +40,21 @@ field.formatter.settings.tpr_service_channel_formatter: weight: type: integer +field.formatter.settings.tpr_service_err_channel_list: + type: mapping + mapping: + sort_order: + type: sequence + sequence: + type: mapping + mapping: + label: + type: label + show: + type: boolean + weight: + type: integer + field.formatter.settings.service_map_embed: type: mapping label: 'Service map embed' diff --git a/helfi_tpr.info.yml b/helfi_tpr.info.yml index 3836dac8..224cc319 100644 --- a/helfi_tpr.info.yml +++ b/helfi_tpr.info.yml @@ -19,4 +19,3 @@ dependencies: - views 'interface translation project': helfi_tpr 'interface translation server pattern': modules/contrib/helfi_tpr/translations/%language.po - diff --git a/helfi_tpr.install b/helfi_tpr.install index f25a875a..b5a7ae81 100644 --- a/helfi_tpr.install +++ b/helfi_tpr.install @@ -13,6 +13,7 @@ use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\helfi_tpr\Entity\ChannelTypeCollection; +use Drupal\migrate\Plugin\MigrateIdMapInterface; /** * Helper function to get the content translation field definitions. @@ -714,3 +715,65 @@ function helfi_tpr_update_8040() : void { ->installFieldStorageDefinition($name, 'tpr_unit', 'helfi_tpr', $field); } } + +/** + * Add name_synonyms field and service_id field to Service entity. + */ +function helfi_tpr_update_8041() : void { + + $fields['service_id'] = BaseFieldDefinition::create('integer') + ->setLabel(new TranslatableMarkup('Service grouping ID')) + ->setDescription(new TranslatableMarkup('Value from service_id property')) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE) + ->setSetting('unsigned', TRUE); + + $fields['name_synonyms'] = BaseFieldDefinition::create('string_long') + ->setTranslatable(TRUE) + ->setRevisionable(FALSE) + ->setLabel(new TranslatableMarkup('Name synonyms')) + ->setDescription(new TranslatableMarkup('Name synonyms for the service title.')) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + foreach ($fields as $name => $field) { + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition($name, 'tpr_service', 'helfi_tpr', $field); + } +} + +/** + * Map all services that needs update to import name_synonyms on next migration. + */ +function helfi_tpr_update_8042() : void { + \Drupal::database()->update('migrate_map_tpr_service')->fields([ + 'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE, + ])->execute(); +} + +/** + * Add has_unit field to Service entity. + */ +function helfi_tpr_update_8043() : void { + $fields['has_unit'] = BaseFieldDefinition::create('boolean') + ->setTranslatable(TRUE) + ->setRevisionable(FALSE) + ->setLabel(new TranslatableMarkup('Has Unit')) + ->setDescription(new TranslatableMarkup('If service have unit its true else false.')) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + foreach ($fields as $name => $field) { + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition($name, 'tpr_service', 'helfi_tpr', $field); + } +} diff --git a/helfi_tpr.module b/helfi_tpr.module index d45b1df8..29b18a2f 100644 --- a/helfi_tpr.module +++ b/helfi_tpr.module @@ -269,3 +269,20 @@ function helfi_tpr_tpr_errand_service_access(EntityInterface $entity, $operation function helfi_tpr_query_owd_relationship_alter(AlterableInterface $query) : void { $query->groupBy('id'); } + +/** + * Implements hook_views_data_alter(). + */ +function helfi_tpr_views_data_alter(&$data) : void { + $data['tpr_service_field_data']['id_or_service_id'] = [ + 'title' => t('ID or Service ID'), + 'help' => t('Displays entities that have either id or service IDs'), + 'argument' => [ + 'field' => 'id', + 'name table' => 'tpr_service_field_data', + 'name field' => 'id', + 'id' => 'id_or_service_id_handler', + ], + ]; + +} diff --git a/helfi_tpr.services.yml b/helfi_tpr.services.yml index 8786b388..15cb2f85 100644 --- a/helfi_tpr.services.yml +++ b/helfi_tpr.services.yml @@ -14,4 +14,3 @@ services: arguments: ['@config.factory'] tags: - { name: event_subscriber } - diff --git a/migrations/tpr_service.yml b/migrations/tpr_service.yml index e84f51f0..86b00a66 100644 --- a/migrations/tpr_service.yml +++ b/migrations/tpr_service.yml @@ -16,6 +16,8 @@ source: process: id: id name: title + name_synonyms: name_synonyms + service_id: service_id description/summary: description_short description/value: description_long description/format: @@ -24,6 +26,10 @@ process: errand_services: plugin: get source: exact_errand_services + has_unit: + plugin: callback + callable: boolval + source: unit_ids links: plugin: sub_process source: links diff --git a/src/Entity/Service.php b/src/Entity/Service.php index 44007aea..294914a7 100644 --- a/src/Entity/Service.php +++ b/src/Entity/Service.php @@ -150,6 +150,38 @@ protected function getErrandServiceIndex(ErrandService $errand_service) { public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields = parent::baseFieldDefinitions($entity_type); + $fields['name_synonyms'] = BaseFieldDefinition::create('string_long') + ->setTranslatable(TRUE) + ->setRevisionable(FALSE) + ->setLabel(new TranslatableMarkup('Name synonyms')) + ->setDescription(new TranslatableMarkup('Name synonyms for the service title.')) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + $fields['has_unit'] = BaseFieldDefinition::create('boolean') + ->setTranslatable(FALSE) + ->setRevisionable(FALSE) + ->setLabel(new TranslatableMarkup('Has Unit')) + ->setDescription(new TranslatableMarkup('If service have unit its true else false.')) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + $fields['service_id'] = BaseFieldDefinition::create('integer') + ->setLabel(new TranslatableMarkup('Service grouping ID')) + ->setDescription(new TranslatableMarkup('Value from service_id property')) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE) + ->setSetting('unsigned', TRUE); + $fields['description'] = BaseFieldDefinition::create('text_with_summary') ->setTranslatable(TRUE) ->setRevisionable(FALSE) @@ -185,6 +217,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) ->setDisplayConfigurable('view', TRUE) ->setDisplayConfigurable('form', TRUE); + $fields['menu_link'] = BaseFieldDefinition::create('entity_reference') ->setLabel(new TranslatableMarkup('Menu link')) ->setSettings([ diff --git a/src/Fixture/Service.php b/src/Fixture/Service.php index 729de5d5..81c3175c 100644 --- a/src/Fixture/Service.php +++ b/src/Fixture/Service.php @@ -57,6 +57,12 @@ public function getMockData() : array { 'url' => sprintf('https://localhost/2/%s/%s', $language, $id), ], ], + 'unit_ids' => $id != 2 ? [] : [ + 1563, + 1940, + ], + 'name_synonyms' => sprintf('Name synonyms %s %s', $language, $id), + 'service_id' => 10554, ]; } } diff --git a/src/Plugin/Field/FieldFormatter/ErrandServicesChannelFormatter.php b/src/Plugin/Field/FieldFormatter/ErrandServicesChannelFormatter.php new file mode 100644 index 00000000..aaf69a25 --- /dev/null +++ b/src/Plugin/Field/FieldFormatter/ErrandServicesChannelFormatter.php @@ -0,0 +1,179 @@ + [], + ] + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ + public function settingsSummary() : array { + $settings = $this->getSetting('sort_order'); + $selected_channels = []; + foreach ($settings as $channel_type => $channel_setting) { + if ($channel_setting['show']) { + $selected_channels[] = $channel_type; + } + } + + return [ + $this->t('Showing @list', [ + '@list' => implode(', ', $selected_channels), + ], + ), + ]; + } + + /** + * Gets the channel types. + * + * @return \Drupal\helfi_tpr\Entity\ChannelTypeCollection + * The channel type collection. + */ + private function getChannelTypes() : ChannelTypeCollection { + return ChannelTypeCollection::createFromArray($this->getSetting('sort_order')); + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state) : array { + $form = parent::settingsForm($form, $form_state); + + $form['sort_order'] = [ + '#type' => 'table', + '#caption' => $this->t('Order'), + '#header' => [ + $this->t('ID'), + $this->t('Label'), + $this->t('Show'), + $this->t('Label'), + $this->t('Weight'), + ], + '#tableselect' => FALSE, + '#tabledrag' => [ + [ + 'action' => 'order', + 'relationship' => 'sibling', + 'group' => 'group-weight', + ], + ], + ]; + $channelTypes = []; + foreach ($this->getChannelTypes() as $channelId => $channelType) { + $channelTypes[$channelId] = $channelType; + } + $channelTypes['OFFICE'] = new ChannelType('OFFICE', 99); + + foreach ($channelTypes as $item) { + $form['sort_order'][$item->id] = [ + '#attributes' => ['class' => ['draggable']], + '#weight' => $item->weight, + 'id' => ['#plain_text' => $item->id], + 'label' => [ + '#type' => 'textfield', + '#default_value' => $this->getSetting('sort_order')[$item->id]['label'] ?? $item->id, + ], + 'show' => [ + '#type' => 'checkbox', + '#default_value' => $this->getSetting('sort_order')[$item->id]['show'] ?? 0, + ], + 'weight' => [ + '#type' => 'weight', + '#title' => $this->t('Weight for @title', ['@title' => $item->id]), + '#title_display' => 'invisible', + '#default_value' => $item->weight, + '#attributes' => ['class' => ['group-weight']], + ], + ]; + } + + return $form; + } + + /** + * {@inheritdoc} + */ + public function viewElements(FieldItemListInterface $items, $langcode) : array { + + if (!$items->getEntity() instanceof Service) { + throw new \InvalidArgumentException('The field can only be used with Services entities.'); + } + $channelTypes = $this->getChannelTypes(); + + /** @var \Drupal\Core\Render\Renderer $renderer */ + $renderer = \Drupal::service('renderer'); + + $channel_list = []; + $errand_services = $items->referencedEntities(); + $item_list = [ + '#theme' => 'item_list', + '#items' => [], + ]; + + foreach ($errand_services as $errand_service) { + /** @var \Drupal\helfi_tpr\Entity\ErrandService $errand_service */ + foreach ($errand_service->getChannels() as $channel) { + if (isset($channel_list[$channel->getType()]) + || empty($this->getSetting('sort_order')[$channel->getType()]['show'])) { + continue; + } + + $channel_list[$channel->getType()] = [ + '#name' => $this->getSetting('sort_order')[$channel->getType()]['label'], + '#weight' => $channelTypes[$channel->getType()]->weight, + ]; + $renderer->addCacheableDependency($item_list, $channel); + } + } + + /** @var \Drupal\helfi_tpr\Entity\Service $service */ + $service = $items->getEntity(); + + if ($service->hasField('has_unit') && $service->has_unit->value) { + $channel_list['OFFICE'] = [ + '#name' => $this->getSetting('sort_order')['OFFICE']['label'], + '#weight' => $this->getSetting('sort_order')['OFFICE']['weight'], + ]; + } + + uasort($channel_list, [SortArray::class, 'sortByWeightProperty']); + $item_list['#items'] = array_column($channel_list, '#name'); + + $elements[0] = $item_list; + + return $elements; + } + +} diff --git a/src/Plugin/views/argument/ServiceIdArgument.php b/src/Plugin/views/argument/ServiceIdArgument.php new file mode 100644 index 00000000..3d82c0ba --- /dev/null +++ b/src/Plugin/views/argument/ServiceIdArgument.php @@ -0,0 +1,42 @@ +ensureMyTable(); + + // Separate IDs from Service IDs. + $input = explode('|', $this->argument); + $ids = array_filter(explode(',', $input[0])); + $service_ids = array_filter(explode(',', $input[1])); + + if (empty($ids) && empty($service_ids)) { + return; + } + + $group = $this->query->setWhereGroup('OR'); + if (!empty($ids)) { + $this->query->addWhere($group, 'id', $ids, 'IN'); + } + if (!empty($service_ids)) { + $this->query->addWhere($group, 'service_id', $service_ids, 'IN'); + } + + } + +} diff --git a/tests/modules/helfi_tpr_test/config/install/views.view.test_service_list.yml b/tests/modules/helfi_tpr_test/config/install/views.view.test_service_list.yml new file mode 100644 index 00000000..836b10f5 --- /dev/null +++ b/tests/modules/helfi_tpr_test/config/install/views.view.test_service_list.yml @@ -0,0 +1,308 @@ +uuid: cf9e0af9-0f30-42ea-b682-cac93313d852 +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.tpr_service.teaser_search_result + module: + - helfi_tpr +id: test_service_list +label: 'test service list' +module: views +description: '' +tag: '' +base_table: tpr_service_field_data +base_field: id +display: + default: + id: default + display_title: Default + display_plugin: default + position: 0 + display_options: + fields: + service_id: + id: service_id + table: tpr_service_field_data + field: service_id + relationship: none + group_type: group + admin_label: '' + entity_type: tpr_service + entity_field: service_id + plugin_id: field + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: number_integer + settings: + thousand_separator: '' + prefix_suffix: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + id: + id: id + table: tpr_service_field_data + field: id + relationship: none + group_type: group + admin_label: '' + entity_type: tpr_service + entity_field: id + plugin_id: field + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: false + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + pager: + type: none + options: + offset: 0 + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + access: + type: none + options: { } + cache: + type: tag + options: { } + empty: { } + sorts: + id: + id: id + table: tpr_service_field_data + field: id + relationship: none + group_type: group + admin_label: '' + entity_type: tpr_service + entity_field: id + plugin_id: standard + order: ASC + expose: + label: '' + field_identifier: '' + exposed: false + arguments: + id_or_service_id: + id: id_or_service_id + table: tpr_service_field_data + field: id_or_service_id + relationship: none + group_type: group + admin_label: '' + entity_type: tpr_service + plugin_id: id_or_service_id_handler + default_action: ignore + exception: + value: all + title_enable: false + title: All + title_enable: false + title: '' + default_argument_type: fixed + default_argument_options: + argument: '' + default_argument_skip_url: false + summary_options: + base_path: '' + count: true + override: false + items_per_page: 25 + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false + validate: + type: none + fail: 'not found' + validate_options: { } + filters: + langcode: + id: langcode + table: tpr_service_field_data + field: langcode + relationship: none + group_type: group + admin_label: '' + entity_type: tpr_service + entity_field: langcode + plugin_id: language + operator: in + value: + '***LANGUAGE_language_content***': '***LANGUAGE_language_content***' + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + operator_limit_selection: false + operator_list: { } + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + reduce: false + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + style: + type: default + options: + row_class: '' + default_row_class: true + uses_fields: true + row: + type: 'entity:tpr_service' + options: + relationship: none + view_mode: teaser_search_result + query: + type: views_query + options: + query_comment: '' + disable_sql_rewrite: false + distinct: false + replica: false + query_tags: { } + relationships: { } + header: + result: + id: result + table: views + field: result + relationship: none + group_type: group + admin_label: '' + plugin_id: result + empty: true + content: 'Displaying @start - @end of @total' + footer: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url + tags: { } diff --git a/tests/modules/helfi_tpr_test/config/schema/helfi_tpr_test.views.schema.yml b/tests/modules/helfi_tpr_test/config/schema/helfi_tpr_test.views.schema.yml new file mode 100644 index 00000000..199cdfcb --- /dev/null +++ b/tests/modules/helfi_tpr_test/config/schema/helfi_tpr_test.views.schema.yml @@ -0,0 +1,12 @@ +# Schema for the views plugins of the Views test config module. + +views.area.test_example: + type: views_area + label: 'Test example' + mapping: + string: + type: text + label: 'The shown text of the area' + custom_access: + type: boolean + label: 'Should access to the area be allowed' diff --git a/tests/modules/helfi_tpr_test/helfi_tpr_test.info.yml b/tests/modules/helfi_tpr_test/helfi_tpr_test.info.yml new file mode 100644 index 00000000..199738ff --- /dev/null +++ b/tests/modules/helfi_tpr_test/helfi_tpr_test.info.yml @@ -0,0 +1,7 @@ +name: 'Service List Test Config' +type: module +core_version_requirement: ^9 || ^10 +description: 'Provides default views for tests.' +package: Testing +dependencies: + - drupal:helfi_tpr diff --git a/tests/src/Kernel/MigrationTestBase.php b/tests/src/Kernel/MigrationTestBase.php index c509d216..da8aa7b4 100644 --- a/tests/src/Kernel/MigrationTestBase.php +++ b/tests/src/Kernel/MigrationTestBase.php @@ -25,6 +25,9 @@ abstract class MigrationTestBase extends ApiMigrationTestBase { 'media', 'telephone', 'menu_link_content', + 'helfi_tpr_test', + 'views', + 'image', ]; /** @@ -45,7 +48,7 @@ public function setUp() : void { foreach ($entity_types as $type) { $this->installEntitySchema($type); } - $this->installConfig(['helfi_tpr']); + $this->installConfig(['helfi_tpr', 'helfi_tpr_test']); } /** diff --git a/tests/src/Kernel/ServiceIdArgumentTest.php b/tests/src/Kernel/ServiceIdArgumentTest.php new file mode 100644 index 00000000..5ff0a86a --- /dev/null +++ b/tests/src/Kernel/ServiceIdArgumentTest.php @@ -0,0 +1,126 @@ +runUnitMigrate(); + $this->runServiceMigrate(); + + // Testing fixtures data is received. + $view = Views::getView('test_service_list'); + $view->setDisplay(); + $view->initHandlers(); + $view->preExecute(); + $view->execute(); + // Expecting 4 results from fixtures data. + $this->assertEquals(4, count($view->result)); + $view->destroy(); + + // Test for service_id. + $view = Views::getView('test_service_list'); + $view->setDisplay(); + $view->initHandlers(); + // Filtering by service_id = 10554. + $view->setArguments(['id_or_service_id' => '|10554']); + $view->preExecute(); + $view->execute(); + + // Expecting 3 results: id's: 1,2,3 that are under service_id = 10554. + $this->assertEquals(3, count($view->result)); + foreach ($view->result as &$row) { + $this->assertEquals('10554', $view->field['service_id']->getValue($row)); + } + $view->destroy(); + + // Test for id. + $view = Views::getView('test_service_list'); + $view->setDisplay(); + $view->initHandlers(); + // Filtering by id = 1. + $view->setArguments(['id_or_service_id' => '1|']); + $view->preExecute(); + $view->execute(); + + // Expecting 1 result: id = 1. + $this->assertEquals(1, count($view->result)); + foreach ($view->result as &$row) { + $this->assertEquals('1', $view->field['id']->getValue($row)); + } + $view->destroy(); + + // Test for service_id and id. + $view = Views::getView('test_service_list'); + $view->setDisplay(); + $view->initHandlers(); + $view->setArguments(['id_or_service_id' => '7705|10554']); + $view->preExecute(); + $view->execute(); + + // Expecting all id's under 10554 service_id and one specific id = 7705. + $this->assertEquals(4, count($view->result)); + $this->assertEquals(10554, $view->field['service_id']->getValue($view->result[0])); + $this->assertEquals(10554, $view->field['service_id']->getValue($view->result[1])); + $this->assertEquals(10554, $view->field['service_id']->getValue($view->result[2])); + $this->assertEquals(7705, $view->field['id']->getValue($view->result[3])); + + $view->destroy(); + + // Test for two id's. + $view = Views::getView('test_service_list'); + $view->setDisplay(); + $view->initHandlers(); + $view->setArguments(['id_or_service_id' => '1,2|']); + $view->preExecute(); + $view->execute(); + + $this->assertEquals(2, count($view->result)); + $this->assertEquals(1, $view->field['id']->getValue($view->result[0])); + $this->assertEquals(2, $view->field['id']->getValue($view->result[1])); + + $view->destroy(); + + // Test for two service_id's. + $view = Views::getView('test_service_list'); + $view->setDisplay(); + $view->initHandlers(); + $view->setArguments(['id_or_service_id' => '|10554,10014']); + $view->preExecute(); + $view->execute(); + + $this->assertEquals(4, count($view->result)); + $this->assertEquals(10554, $view->field['service_id']->getValue($view->result[0])); + $this->assertEquals(10554, $view->field['service_id']->getValue($view->result[1])); + $this->assertEquals(10554, $view->field['service_id']->getValue($view->result[2])); + $this->assertEquals(10014, $view->field['service_id']->getValue($view->result[3])); + + $view->destroy(); + + // Testing no result. + $view = Views::getView('test_service_list'); + $view->setDisplay(); + $view->initHandlers(); + // Filtering by service_id|id. + $view->setArguments(['id_or_service_id' => '10554|1']); + $view->preExecute(); + $view->execute(); + // Expecting 0 results. + $this->assertEquals(0, count($view->result)); + $view->destroy(); + } + +} diff --git a/tests/src/Kernel/ServiceMigrationTest.php b/tests/src/Kernel/ServiceMigrationTest.php index bb5c7fdc..3877e92e 100644 --- a/tests/src/Kernel/ServiceMigrationTest.php +++ b/tests/src/Kernel/ServiceMigrationTest.php @@ -80,6 +80,17 @@ public function testServiceMigration() : void { $this->assertEquals(sprintf('Description short %s %s', $langcode, $translation->id()), $translation->get('description')->summary); $this->assertEquals(sprintf('Description long %s %s', $langcode, $translation->id()), $translation->get('description')->value); + $this->assertEquals(sprintf('Name synonyms %s %s', $langcode, $translation->id()), $translation->get('name_synonyms')->value); + + $this->assertEquals(10554, $translation->get('service_id')->value); + $has_unit = !empty($translation->get('has_unit')->value); + if ($translation->id() == 2) { + $this->assertTrue($has_unit); + } + else { + $this->assertFalse($has_unit); + } + foreach ([123, 456] as $key => $id) { $this->assertEquals($id, $translation->get('errand_services')->get($key)->target_id); }