Compare commits
25 Commits
revisioner
...
801c69fa06
Author | SHA1 | Date | |
---|---|---|---|
801c69fa06 | |||
de3a79209b | |||
7ea66d37a7 | |||
cd8974fdb9 | |||
5e0bde90a0 | |||
bca978f6f0 | |||
49bf43e5b4 | |||
2c65aff7e1 | |||
44b9680e0c | |||
b70697995a | |||
ffb56ab09f | |||
2f07a2b9aa | |||
20f2312245 | |||
6857bb8d4c | |||
f48dae3371 | |||
183537db39 | |||
fb9737ca04 | |||
737104d7bd | |||
66fa591566 | |||
c318c451dc | |||
d81e1b3711 | |||
eb9335b250 | |||
809dbfc837 | |||
156434fecc | |||
57795b6393 |
257
config/optional/views.view.cases_by_provider.yml
Normal file
257
config/optional/views.view.cases_by_provider.yml
Normal file
@ -0,0 +1,257 @@
|
|||||||
|
uuid: 24db3b38-2204-47be-8347-20c277b05d2a
|
||||||
|
langcode: en
|
||||||
|
status: true
|
||||||
|
dependencies:
|
||||||
|
config:
|
||||||
|
- user.role.authenticated
|
||||||
|
module:
|
||||||
|
- opencase_cases
|
||||||
|
- opencase_entities
|
||||||
|
- user
|
||||||
|
id: cases_by_provider
|
||||||
|
label: 'Cases by provider'
|
||||||
|
module: views
|
||||||
|
description: ''
|
||||||
|
tag: ''
|
||||||
|
base_table: oc_case_provision_field_data
|
||||||
|
base_field: id
|
||||||
|
display:
|
||||||
|
default:
|
||||||
|
id: default
|
||||||
|
display_title: Default
|
||||||
|
display_plugin: default
|
||||||
|
position: 0
|
||||||
|
display_options:
|
||||||
|
title: 'Cases by provider'
|
||||||
|
fields:
|
||||||
|
name_1:
|
||||||
|
id: name_1
|
||||||
|
table: oc_case_field_data
|
||||||
|
field: name
|
||||||
|
relationship: oc_case
|
||||||
|
group_type: group
|
||||||
|
admin_label: ''
|
||||||
|
entity_type: oc_case
|
||||||
|
entity_field: name
|
||||||
|
plugin_id: field
|
||||||
|
label: Title
|
||||||
|
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: true
|
||||||
|
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: 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
|
||||||
|
pager:
|
||||||
|
type: mini
|
||||||
|
options:
|
||||||
|
offset: 0
|
||||||
|
items_per_page: 10
|
||||||
|
total_pages: null
|
||||||
|
id: 0
|
||||||
|
tags:
|
||||||
|
next: ››
|
||||||
|
previous: ‹‹
|
||||||
|
expose:
|
||||||
|
items_per_page: false
|
||||||
|
items_per_page_label: 'Items per page'
|
||||||
|
items_per_page_options: '5, 10, 25, 50'
|
||||||
|
items_per_page_options_all: false
|
||||||
|
items_per_page_options_all_label: '- All -'
|
||||||
|
offset: false
|
||||||
|
offset_label: Offset
|
||||||
|
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: role
|
||||||
|
options:
|
||||||
|
role:
|
||||||
|
authenticated: authenticated
|
||||||
|
cache:
|
||||||
|
type: tag
|
||||||
|
options: { }
|
||||||
|
empty: { }
|
||||||
|
sorts: { }
|
||||||
|
arguments:
|
||||||
|
uid:
|
||||||
|
id: uid
|
||||||
|
table: users_field_data
|
||||||
|
field: uid
|
||||||
|
relationship: reverse__user__field_linked_opencase_actor
|
||||||
|
group_type: group
|
||||||
|
admin_label: ''
|
||||||
|
entity_type: user
|
||||||
|
entity_field: uid
|
||||||
|
plugin_id: user_uid
|
||||||
|
default_action: default
|
||||||
|
exception:
|
||||||
|
value: all
|
||||||
|
title_enable: false
|
||||||
|
title: All
|
||||||
|
title_enable: false
|
||||||
|
title: ''
|
||||||
|
default_argument_type: current_user
|
||||||
|
default_argument_options: { }
|
||||||
|
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: { }
|
||||||
|
break_phrase: false
|
||||||
|
not: false
|
||||||
|
filters:
|
||||||
|
status:
|
||||||
|
id: status
|
||||||
|
table: oc_case_provision_field_data
|
||||||
|
field: status
|
||||||
|
entity_type: oc_case_provision
|
||||||
|
entity_field: status
|
||||||
|
plugin_id: boolean
|
||||||
|
value: '1'
|
||||||
|
group: 1
|
||||||
|
expose:
|
||||||
|
operator: ''
|
||||||
|
operator_limit_selection: false
|
||||||
|
operator_list: { }
|
||||||
|
style:
|
||||||
|
type: table
|
||||||
|
row:
|
||||||
|
type: fields
|
||||||
|
query:
|
||||||
|
type: views_query
|
||||||
|
options:
|
||||||
|
query_comment: ''
|
||||||
|
disable_sql_rewrite: false
|
||||||
|
distinct: false
|
||||||
|
replica: false
|
||||||
|
query_tags: { }
|
||||||
|
relationships:
|
||||||
|
oc_case:
|
||||||
|
id: oc_case
|
||||||
|
table: oc_case_provision_field_data
|
||||||
|
field: oc_case
|
||||||
|
relationship: none
|
||||||
|
group_type: group
|
||||||
|
admin_label: Case
|
||||||
|
entity_type: oc_case_provision
|
||||||
|
entity_field: oc_case
|
||||||
|
plugin_id: standard
|
||||||
|
required: true
|
||||||
|
oc_provider:
|
||||||
|
id: oc_provider
|
||||||
|
table: oc_case_provision_field_data
|
||||||
|
field: oc_provider
|
||||||
|
relationship: none
|
||||||
|
group_type: group
|
||||||
|
admin_label: Person
|
||||||
|
entity_type: oc_case_provision
|
||||||
|
entity_field: oc_provider
|
||||||
|
plugin_id: standard
|
||||||
|
required: true
|
||||||
|
reverse__user__field_linked_opencase_actor:
|
||||||
|
id: reverse__user__field_linked_opencase_actor
|
||||||
|
table: oc_actor_field_data
|
||||||
|
field: reverse__user__field_linked_opencase_actor
|
||||||
|
relationship: oc_provider
|
||||||
|
group_type: group
|
||||||
|
admin_label: User
|
||||||
|
entity_type: oc_actor
|
||||||
|
plugin_id: entity_reverse
|
||||||
|
required: true
|
||||||
|
header: { }
|
||||||
|
footer: { }
|
||||||
|
display_extenders: { }
|
||||||
|
cache_metadata:
|
||||||
|
max-age: -1
|
||||||
|
contexts:
|
||||||
|
- 'languages:language_content'
|
||||||
|
- 'languages:language_interface'
|
||||||
|
- url
|
||||||
|
- url.query_args
|
||||||
|
- user
|
||||||
|
- user.roles
|
||||||
|
tags: { }
|
||||||
|
page_1:
|
||||||
|
id: page_1
|
||||||
|
display_title: Page
|
||||||
|
display_plugin: page
|
||||||
|
position: 1
|
||||||
|
display_options:
|
||||||
|
display_extenders: { }
|
||||||
|
path: cases-by-provider
|
||||||
|
cache_metadata:
|
||||||
|
max-age: -1
|
||||||
|
contexts:
|
||||||
|
- 'languages:language_content'
|
||||||
|
- 'languages:language_interface'
|
||||||
|
- url
|
||||||
|
- url.query_args
|
||||||
|
- user
|
||||||
|
- user.roles
|
||||||
|
tags: { }
|
||||||
|
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Drupal\opencase_cases\Entity;
|
namespace Drupal\opencase_cases\Entity;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\ContentEntityBase;
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
use Drupal\Core\Field\BaseFieldDefinition;
|
use Drupal\Core\Field\BaseFieldDefinition;
|
||||||
use Drupal\Core\Entity\RevisionableContentEntityBase;
|
use Drupal\Core\Entity\RevisionableContentEntityBase;
|
||||||
@ -83,6 +84,10 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public static function loadFromUrlQueryParameter(string $param) {
|
||||||
|
return self::load(\Drupal::request()->query->get($param));
|
||||||
|
}
|
||||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values)
|
public static function preCreate(EntityStorageInterface $storage_controller, array &$values)
|
||||||
{
|
{
|
||||||
parent::preCreate($storage_controller, $values);
|
parent::preCreate($storage_controller, $values);
|
||||||
@ -91,6 +96,26 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCaseProviderIds(int $role_id = null): array {
|
||||||
|
$case_provision_ids = $this->getCaseProvisionIds();
|
||||||
|
$provider_ids = [];
|
||||||
|
foreach($case_provision_ids as $id) {
|
||||||
|
$provision = \Drupal::entityTypeManager()->getStorage('oc_case_provision')->load($id);
|
||||||
|
if ($provision instanceOf OCCaseProvision) {
|
||||||
|
if (is_null($role_id) || $role_id == $provision->get('oc_case_provider_role')->target_id) {
|
||||||
|
$provider_ids[] = $provision->get('oc_provider')->target_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $provider_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getCaseProvisionIds(): array {
|
||||||
|
$query = \Drupal::entityTypeManager()->getStorage('oc_case_provision')->getQuery();
|
||||||
|
$query->condition('oc_case.target_id', $this->id());
|
||||||
|
return $query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
public function deleteCaseProvisions(): void {
|
public function deleteCaseProvisions(): void {
|
||||||
$this->deleteChildren('oc_case_provision');
|
$this->deleteChildren('oc_case_provision');
|
||||||
}
|
}
|
||||||
@ -98,8 +123,7 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
|
|||||||
$this->deleteChildren('oc_activity');
|
$this->deleteChildren('oc_activity');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function deleteChildren($child_entity_type):void {
|
||||||
public function deleteChildren($child_entity_type):void {
|
|
||||||
$query = \Drupal::entityQuery($child_entity_type)
|
$query = \Drupal::entityQuery($child_entity_type)
|
||||||
->condition('oc_case.target_id', $this->id());
|
->condition('oc_case.target_id', $this->id());
|
||||||
$ids = $query->execute();
|
$ids = $query->execute();
|
||||||
@ -116,6 +140,16 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
|
|||||||
else return [];
|
else return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTargetEntity(): ContentEntityBase {
|
||||||
|
if (!$this->oc_target->isEmpty()) {
|
||||||
|
return $this->oc_target->entity;
|
||||||
|
} elseif ($this->hasField('client') && !$this->client->isEmpty()) {
|
||||||
|
return $this->client->entity;
|
||||||
|
} else {
|
||||||
|
throw new \Exception('No target found on case');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -230,7 +230,8 @@ class OCCaseFee extends EditorialContentEntityBase implements OCCaseFeeInterface
|
|||||||
->setLabel(t('Visible'))
|
->setLabel(t('Visible'))
|
||||||
->setDescription(t('A boolean indicating whether the Case Fee is published.'))
|
->setDescription(t('A boolean indicating whether the Case Fee is published.'))
|
||||||
->setDisplayConfigurable('form', TRUE)
|
->setDisplayConfigurable('form', TRUE)
|
||||||
->setDisplayConfigurable('view', TRUE);
|
->setDisplayConfigurable('view', TRUE)
|
||||||
|
->setDefaultValue(TRUE);
|
||||||
|
|
||||||
$fields['created'] = BaseFieldDefinition::create('created')
|
$fields['created'] = BaseFieldDefinition::create('created')
|
||||||
->setLabel(t('Created'))
|
->setLabel(t('Created'))
|
||||||
@ -268,7 +269,7 @@ class OCCaseFee extends EditorialContentEntityBase implements OCCaseFeeInterface
|
|||||||
->setDisplayConfigurable("view", true)
|
->setDisplayConfigurable("view", true)
|
||||||
->setDisplayConfigurable("form", true)
|
->setDisplayConfigurable("form", true)
|
||||||
->setRequired(FALSE);
|
->setRequired(FALSE);
|
||||||
|
|
||||||
$fields['description'] = BaseFieldDefinition::create('string_long')
|
$fields['description'] = BaseFieldDefinition::create('string_long')
|
||||||
->setRevisionable(TRUE)
|
->setRevisionable(TRUE)
|
||||||
->setLabel(t('Description'))
|
->setLabel(t('Description'))
|
||||||
|
@ -4,6 +4,30 @@
|
|||||||
use \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter;
|
use \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter;
|
||||||
use \Drupal\Core\Field\BaseFieldDefinition;
|
use \Drupal\Core\Field\BaseFieldDefinition;
|
||||||
|
|
||||||
|
function opencase_entities_update_90004() {
|
||||||
|
$update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||||
|
$definition = $update_manager->getFieldStorageDefinition('website', 'oc_organisation');
|
||||||
|
$update_manager->uninstallFieldStorageDefinition($definition);
|
||||||
|
}
|
||||||
|
|
||||||
|
function opencase_entities_update_90003() {
|
||||||
|
$field_storage_definition = BaseFieldDefinition::create('link')
|
||||||
|
->setLabel(t('Website'))
|
||||||
|
->setRevisionable(TRUE)
|
||||||
|
->setSettings([
|
||||||
|
'max_length' => 50,
|
||||||
|
'text_processing' => 0,
|
||||||
|
])
|
||||||
|
->setDefaultValue('')
|
||||||
|
->setDisplayConfigurable('form', true)
|
||||||
|
->setDisplayConfigurable('view', true)
|
||||||
|
->setRequired(FALSE);
|
||||||
|
|
||||||
|
|
||||||
|
\Drupal::entityDefinitionUpdateManager()
|
||||||
|
->installFieldStorageDefinition('org_website', 'oc_organisation', 'opencase_entities', $field_storage_definition);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function opencase_entities_update_90002() {
|
function opencase_entities_update_90002() {
|
||||||
$field_storage_definition = BaseFieldDefinition::create('entity_reference')
|
$field_storage_definition = BaseFieldDefinition::create('entity_reference')
|
||||||
|
@ -211,6 +211,9 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface
|
|||||||
public function getCountOfCaseProvisions(array $conditionsToApplyToCaseProvisionQuery = []): int {
|
public function getCountOfCaseProvisions(array $conditionsToApplyToCaseProvisionQuery = []): int {
|
||||||
$query = \Drupal::entityQuery('oc_case_provision');
|
$query = \Drupal::entityQuery('oc_case_provision');
|
||||||
$query->condition('oc_provider', $this->id());
|
$query->condition('oc_provider', $this->id());
|
||||||
|
foreach($conditionsToApplyToCaseProvisionQuery as $condition) {
|
||||||
|
$query->condition($condition[0], $condition[1], $condition[2] ?? '=');
|
||||||
|
}
|
||||||
return count($query->execute());
|
return count($query->execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +294,7 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface
|
|||||||
->setRequired(TRUE);
|
->setRequired(TRUE);
|
||||||
|
|
||||||
// Contact details.
|
// Contact details.
|
||||||
$fields['email'] = BaseFieldDefinition::create('string')
|
$fields['email'] = BaseFieldDefinition::create('email')
|
||||||
->setLabel(t('Email Address'))
|
->setLabel(t('Email Address'))
|
||||||
->setRevisionable(TRUE)
|
->setRevisionable(TRUE)
|
||||||
->setSettings(array(
|
->setSettings(array(
|
||||||
|
@ -211,17 +211,20 @@ class OCOrganisation extends EditorialContentEntityBase implements OCOrganisatio
|
|||||||
'max_length' => 255,
|
'max_length' => 255,
|
||||||
'text_processing' => 0,
|
'text_processing' => 0,
|
||||||
));
|
));
|
||||||
$fields['website'] = BaseFieldDefinition::create('string')
|
|
||||||
|
$fields['org_website'] = BaseFieldDefinition::create('link')
|
||||||
->setLabel(t('Website'))
|
->setLabel(t('Website'))
|
||||||
->setRevisionable(TRUE)
|
->setRevisionable(TRUE)
|
||||||
->setSettings([
|
->setSettings([
|
||||||
'max_length' => 50,
|
|
||||||
'text_processing' => 0,
|
'text_processing' => 0,
|
||||||
|
'title' => 0,
|
||||||
|
'link_type' => 16
|
||||||
])
|
])
|
||||||
->setDefaultValue('')
|
->setDefaultValue('')
|
||||||
->setDisplayConfigurable('form', true)
|
->setDisplayConfigurable('form', true)
|
||||||
->setDisplayConfigurable('view', true)
|
->setDisplayConfigurable('view', true)
|
||||||
->setRequired(FALSE);
|
->setRequired(FALSE);
|
||||||
|
|
||||||
$fields['contact_name'] = BaseFieldDefinition::create('string')
|
$fields['contact_name'] = BaseFieldDefinition::create('string')
|
||||||
->setLabel(t('Contact Name'))
|
->setLabel(t('Contact Name'))
|
||||||
->setDescription(t('Name of the main contact for this organisation.'))
|
->setDescription(t('Name of the main contact for this organisation.'))
|
||||||
@ -247,14 +250,10 @@ class OCOrganisation extends EditorialContentEntityBase implements OCOrganisatio
|
|||||||
->setDisplayConfigurable('form', true)
|
->setDisplayConfigurable('form', true)
|
||||||
->setDisplayConfigurable('view', true)
|
->setDisplayConfigurable('view', true)
|
||||||
->setRequired(FALSE);
|
->setRequired(FALSE);
|
||||||
$fields['email'] = BaseFieldDefinition::create('string')
|
|
||||||
|
$fields['email'] = BaseFieldDefinition::create('email')
|
||||||
->setLabel(t('Email Address'))
|
->setLabel(t('Email Address'))
|
||||||
->setRevisionable(TRUE)
|
->setRevisionable(TRUE)
|
||||||
->setSettings(array(
|
|
||||||
'default_value' => '',
|
|
||||||
'max_length' => 100,
|
|
||||||
'text_processing' => 0,
|
|
||||||
))
|
|
||||||
->setDisplayConfigurable('form', true)
|
->setDisplayConfigurable('form', true)
|
||||||
->setDisplayConfigurable('view', true);
|
->setDisplayConfigurable('view', true);
|
||||||
|
|
||||||
@ -302,7 +301,7 @@ class OCOrganisation extends EditorialContentEntityBase implements OCOrganisatio
|
|||||||
->setDisplayConfigurable('view', true)
|
->setDisplayConfigurable('view', true)
|
||||||
->setRequired(FALSE);
|
->setRequired(FALSE);
|
||||||
|
|
||||||
$fields['billing_email'] = BaseFieldDefinition::create('string')
|
$fields['billing_email'] = BaseFieldDefinition::create('email')
|
||||||
->setLabel(t('Billing Email Address'))
|
->setLabel(t('Billing Email Address'))
|
||||||
->setRevisionable(TRUE)
|
->setRevisionable(TRUE)
|
||||||
->setSettings(array(
|
->setSettings(array(
|
||||||
|
@ -56,7 +56,7 @@ opencase.manage_taxonomy_links:
|
|||||||
menu_name: opencase
|
menu_name: opencase
|
||||||
parent: opencase.opencase_admin_menu
|
parent: opencase.opencase_admin_menu
|
||||||
opencase.manage_user_logins:
|
opencase.manage_user_logins:
|
||||||
title: 'Manage user logins'
|
title: 'Manage User Logins'
|
||||||
description: 'Manage who can access the system'
|
description: 'Manage who can access the system'
|
||||||
menu_name: opencase
|
menu_name: opencase
|
||||||
parent: opencase.opencase_admin_menu
|
parent: opencase.opencase_admin_menu
|
||||||
|
@ -9,6 +9,25 @@ use Drupal\Core\Access\AccessResult;
|
|||||||
use Drupal\opencase_cases\Entity\OCCase;
|
use Drupal\opencase_cases\Entity\OCCase;
|
||||||
use Drupal\Core\Routing\RouteMatchInterface;
|
use Drupal\Core\Routing\RouteMatchInterface;
|
||||||
use Drupal\opencase_cases\Entity\OCCaseProvision;
|
use Drupal\opencase_cases\Entity\OCCaseProvision;
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_form_FORM_ID_alter().
|
||||||
|
*/
|
||||||
|
function opencase_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
|
||||||
|
$form['#submit'][] = 'opencase_user_login_form_submit';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the user does not have permissions to see all cases, then when the login they are
|
||||||
|
* redirected to a view of just their own cases.
|
||||||
|
*/
|
||||||
|
function opencase_user_login_form_submit($form, FormStateInterface $form_state) {
|
||||||
|
if (!\Drupal::currentUser()->hasPermission('view published case entities')) {
|
||||||
|
$form_state->setRedirectUrl(Url::fromRoute('view.cases_by_provider.page_1'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_element_info_alter().
|
* Implements hook_element_info_alter().
|
||||||
|
8
opencase.services.yml
Normal file
8
opencase.services.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
services:
|
||||||
|
opencase.breadcrumb:
|
||||||
|
# The namespace + classname from your BreadcrumbBuilderInterface class
|
||||||
|
class: Drupal\opencase\Breadcrumb\BreadcrumbBuilder
|
||||||
|
|
||||||
|
# Priority determines the order in which Breadcrumb services run.
|
||||||
|
tags:
|
||||||
|
- { name: breadcrumb_builder, priority: 100 }
|
105
src/Breadcrumb/BreadcrumbBuilder.php
Normal file
105
src/Breadcrumb/BreadcrumbBuilder.php
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Drupal\opencase\Breadcrumb;
|
||||||
|
|
||||||
|
use Drupal\Core\Link ;
|
||||||
|
use Drupal\Core\Breadcrumb\Breadcrumb;
|
||||||
|
use Drupal\opencase_cases\Entity\OCCase;
|
||||||
|
use Drupal\Core\Entity\ContentEntityBase;
|
||||||
|
use Drupal\Core\Routing\RouteMatchInterface;
|
||||||
|
use Drupal\opencase_entities\Entity\OCOrganisation;
|
||||||
|
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
|
||||||
|
|
||||||
|
class BreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
||||||
|
|
||||||
|
private string $title;
|
||||||
|
private function addTitle($route_match) {
|
||||||
|
$title = $this->title ?? $this->getPageTitle($route_match);
|
||||||
|
$this->breadcrumb->addLink(Link::createFromRoute($title, '<none>'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function applies(RouteMatchInterface $route_match) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPageTitle($route_match) {
|
||||||
|
$request = \Drupal::request();
|
||||||
|
return \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addLinksForCaseTarget(ContentEntityBase $entity) {
|
||||||
|
if ($entity instanceof OCOrganisation) {
|
||||||
|
$this->addLinksForOrganisation($entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addLinksForOrganisation(ContentEntityBase $entity) {
|
||||||
|
$fields = ['field_umbrella_client'];
|
||||||
|
$this->addLinks($entity, $fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addLinksForCase(OCCase $case) {
|
||||||
|
$fields = ['client', 'field_project'];
|
||||||
|
$this->addLinksForCaseTarget($case->getTargetEntity());
|
||||||
|
$this->addLinks($case, $fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addLinks(ContentEntityBase $entity, array $fields) {
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
if ($entity->hasField($field) && !$entity->get($field)->isEmpty()) {
|
||||||
|
$this->breadcrumb->addLink($entity->$field->entity->toLink());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function build(RouteMatchInterface $route_match) {
|
||||||
|
$this->breadcrumb = new Breadcrumb();
|
||||||
|
$this->breadcrumb->addLink(Link::createFromRoute('Home', '<front>'));
|
||||||
|
$params = $route_match->getParameters();
|
||||||
|
|
||||||
|
if ($params->has('oc_activity')) {
|
||||||
|
$activity = $params->get('oc_activity');
|
||||||
|
if (!$activity->get('oc_case')->isEmpty()){
|
||||||
|
$this->addLinksForCase($activity->get('oc_case')->entity);
|
||||||
|
}
|
||||||
|
$this->addLinks($activity, ['client', 'oc_case']);
|
||||||
|
$this->title = $activity->getName() ?? $activity->type->entity->label();
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif ($params->has('oc_organisation')) {
|
||||||
|
$this->addLinksForOrganisation($params->get('oc_organisation'));
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif ($params->has('oc_case')) {
|
||||||
|
$this->addLinksForCase($params->get('oc_case'));
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif ($params->has('oc_case_fee')) {
|
||||||
|
$case_provision = $params->get('oc_case_fee');
|
||||||
|
$this->addLinksForCase($case_provision->get('oc_case')->entity);
|
||||||
|
$this->addLinks($case_provision, ['oc_case']);
|
||||||
|
$this->title = "Fee";
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif ($params->has('oc_case_provision')) {
|
||||||
|
$case_provision = $params->get('oc_case_provision');
|
||||||
|
$this->addLinksForCase($case_provision->get('oc_case')->entity);
|
||||||
|
$this->addLinks($case_provision, ['oc_case']);
|
||||||
|
$this->title = $case_provision->type->entity->label();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addTitle($route_match);
|
||||||
|
|
||||||
|
// Don't forget to add cache control by a route.
|
||||||
|
// Otherwise all pages will have the same breadcrumb.
|
||||||
|
$this->breadcrumb->addCacheContexts(['route']);
|
||||||
|
return $this->breadcrumb;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -45,7 +45,7 @@ class AddEventsMenuLink extends DeriverBase implements ContainerDeriverInterface
|
|||||||
$eventTypes = $this->entityTypeManager->getStorage('oc_event_type')->loadMultiple();
|
$eventTypes = $this->entityTypeManager->getStorage('oc_event_type')->loadMultiple();
|
||||||
foreach ($eventTypes as $id => $eventType) {
|
foreach ($eventTypes as $id => $eventType) {
|
||||||
$links[$id] = [
|
$links[$id] = [
|
||||||
'title' => $eventType->label(),
|
'title' => $eventType->label() . " Event",
|
||||||
'route_name' => "entity.oc_event.add_form",
|
'route_name' => "entity.oc_event.add_form",
|
||||||
'route_parameters' => ['oc_event_type' => $eventType->id()]
|
'route_parameters' => ['oc_event_type' => $eventType->id()]
|
||||||
] + $base_plugin_definition;
|
] + $base_plugin_definition;
|
||||||
|
@ -2,8 +2,14 @@
|
|||||||
|
|
||||||
namespace Drupal\opencase;
|
namespace Drupal\opencase;
|
||||||
|
|
||||||
|
|
||||||
class Pluraliser {
|
class Pluraliser {
|
||||||
|
const NO_CHANGE = ['Staff'];
|
||||||
public static function pluralise($text) {
|
public static function pluralise($text) {
|
||||||
return $text . "s";
|
if (in_array($text, self::NO_CHANGE)) {
|
||||||
|
return $text;
|
||||||
|
} else {
|
||||||
|
return $text . "s";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,25 +2,21 @@
|
|||||||
|
|
||||||
namespace Drupal\opencase;
|
namespace Drupal\opencase;
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\opencase\Utils;
|
|
||||||
|
|
||||||
final class TimeBasedFieldUpdater {
|
final class TimeBasedFieldUpdater {
|
||||||
|
|
||||||
private EntityTypeManagerInterface $entityTypeManager;
|
private EntityTypeManagerInterface $entityTypeManager;
|
||||||
private string $date_field;
|
private string $date_field;
|
||||||
private Utils $utils;
|
|
||||||
private string $entity_type;
|
private string $entity_type;
|
||||||
private string $date_format;
|
private string $date_format;
|
||||||
private string $bundle;
|
private string $bundle;
|
||||||
|
|
||||||
final public function __construct(
|
final public function __construct(
|
||||||
EntityTypeManagerInterface $entityTypeManager,
|
EntityTypeManagerInterface $entityTypeManager,
|
||||||
Utils $utils,
|
|
||||||
string $entity_type, string $bundle, string $date_field, string $date_format = 'Y-m-d'
|
string $entity_type, string $bundle, string $date_field, string $date_format = 'Y-m-d'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->entityTypeManager = $entityTypeManager;
|
$this->entityTypeManager = $entityTypeManager;
|
||||||
$this->utils = $utils;
|
|
||||||
$this->date_field = $date_field;
|
$this->date_field = $date_field;
|
||||||
$this->date_format = $date_format;
|
$this->date_format = $date_format;
|
||||||
$this->entity_type = $entity_type;
|
$this->entity_type = $entity_type;
|
||||||
@ -39,7 +35,7 @@ final class TimeBasedFieldUpdater {
|
|||||||
$this->updateEntity($id, $new_values);
|
$this->updateEntity($id, $new_values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private function updateEntity(int $entity_id, array $new_values): void {
|
private function updateEntity(string $entity_id, array $new_values): void {
|
||||||
$entity = $this->entityTypeManager->getStorage($this->entity_type)->load($entity_id);
|
$entity = $this->entityTypeManager->getStorage($this->entity_type)->load($entity_id);
|
||||||
foreach($new_values as $new_field=>$new_value) {
|
foreach($new_values as $new_field=>$new_value) {
|
||||||
$entity->$new_field = $new_value;
|
$entity->$new_field = $new_value;
|
||||||
|
38
tests/src/Unit/EntityTrait.php
Normal file
38
tests/src/Unit/EntityTrait.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
namespace Drupal\Tests\opencase\Unit;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
trait EntityTrait {
|
||||||
|
public function getEntityTypeManager() {
|
||||||
|
return $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStorage(MockObject $entityTypeManager, string $entityTypeToExpect = ''): MockObject {
|
||||||
|
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$entityTypeManager->method('getStorage')->willReturn($storage);
|
||||||
|
if ($entityTypeToExpect) {
|
||||||
|
$entityTypeManager->expects($this->any())->method('getStorage')->with($entityTypeToExpect)->willReturn($storage);
|
||||||
|
}
|
||||||
|
return $storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQuery(MockObject $storage): MockObject {
|
||||||
|
$query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock();
|
||||||
|
$storage->method('getQuery')->willReturn($query);
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEntity(): MockObject {
|
||||||
|
return $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||||
|
}
|
||||||
|
public function getContainer(array $services): ContainerBuilder {
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
foreach ($services as $key => $mock) {
|
||||||
|
$container->set($key, $mock);
|
||||||
|
}
|
||||||
|
\Drupal::setContainer($container);
|
||||||
|
return $container;
|
||||||
|
}
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
<?php declare(strict_types = 1);
|
|
||||||
|
|
||||||
namespace Drupal\Tests\opencase\Unit;
|
|
||||||
|
|
||||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
|
||||||
use Drupal\Core\Form\FormState;
|
|
||||||
use Drupal\opencase_entities\Form\OCActivityRevisionRevertForm;
|
|
||||||
use Drupal\Tests\UnitTestCase;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
|
||||||
|
|
||||||
class OCActivityRevisionRevertFormTest extends UnitTestCase{
|
|
||||||
public function setUp(): void {
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
|
||||||
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
|
||||||
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
|
||||||
$revision = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\OCActivity')->disableOriginalConstructor()->getMock();
|
|
||||||
$request = new Request([], [], [], [], [], [], [], json_encode([
|
|
||||||
'foo' => 'bar'
|
|
||||||
]));
|
|
||||||
$requestStack = new RequestStack();
|
|
||||||
$requestStack->push($request);
|
|
||||||
$dateFormatter->method('format');
|
|
||||||
$container->set('entity_type.manager', $entityTypeManager);
|
|
||||||
$container->set('date.formatter', $dateFormatter);
|
|
||||||
$entityTypeManager->method('getStorage')->willReturn($storage);
|
|
||||||
$storage->method('loadRevision')->willReturn($revision);
|
|
||||||
$container->set('string_translation', self::getStringTranslationStub());
|
|
||||||
$container->set('request_stack', $requestStack);
|
|
||||||
\Drupal::setContainer($container);
|
|
||||||
$this->reverter = OCActivityRevisionRevertForm::create($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBuildForm():void {
|
|
||||||
$form = [];
|
|
||||||
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
<?php declare(strict_types = 1);
|
|
||||||
|
|
||||||
namespace Drupal\Tests\opencase\Unit;
|
|
||||||
|
|
||||||
use Drupal\opencase_entities\Form\OCActorRevisionRevertForm;
|
|
||||||
use Drupal\Tests\UnitTestCase;
|
|
||||||
use Drupal\Core\Form\FormState;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
|
||||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
|
||||||
|
|
||||||
class OCActorRevisionRevertFormTest extends UnitTestCase{
|
|
||||||
public function setUp(): void {
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
|
||||||
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
|
||||||
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
|
||||||
$revision = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\OCActor')->disableOriginalConstructor()->getMock();
|
|
||||||
$request = new Request([], [], [], [], [], [], [], json_encode([
|
|
||||||
'foo' => 'bar'
|
|
||||||
]));
|
|
||||||
$requestStack = new RequestStack();
|
|
||||||
$requestStack->push($request);
|
|
||||||
$dateFormatter->method('format');
|
|
||||||
$container->set('entity_type.manager', $entityTypeManager);
|
|
||||||
$container->set('date.formatter', $dateFormatter);
|
|
||||||
$entityTypeManager->method('getStorage')->willReturn($storage);
|
|
||||||
$storage->method('loadRevision')->willReturn($revision);
|
|
||||||
$container->set('string_translation', self::getStringTranslationStub());
|
|
||||||
$container->set('request_stack', $requestStack);
|
|
||||||
\Drupal::setContainer($container);
|
|
||||||
$this->reverter = OCActorRevisionRevertForm::create($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBuildForm():void {
|
|
||||||
$form = [];
|
|
||||||
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
61
tests/src/Unit/OCActorTest.php
Normal file
61
tests/src/Unit/OCActorTest.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Drupal\Tests\opencase\Unit;
|
||||||
|
|
||||||
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
|
||||||
|
class OCActorTest extends UnitTestCase{
|
||||||
|
|
||||||
|
use EntityTrait;
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
$this->etm = $this->getEntityTypeManager();
|
||||||
|
$this->getContainer([
|
||||||
|
'entity_type.manager' => $this->etm
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetCountOfCaseProvisionsWithNoExtraConditions(): void{
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$actor = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\\OCActor')->disableOriginalConstructor()
|
||||||
|
->onlyMethods(['id'])
|
||||||
|
->getMock();
|
||||||
|
$actor->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->once())->method('condition')->with('oc_provider', 5);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1,2,3,4]);
|
||||||
|
$count = $actor->getCountOfCaseProvisions();
|
||||||
|
$this->assertTrue($count == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testGetCountOfCaseProvisionsWithExtraConditions(): void{
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$actor = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\\OCActor')->disableOriginalConstructor()
|
||||||
|
->onlyMethods(['id'])
|
||||||
|
->getMock();
|
||||||
|
$actor->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->exactly(2))->method('condition')->withConsecutive(
|
||||||
|
['oc_provider', 5],
|
||||||
|
['some_date_field', '2022-01-01', '<']);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1,2,3,4]);
|
||||||
|
$count = $actor->getCountOfCaseProvisions([['some_date_field', '2022-01-01', '<']]);
|
||||||
|
$this->assertTrue($count == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetCountOfCaseProvisionsWithExtraConditionsWithAssumedEqualityOperator(): void{
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$actor = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\\OCActor')->disableOriginalConstructor()
|
||||||
|
->onlyMethods(['id'])
|
||||||
|
->getMock();
|
||||||
|
$actor->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->exactly(2))->method('condition')->withConsecutive(
|
||||||
|
['oc_provider', 5],
|
||||||
|
['some_date_field', '2022-01-01', '=']);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1,2,3,4]);
|
||||||
|
$count = $actor->getCountOfCaseProvisions([['some_date_field', '2022-01-01']]);
|
||||||
|
$this->assertTrue($count == 4);
|
||||||
|
}
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
<?php declare(strict_types = 1);
|
|
||||||
|
|
||||||
namespace Drupal\Tests\opencase\Unit;
|
|
||||||
|
|
||||||
use Drupal\opencase_cases\Form\OCCaseRevisionRevertForm;
|
|
||||||
use Drupal\Tests\UnitTestCase;
|
|
||||||
use Drupal\Core\Form\FormState;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
|
||||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
|
||||||
|
|
||||||
class OCCaseRevisionRevertFormTest extends UnitTestCase{
|
|
||||||
public function setUp(): void {
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
|
||||||
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
|
||||||
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
|
||||||
$revision = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\OCCase')->disableOriginalConstructor()->getMock();
|
|
||||||
$request = new Request([], [], [], [], [], [], [], json_encode([
|
|
||||||
'foo' => 'bar'
|
|
||||||
]));
|
|
||||||
$requestStack = new RequestStack();
|
|
||||||
$requestStack->push($request);
|
|
||||||
$dateFormatter->method('format');
|
|
||||||
$container->set('entity_type.manager', $entityTypeManager);
|
|
||||||
$container->set('date.formatter', $dateFormatter);
|
|
||||||
$entityTypeManager->method('getStorage')->willReturn($storage);
|
|
||||||
$storage->method('loadRevision')->willReturn($revision);
|
|
||||||
$container->set('string_translation', self::getStringTranslationStub());
|
|
||||||
$container->set('request_stack', $requestStack);
|
|
||||||
\Drupal::setContainer($container);
|
|
||||||
$this->reverter = OCCaseRevisionRevertForm::create($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBuildForm():void {
|
|
||||||
$form = [];
|
|
||||||
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
125
tests/src/Unit/OCCaseTest.php
Normal file
125
tests/src/Unit/OCCaseTest.php
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Drupal\Tests\opencase\Unit;
|
||||||
|
|
||||||
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
|
||||||
|
class OCCaseTest extends UnitTestCase{
|
||||||
|
|
||||||
|
use EntityTrait;
|
||||||
|
|
||||||
|
private $case;
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
$this->etm = $this->getEntityTypeManager();
|
||||||
|
$this->getContainer([
|
||||||
|
'entity_type.manager' => $this->etm
|
||||||
|
]);
|
||||||
|
$this->case = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\\OCCase')->disableOriginalConstructor()
|
||||||
|
->onlyMethods(['id'])
|
||||||
|
->getMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetCaseProviderIds_SingleCaseProvision(): void{
|
||||||
|
// It will first get the id of the case provision that references this case
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$this->case->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->once())->method('condition')->with('oc_case.target_id', 5);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1]);
|
||||||
|
|
||||||
|
// Then it will load the provision
|
||||||
|
$provision = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\\OCCaseProvision')->disableOriginalConstructor()->getMock();
|
||||||
|
$storage->expects($this->once())->method('load')->with(1)->willReturn($provision);
|
||||||
|
|
||||||
|
// Then it will get the target id of the provider field from the provision and return it as an array
|
||||||
|
$providerField = $this->getMockBuilder('\\Drupal\\COre\\Field\\FieldItemListInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$providerField->target_id = '45';
|
||||||
|
$provision->expects($this->once())->method('get')->with('oc_provider')->willReturn($providerField);
|
||||||
|
|
||||||
|
$ids = $this->case->getCaseProviderIds();
|
||||||
|
$this->assertTrue($ids == [45]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testGetCaseProviderIds_MultipleCaseProvisions(): void{
|
||||||
|
// It will first get the id of the case provisions that reference this case
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$this->case->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->once())->method('condition')->with('oc_case.target_id', 5);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1, 2, 3]);
|
||||||
|
|
||||||
|
// Then it will load the provisions
|
||||||
|
$provision1 = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\\OCCaseProvision')->disableOriginalConstructor()->getMock();
|
||||||
|
$provision2 = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\\OCCaseProvision')->disableOriginalConstructor()->getMock();
|
||||||
|
$provision3 = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\\OCCaseProvision')->disableOriginalConstructor()->getMock();
|
||||||
|
$storage->method('load')->willReturnMap([[1, $provision1], [2, $provision2], [3, $provision3]]);
|
||||||
|
|
||||||
|
// Then it will get the target id of the provider field from each provision and return them as an array
|
||||||
|
$providerField1 = $this->getMockBuilder('\\Drupal\\COre\\Field\\FieldItemListInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$providerField1->target_id = '45';
|
||||||
|
$provision1->expects($this->once())->method('get')->with('oc_provider')->willReturn($providerField1);
|
||||||
|
$providerField2 = $this->getMockBuilder('\\Drupal\\COre\\Field\\FieldItemListInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$providerField2->target_id = '55';
|
||||||
|
$provision2->expects($this->once())->method('get')->with('oc_provider')->willReturn($providerField2);
|
||||||
|
$providerField3 = $this->getMockBuilder('\\Drupal\\COre\\Field\\FieldItemListInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$providerField3->target_id = '65';
|
||||||
|
$provision3->expects($this->once())->method('get')->with('oc_provider')->willReturn($providerField3);
|
||||||
|
|
||||||
|
$ids = $this->case->getCaseProviderIds();
|
||||||
|
$this->assertTrue($ids == [45, 55, 65]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetCaseProviderIds_SingleCaseProvision_RoleSpecifiedAndMatched(): void{
|
||||||
|
// It will first get the id of the case provision that references this case
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$this->case->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->once())->method('condition')->with('oc_case.target_id', 5);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1]);
|
||||||
|
|
||||||
|
// Then it will load the provision
|
||||||
|
$provision = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\\OCCaseProvision')->disableOriginalConstructor()->getMock();
|
||||||
|
$storage->expects($this->once())->method('load')->with(1)->willReturn($provision);
|
||||||
|
|
||||||
|
// Then it will check the role field, and find that the role is the one specified
|
||||||
|
// so it will get the target id of the provider field from the provision and return it as an array
|
||||||
|
$roleField = $this->getMockBuilder('\\Drupal\\COre\\Field\\FieldItemListInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$roleField->target_id = '7';
|
||||||
|
$providerField = $this->getMockBuilder('\\Drupal\\COre\\Field\\FieldItemListInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$providerField->target_id = '45';
|
||||||
|
$provision->expects($this->any())->method('get')->withConsecutive(['oc_case_provider_role'], ['oc_provider'])->willReturnMap(
|
||||||
|
[['oc_provider', $providerField], ['oc_case_provider_role', $roleField]]
|
||||||
|
);
|
||||||
|
|
||||||
|
$ids = $this->case->getCaseProviderIds(7);
|
||||||
|
$this->assertTrue($ids == [45]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetCaseProviderIds_SingleCaseProvision_RoleSpecifiedAndNotMatched(): void{
|
||||||
|
// It will first get the id of the case provision that references this case
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$this->case->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->once())->method('condition')->with('oc_case.target_id', 5);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1]);
|
||||||
|
|
||||||
|
// Then it will load the provision
|
||||||
|
$provision = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\\OCCaseProvision')->disableOriginalConstructor()->getMock();
|
||||||
|
$storage->expects($this->once())->method('load')->with(1)->willReturn($provision);
|
||||||
|
|
||||||
|
// Then it will check the role field, and find that the role is *not* the one specified
|
||||||
|
// so it will return nothing
|
||||||
|
$roleField = $this->getMockBuilder('\\Drupal\\COre\\Field\\FieldItemListInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$roleField->target_id = '7';
|
||||||
|
$providerField = $this->getMockBuilder('\\Drupal\\COre\\Field\\FieldItemListInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$providerField->target_id = '45';
|
||||||
|
$provision->expects($this->any())->method('get')->withConsecutive(['oc_case_provider_role'], ['oc_provider'])->willReturnMap(
|
||||||
|
[['oc_provider', $providerField], ['oc_case_provider_role', $roleField]]
|
||||||
|
);
|
||||||
|
|
||||||
|
$ids = $this->case->getCaseProviderIds(8);
|
||||||
|
$this->assertTrue($ids == []);
|
||||||
|
}
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
<?php declare(strict_types = 1);
|
|
||||||
|
|
||||||
namespace Drupal\Tests\opencase\Unit;
|
|
||||||
|
|
||||||
use Drupal\Tests\UnitTestCase;
|
|
||||||
use Drupal\Core\Form\FormState;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
|
||||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
|
||||||
use Drupal\opencase_entities\Form\OCOrganisationRevisionRevertForm;
|
|
||||||
|
|
||||||
class OCOrganisationRevisionRevertFormTest extends UnitTestCase{
|
|
||||||
public function setUp(): void {
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
|
||||||
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
|
||||||
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
|
||||||
$revision = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\OCOrganisation')->disableOriginalConstructor()->getMock();
|
|
||||||
$request = new Request([], [], [], [], [], [], [], json_encode([
|
|
||||||
'foo' => 'bar'
|
|
||||||
]));
|
|
||||||
$requestStack = new RequestStack();
|
|
||||||
$requestStack->push($request);
|
|
||||||
$dateFormatter->method('format');
|
|
||||||
$container->set('entity_type.manager', $entityTypeManager);
|
|
||||||
$container->set('date.formatter', $dateFormatter);
|
|
||||||
$entityTypeManager->method('getStorage')->willReturn($storage);
|
|
||||||
$storage->method('loadRevision')->willReturn($revision);
|
|
||||||
$container->set('string_translation', self::getStringTranslationStub());
|
|
||||||
$container->set('request_stack', $requestStack);
|
|
||||||
\Drupal::setContainer($container);
|
|
||||||
$this->reverter = OCOrganisationRevisionRevertForm::create($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBuildForm():void {
|
|
||||||
$form = [];
|
|
||||||
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
60
tests/src/Unit/RevisionRevertFormTest.php
Normal file
60
tests/src/Unit/RevisionRevertFormTest.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Drupal\Tests\opencase\Unit;
|
||||||
|
|
||||||
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
use Drupal\Core\Form\FormState;
|
||||||
|
use Drupal\Tests\opencase\Unit\EntityTrait;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
use Drupal\opencase_cases\Form\OCCaseRevisionRevertForm;
|
||||||
|
use Drupal\opencase_entities\Form\OCActorRevisionRevertForm;
|
||||||
|
use Drupal\opencase_entities\Form\OCActivityRevisionRevertForm;
|
||||||
|
use Drupal\opencase_entities\Form\OCOrganisationRevisionRevertForm;
|
||||||
|
|
||||||
|
class RevisionRevertFormTest extends UnitTestCase{
|
||||||
|
|
||||||
|
use EntityTrait;
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
$entityTypeManager = $this->getEntityTypeManager();
|
||||||
|
$storage = $this->getStorage($entityTypeManager);
|
||||||
|
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
||||||
|
$revision = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\OCActivity')->disableOriginalConstructor()->getMock();
|
||||||
|
$request = new Request([], [], [], [], [], [], [], json_encode([
|
||||||
|
'foo' => 'bar'
|
||||||
|
]));
|
||||||
|
$requestStack = new RequestStack();
|
||||||
|
$requestStack->push($request);
|
||||||
|
$dateFormatter->method('format');
|
||||||
|
$storage->method('loadRevision')->willReturn($revision);
|
||||||
|
$this->container = $this->getContainer([
|
||||||
|
'entity_type.manager'=> $entityTypeManager,
|
||||||
|
'date.formatter' => $dateFormatter,
|
||||||
|
'string_translation'=> self::getStringTranslationStub(),
|
||||||
|
'request_stack'=> $requestStack
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBuildFormForRevertingActivity():void {
|
||||||
|
$this->reverter = OCActivityRevisionRevertForm::create($this->container);
|
||||||
|
$form = [];
|
||||||
|
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
||||||
|
}
|
||||||
|
public function testBuildFormForRevertingActor():void {
|
||||||
|
$this->reverter = OCActorRevisionRevertForm::create($this->container);
|
||||||
|
$form = [];
|
||||||
|
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
||||||
|
}
|
||||||
|
public function testBuildFormForRevertingCase():void {
|
||||||
|
$this->reverter = OCCaseRevisionRevertForm::create($this->container);
|
||||||
|
$form = [];
|
||||||
|
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
||||||
|
}
|
||||||
|
public function testBuildFormForRevertingOrganisation():void {
|
||||||
|
$this->reverter = OCOrganisationRevisionRevertForm::create($this->container);
|
||||||
|
$form = [];
|
||||||
|
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
||||||
|
}
|
||||||
|
}
|
@ -7,42 +7,39 @@ use Drupal\opencase\TimeBasedFieldUpdater;
|
|||||||
|
|
||||||
class TimeBasedFieldUpdaterTest extends UnitTestCase{
|
class TimeBasedFieldUpdaterTest extends UnitTestCase{
|
||||||
|
|
||||||
|
use EntityTrait;
|
||||||
|
|
||||||
function setUp():void {
|
function setUp():void {
|
||||||
/** @var \Drupal\opencase\Utils&\PHPUnit\Framework\MockObject\MockObject $utils */
|
$this->etm = $this->getEntityTypeManager();
|
||||||
$this->utils = $this->getMockBuilder('\\Drupal\\opencase\\Utils')->disableOriginalConstructor()->getMock();
|
$this->storage = $this->getStorage($this->etm);
|
||||||
/** @var \Drupal\core\Entity\EntityTypeManagerInterface&\PHPUnit\Framework\MockObject\MockObject $entityTypeManager */
|
$this->query = $this->getQuery($this->storage);
|
||||||
$this->entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
$this->updater = new TimeBasedFieldUpdater($this->etm, 'dummy_entity_type', 'dummy_bundle', 'dummy_date_field');
|
||||||
$this->storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->getMock();
|
|
||||||
$this->query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock();
|
|
||||||
$this->entityTypeManager->method('getStorage')->willReturn($this->storage);
|
|
||||||
$this->storage->method('getQuery')->willReturn($this->query);
|
|
||||||
$this->updater = new TimeBasedFieldUpdater($this->entityTypeManager, $this->utils, 'dummy_entity_type', 'dummy_bundle', 'dummy_date_field');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
function testFieldIsUpdatedOnEntityReturnedByQuery():void {
|
function testFieldIsUpdatedOnEntityReturnedByQuery():void {
|
||||||
$this->query->method('execute')->willReturn([1]);
|
$this->query->method('execute')->willReturn(['1']);
|
||||||
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||||
$this->storage->expects($this->once())->method('load')->with(1)->willReturn($this->entity);
|
$this->storage->expects($this->once())->method('load')->with(1)->willReturn($this->entity);
|
||||||
$this->updater->update([], '3 months', ['dummy_field' => 4]);
|
$this->updater->update([], '3 months', ['dummy_field' => 4]);
|
||||||
$this->assertEquals($this->entity->dummy_field, 4);
|
$this->assertEquals($this->entity->dummy_field, 4);
|
||||||
}
|
}
|
||||||
function testFieldIsUpdatedOnAllEntitiesReturnedByQuery():void {
|
function testFieldIsUpdatedOnAllEntitiesReturnedByQuery():void {
|
||||||
$this->query->method('execute')->willReturn([1, 2]);
|
$this->query->method('execute')->willReturn(['1', '2']);
|
||||||
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
$entity = $this->getEntity();
|
||||||
$this->entity2 = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
$entity2 = $this->getEntity();
|
||||||
$this->storage->method('load')->willReturnMap([[1, $this->entity], [2, $this-> entity2]]);
|
$this->storage->method('load')->willReturnMap([['1', $entity], ['2', $entity2]]);
|
||||||
$this->updater->update([], '3 months', ['dummy_field' => 4]);
|
$this->updater->update([], '3 months', ['dummy_field' => 4]);
|
||||||
$this->assertEquals($this->entity->dummy_field, 4);
|
$this->assertEquals($entity->dummy_field, 4);
|
||||||
$this->assertEquals($this->entity2->dummy_field, 4);
|
$this->assertEquals($entity2->dummy_field, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMultipleFieldsAreUpdated(): void {
|
function testMultipleFieldsAreUpdated(): void {
|
||||||
$this->query->method('execute')->willReturn([1]);
|
$this->query->method('execute')->willReturn(['1']);
|
||||||
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
$entity = $this->getEntity();
|
||||||
$this->storage->expects($this->once())->method('load')->with(1)->willReturn($this->entity);
|
$this->storage->expects($this->once())->method('load')->with(1)->willReturn($entity);
|
||||||
$this->updater->update([], '3 months', ['dummy_field' => 4, 'dummy_field_2' => 5]);
|
$this->updater->update([], '3 months', ['dummy_field' => 4, 'dummy_field_2' => 5]);
|
||||||
$this->assertEquals($this->entity->dummy_field, 4);
|
$this->assertEquals($entity->dummy_field, 4);
|
||||||
$this->assertEquals($this->entity->dummy_field_2, 5);
|
$this->assertEquals($entity->dummy_field_2, 5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user