8000 Add index definitions to the data dictionary form/Separate index form by beeyayjay · Pull Request #4375 · GetDKAN/dkan · GitHub
[go: up one dir, main page]

Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8000
2c2d0e4
Initial commit of updates to include indexes and index fields to the …
kaise-lafrai Apr 29, 2024
5396653
Added working cancel button for index, fixed errors appearing in log
kaise-lafrai May 14, 2024
bb42cf8
Removed unused code, fixed index fields cancel button
kaise-lafrai May 20, 2024
5e0ee4c
Added validation for index fields form, refactored code, refactored t…
kaise-lafrai May 24, 2024
e529acc
Fully functional edit experience for index fields (#4204)
kaise-lafrai Jul 8, 2024
620bced
Editable Index (#4239)
kaise-lafrai Aug 1, 2024
2250243
Index UI unit tests (#4262)
dmundra Aug 19, 2024
b7f844b
Updated data dictionary widget functional test to test all fields in …
dmundra Aug 29, 2024
b10bd49
Added Indexes edit unit tests (#4266)
dmundra Aug 30, 2024
567107f
Some simple code cleanup (white space, removal of commented out code,…
dmundra Sep 5, 2024
a9ccde9
WCMS-20047: Data Dictionary Documentation (#4271)
rovcase Sep 6, 2024
bb76f74
Data dictionary indexes code refactoring (#4280)
dmundra Sep 10, 2024
c7d7cfe
Reverted changes to checkIndexEditingField and checkIndexEditing. Upd…
dmundra Sep 10, 2024
4b4cf50
Adding code comments. (#4289)
dmundra Sep 18, 2024
ea018c7
Dictionary-Widget: Streamline the button labels for the Index and Ind…
rovcase Oct 24, 2024
ffb4d44
Provisional commit
Nov 27, 2024
ae7e367
In progress
Dec 3, 2024
a320129
Added indexes to admin view.
Dec 3, 2024
53fe56f
Temp save
Dec 4, 2024
0d46835
Temp save
Dec 4, 2024
2f45d07
Temp save
Dec 9, 2024
ec4fdf8
Temp save
Dec 9, 2024
058a91a
Index keyname changes and bug fixes.
Dec 12, 2024
1f3c275
Other indexes.
Jan 2, 2025
982d12f
Index edit works.
Jan 5, 2025
326d0b5
Add index field and cancel work.
Jan 5, 2025
69ee91f
Some cleanup.
Jan 6, 2025
622f4a9
More stuff
Jan 6, 2025
c9b743b
Some cleanup
Jan 6, 2025
3e82443
Updated data dictionary admin list. Added 'Add index' link.
Jan 6, 2025
a3bf332
Removed test field and made index length optional.
Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added Indexes edit unit tests (#4266)
  • Loading branch information
dmundra authored and Beth Jacobson committed Jan 6, 2025
commit b10bd490ae5cf26ff9492b446c873ca4f61e3309
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\data_dictionary_widget\Indexes\IndexFieldAddCreation;
use Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks;
use Drupal\data_dictionary_widget\Indexes\IndexFieldEditCreation;
use Drupal\data_dictionary_widget\Indexes\IndexFieldOperations;
use Drupal\data_dictionary_widget\Indexes\IndexValidation;
use Drupal\data_dictionary_widget\Plugin\Field\FieldWidget\DataDictionaryWidget;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -341,7 +343,7 @@ public function testEditIndexesButtonsCreationDictionaryWidget() {
}

/**
* Test edit a data dictionary index field and save it.
* Test edit a data dictionary index and save it.
*/
public function testEditDataDictionaryIndexDictionaryWidget() {
$formState = $this->createMock(FormStateInterface::class);
Expand Down Expand Up @@ -519,4 +521,259 @@ public function testEditDataDictionaryIndexDictionaryWidget() {
$this->assertEquals($updated_index[0]["type"], $element["indexes"]["data"]["#rows"][0]["type"]);
}

/**
* Test edit index for indexes.
*/
public function testEditDataDictionaryIndexEdit() {
// Arrange
$indexKey = 'index_key_0';
$current_index = [
[
'description' => 'test',
'type' => 'index',
'fields' => [
[
'name' => 'test',
'length' => 20
]
]
]
];
$index_being_modified = $current_index;
$formState = $this->createMock(FormStateInterface::class);
$formState->expects($this->any())
->method('get')
->willReturnOnConsecutiveCalls(FALSE);

// Act
$edit_index = IndexFieldEditCreation::editIndex($indexKey, $current_index, $index_being_modified, $formState);

// Assert
$this->assertNotNull($edit_index);
$this->assertEquals('field_json_metadata[0][indexes][edit_index][index_key_0][description]', $edit_index['description']['#name']);
$this->assertEquals($current_index[0]['description'], $edit_index['description']['#value']);
$this->assertEquals('field_json_metadata[0][indexes][edit_index][index_key_0][type]', $edit_index['type']['#name']);
$this->assertEquals($current_index[0]['type'], $edit_index['type']['#value']);
$this->assertEquals($current_index[0]['fields'][0]['name'], $edit_index['group']['fields']['data']['#rows'][0]['name']);
$this->assertEquals($current_index[0]['fields'][0]['length'], $edit_index['group']['fields']['data']['#rows'][0]['length']);
}

/**
* Test edit index fields for indexes.
*/
public function testEditDataDictionaryIndexEditFields() {
// Arrange
$indexKey = 'index_field_key_0';
$current_index_fields = [
[
'name' => 'test',
'length' => 20
]
];

// Act
$edit_index_fields = IndexFieldEditCreation::editIndexFields($indexKey, $current_index_fields, null);

// Assert
$this->assertNotNull($edit_index_fields);
$this->assertEquals('field_json_metadata[0][indexes][fields][edit_index_fields][0][name]', $edit_index_fields['name']['#name']);
$this->assertEquals($current_index_fields[0]['name'], $edit_index_fields['name']['#value']);
$this->assertEquals('field_json_metadata[0][indexes][fields][edit_index_fields][0][length]', $edit_index_fields['length']['#name']);
$this->assertEquals($current_index_fields[0]['length'], $edit_index_fields['length']['#value']);
}

/**
* Test editing data dictionary index fields and save it.
*/
public function testEditDataDictionaryIndexFieldsDictionaryWidget() {
$formState = $this->createMock(FormStateInterface::class);
$formObject = $this->createMock(EntityFormInterface::class);
$entity = $this->createMock(FieldableEntityInterface::class);
$fieldItemList = $this->createMock(FieldItemListInterface::class);
$field_definition = $this->createMock(FieldDefinitionInterface::class);
$settings = [];
$third_party_settings = [];
$form = [];
$plugin_id = '';
$plugin_definition = [];

$current_index_field = [
[
'name' => 'test',
'length' => 20,
]
];

$updated_index_field = [
[
'name' => 'test_update',
'length' => 25,
]
];

$user_input = [
'field_json_metadata' => [
0 => [
'identifier' => 'test_identifier',
'title' => 'test_title',
'indexes' => [
'edit_index' => [
'index_key_0' => [
'description' => 'test_edit',
'type' => 'fulltext',
]
],
'fields' => [
'edit_index_fields' => [
[
'name' => 'test',
'length' => 20,
]
]
]
],
],
],
];

$form["field_json_metadata"]["widget"][0] = [
"dictionary_fields" => [
"data" => [
"#rows" => [
0 => [],
],
],
],
'indexes' => [
'data' => [
"#rows" => [
[
'description' => 'test',
'type' => 'index',
'fields' => [
'name' => 'test',
'length' => 20,
],
],
],
],
'fields' => [
'data' => [
"#rows" => [
0 => [
'name' => 'test',
'length' => 20,
],
],
],
]
],
];

$formState->expects($this->exactly(2))
->method('getFormObject')
->willReturn($formObject);

$formObject->expects($this->exactly(2))
->method('getEntity')
->willReturn($entity);

$entity->expects($this->exactly(2))
->method('set')
->with('field_data_type', 'data-dictionary');

// The gets are happening in indexEditCallback and formElement and function calls in it that use the formState variable.
// Set the value for various $form_state calls that use the current index and then are updated when we pass the updated index value.
$formState->expects($this->any())
->method('get')
->willReturnOnConsecutiveCalls(
$current_index_field,
$current_index_field,
[],
[],
$current_index_field,
[],
[],
[],
[],
[],
[],
$current_index_field,
$current_index_field,
[],
$current_index_field,
[],
[],
TRUE,
$current_index_field,
$current_index_field,
[],
[],
[],
[],
[],
[],
[],
[],
[],
$updated_index_field,
$updated_index_field,
[],
$updated_index_field,
);

$formState->expects($this->any())
->method('getTriggeringElement')
->willReturnOnConsecutiveCalls(
['#op' => 'edit_index_field_key_0'], ['#op' => 'edit_index_field_key_0'],
['#op' => 'update_index_field_key_0'], ['#op' => 'update_index_field_key_0'],
);

$formState->expects($this->any())
->method('getUserInput')
->willReturn($user_input);

$dataDictionaryWidget = new DataDictionaryWidget(
$plugin_id,
$plugin_definition,
$field_definition,
$settings,
$third_party_settings
);

// Trigger callback function to edit fields.
IndexFieldCallbacks::indexEditSubformCallback($form, $formState);

// First call to re-create data dictionary form with the editable fields.
$element = $dataDictionaryWidget->formElement(
$fieldItemList,
0,
[],
$form,
$formState
);

// Assert edit feature loads form with the current field values.
$this->assertNotNull($element);
$this->assertEquals($current_index_field[0]["name"], $element["indexes"]["fields"]["data"]["#rows"][0]["name"]);
$this->assertEquals($current_index_field[0]["length"], $element["indexes"]["fields"]["data"]["#rows"][0]["length"]);

// Trigger callback function to save the edited fields.
IndexFieldCallbacks::indexEditSubformCallback($form, $formState);

// Second call to re-create data dictionary and apply the edits made to the fields.
$element = $dataDictionaryWidget->formElement(
$fieldItemList,
0,
[],
$form,
$formState
);

// Assert update feature loads form with the edited field values.
$this->assertNotNull($element);
$this->assertEquals($updated_index_field[0]["name"], $element["indexes"]["fields"][&q 4397 uot;data"]["#rows"][0]["name"]);
$this->assertEquals($updated_index_field[0]["length"], $element["indexes"]["fields"]["data"]["#rows"][0]["length"]);
}

}
0