diff --git a/cypress/integration/07_admin_dataset_json_form.spec.js b/cypress/integration/07_admin_dataset_json_form.spec.js
deleted file mode 100644
index 276b7cd427..0000000000
--- a/cypress/integration/07_admin_dataset_json_form.spec.js
+++ /dev/null
@@ -1,90 +0,0 @@
-context('Admin dataset json form', () => {
- let baseurl = Cypress.config().baseUrl;
- beforeEach(() => {
- const user_credentials = Cypress.env('TEST_USER_CREDENTIALS')
- cy.drupalLogin(user_credentials.user, user_credentials.pass)
- })
-
- it('The dataset form has the correct required fields.', () => {
- cy.visit(baseurl + "/node/add/data")
- cy.get('#edit-field-json-metadata-0-value-title').should('have.attr', 'required', 'required')
- cy.get('#edit-field-json-metadata-0-value-description').should('have.attr', 'required', 'required')
- cy.get('#edit-field-json-metadata-0-value-accesslevel').should('have.attr', 'required', 'required')
- cy.get('#edit-field-json-metadata-0-value-modified-date').should('have.attr', 'required', 'required')
- cy.get('#edit-field-json-metadata-0-value-publisher-publisher-name').should('have.attr', 'required', 'required')
- cy.get('#edit-field-json-metadata-0-value-contactpoint-contactpoint-fn').should('have.attr', 'required', 'required')
- cy.get('#edit-field-json-metadata-0-value-contactpoint-contactpoint-hasemail').should('have.attr', 'required', 'required')
- })
-
- it('License and format fields are select or other elements in dataset form', () => {
- cy.visit(baseurl + '/node/add/data')
- cy.get('#edit-field-json-metadata-0-value-license-select').select('select_or_other', { force: true })
- cy.get('#edit-field-json-metadata-0-value-license-other.form-url').should('be.visible')
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-select').select('select_or_other', { force: true })
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-other.form-text').should('be.visible')
- })
-
- it('User can create and edit a dataset with the json form UI. User can delete a dataset.', () => {
- cy.visit(baseurl + "/node/add/data")
- cy.wait(2000)
- cy.get('#edit-field-json-metadata-0-value-title').type('DKANTEST dataset title', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-description').type('DKANTEST dataset description.', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-accesslevel').select('public', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-modified-date').type('2020-02-02', { force:true } )
- // Fill select2 field for publisher.
- cy.get('#edit-field-json-metadata-0-value-publisher-publisher-name + .select2')
- .find('.select2-selection')
- .click({ force:true });
- cy.get('input[aria-controls="select2-edit-field-json-metadata-0-value-publisher-publisher-name-results"]').type('DKANTEST Publisher{enter}')
- // End filling up publisher.
- cy.get('#edit-field-json-metadata-0-value-contactpoint-contactpoint-fn').type('DKANTEST Contact Name', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-contactpoint-contactpoint-hasemail').type('dkantest@test.com', { force:true } )
- // Fill select2 field for keyword.
- cy.get('#edit-field-json-metadata-0-value-keyword-keyword-0 + .select2')
- .find('.select2-selection')
- .click({ force: true });
- cy.get('input[aria-controls="select2-edit-field-json-metadata-0-value-keyword-keyword-0-results"]').type('open data{enter}')
- // End filling up keyword.
- cy.wait(2000)
- cy.get('#edit-actions').within(() => {
- cy.get('#edit-preview').should('exist')
- })
- cy.get('#edit-submit').click({ force:true })
- cy.get('.button').contains('Yes').click({ force:true });
- cy.get('.messages--status').should('contain','has been created')
- // Confirm the default dkan admin view is filtered to show only datasets.
- cy.visit(baseurl + "/admin/dkan/datasets")
- cy.get('tbody tr').each(($el) => {
- cy.wrap($el).within(() => {
- cy.get('td.views-field-field-data-type').should('contain', 'dataset')
- })
- })
- // Edit the dataset.
- cy.get('#edit-title').type('DKANTEST dataset title', { force:true } )
- cy.get('#edit-submit-dkan-dataset-content').click({ force:true })
- cy.get('tbody > tr:first-of-type > .views-field-nothing > a').click({ force:true })
- cy.wait(2000)
- cy.get('#edit-field-json-metadata-0-value-title').should('have.value','DKANTEST dataset title')
- cy.get('#edit-field-json-metadata-0-value-title').type('NEW dkantest dataset title',{ force:true })
- cy.get('#edit-field-json-metadata-0-value-accrualperiodicity').select('Annual', { force:true })
- cy.get('#edit-field-json-metadata-0-value-keyword-keyword-0 + .select2')
- .find('.select2-selection')
- .click({ force: true });
- cy.get('input[aria-controls="select2-edit-field-json-metadata-0-value-keyword-keyword-0-results"]').type('testing{enter}')
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-title').type('DKANTEST distribution title text', { force:true })
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-description').type('DKANTEST distribution description text', { force:true })
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-select').select('csv', { force:true })
- cy.get('#edit-submit').click({ force:true })
- cy.get('.button').contains('Yes').click({ force:true });
- cy.get('.messages--status').should('contain','has been updated')
- // Delete dataset.
- cy.visit(baseurl + "/admin/dkan/datasets")
- cy.wait(2000)
- cy.get('#edit-node-bulk-form-0').check({ force:true })
- cy.get('#edit-action').select('Delete content',{ force: true }).should('have.value', 'node_delete_action')
- cy.get('#edit-submit').click({ force:true })
- cy.get('input[value="Delete"]').click({ force:true })
- cy.get('.messages__content').should('contain','Deleted 1 content item.')
- })
-
-})
diff --git a/cypress/integration/11_admin_dataset_file_upload.spec.js b/cypress/integration/11_admin_dataset_file_upload.spec.js
deleted file mode 100644
index 5d3060095b..0000000000
--- a/cypress/integration/11_admin_dataset_file_upload.spec.js
+++ /dev/null
@@ -1,169 +0,0 @@
-import * as dkan from '../support/helpers/dkan'
-
-context('Admin dataset file upload', () => {
- context('Create dataset with remote file', () => {
- const fileUrl = 'https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv'
- const title = dkan.generateRandomString()
-
- beforeEach(() => {
- const user_credentials = Cypress.env('TEST_USER_CREDENTIALS')
- cy.drupalLogin(user_credentials.user, user_credentials.pass)
- })
-
- it('create the dataset', () => {
- cy.visit('/node/add/data')
- cy.wait(2000)
- cy.get('#edit-field-json-metadata-0-value-title').type(title, { force:true } )
- cy.get('#edit-field-json-metadata-0-value-description').type('DKANTEST distribution description.', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-accesslevel').select('public', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-modified-date').type('2021-02-02', { force:true } )
- // Fill select2 field for publisher.
- cy.get('#edit-field-json-metadata-0-value-publisher-publisher-name + .select2')
- .find('.select2-selection')
- .click({ force:true })
- cy.get('input[aria-controls="select2-edit-field-json-metadata-0-value-publisher-publisher-name-results"]').type('DKANTEST Publisher{enter}')
- // End filling up publisher.
- cy.get('#edit-field-json-metadata-0-value-contactpoint-contactpoint-fn').type('DKANTEST Contact Name', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-contactpoint-contactpoint-hasemail').type('dkantest@test.com', { force:true } )
- // Fill select2 field for keyword.
- cy.get('#edit-field-json-metadata-0-value-keyword-keyword-0 + .select2')
- .find('.select2-selection')
- .click({ force: true })
- cy.get('input[aria-controls="select2-edit-field-json-metadata-0-value-keyword-keyword-0-results"]').type('open data{enter}')
- // End filling up keyword.
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-title')
- .type('distribution title test', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-description')
- .type('distribution description test', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-select')
- .select('csv', { force:true })
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl-file-url-type-remote')
- .click({ force:true })
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl-file-url-remote')
- .type(fileUrl, { force:true })
- cy.get('#edit-submit')
- .click({ force:true })
- cy.get('.button').contains('Yes')
- .click({ force:true })
- cy.get('.messages--status')
- .should('contain','has been created')
- })
-
- it('can fill up the form with distribution and submit', () => {
- // run cron to gather file.
- cy.visit('/admin/config/system/cron')
- cy.get('#edit-run')
- .click({force: true})
- cy.contains('h1', 'Cron');
- cy.get('.messages--status', {timeout: 120000})
- .should('be.visible')
- // run cron to perform data import.
- cy.visit('/admin/config/system/cron')
- cy.get('#edit-run')
- .click({force: true})
-
- // verify dataset was imported successfully
- dkan.verifyFileImportedSuccessfully(fileUrl.split('/').pop())
- })
-
- it('uploaded dataset files show remote link on edit', () => {
- cy.visit('/admin/dkan/datasets')
- cy.get('#edit-title').type(title)
- cy.get('#edit-submit-dkan-dataset-content').click()
- cy.get('.views-field-nothing > a').click()
- cy.contains('h1', 'Edit Data');
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl a')
- .invoke('attr', 'href')
- .should('eq', fileUrl)
- })
- })
-
- context('Create dataset with file upload', () => {
- const fileName = 'example.csv'
- const fileType = 'csv'
- const title = dkan.generateRandomString()
- // generate a separate upload file name to prevent name collisions across
- // tests
- const uploadedFileName = dkan.generateCSVFileName()
-
- beforeEach(() => {
- const user_credentials = Cypress.env('TEST_USER_CREDENTIALS')
- cy.drupalLogin(user_credentials.user, user_credentials.pass)
- })
-
- it('create the dataset', () => {
- const selectorDist = '#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl-upload'
- cy.visit('/node/add/data')
- cy.wait(2000)
- cy.get('#edit-field-json-metadata-0-value-title').type(title, { force:true } )
- cy.get('#edit-field-json-metadata-0-value-description').type('DKANTEST distribution description.', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-accesslevel').select('public', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-modified-date').type('2021-02-02', { force:true } )
- // Fill select2 field for publisher.
- cy.get('#edit-field-json-metadata-0-value-publisher-publisher-name + .select2')
- .find('.select2-selection')
- .click({ force:true })
- cy.get('input[aria-controls="select2-edit-field-json-metadata-0-value-publisher-publisher-name-results"]').type('DKANTEST Publisher{enter}')
- // End filling up publisher.
- cy.get('#edit-field-json-metadata-0-value-contactpoint-contactpoint-fn').type('DKANTEST Contact Name', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-contactpoint-contactpoint-hasemail').type('dkantest@test.com', { force:true } )
- // Fill select2 field for keyword.
- cy.get('#edit-field-json-metadata-0-value-keyword-keyword-0 + .select2')
- .find('.select2-selection')
- .click({ force: true })
- cy.get('input[aria-controls="select2-edit-field-json-metadata-0-value-keyword-keyword-0-results"]').type('open data{enter}')
- // End filling up keyword.
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-title')
- .type('distribution title test', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-description')
- .type('distribution description test', { force:true } )
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-select')
- .select('csv', { force:true })
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl-file-url-type-upload')
- .click({ force:true })
-
- cy.get(selectorDist).uploadFile(fileName, fileType, uploadedFileName)
- //wait for the file to be fully loaded
- cy.get('.file--mime-text-csv', {timeout: 120000})
- .should('be.visible')
- cy.get('#edit-submit')
- .click({ force:true })
- cy.get('.button').contains('Yes')
- .click({ force:true })
- cy.get('.messages--status')
- .should('contain','has been created')
- })
-
-
- it('can import dataset with uploaded file', () => {
- // run cron to localize the file.
- cy.visit('/admin/config/system/cron')
- cy.get('#edit-run')
- .click({force: true})
- cy.get('.messages--status', {timeout: 120000})
- .should('be.visible')
- // run cron again to import new dataset.
- cy.visit('/admin/config/system/cron')
- cy.get('#edit-run')
- .click({force: true})
- cy.get('.messages--status', {timeout: 120000})
- .should('be.visible')
-
- // verify dataset was imported successfully
- dkan.verifyFileImportedSuccessfully(uploadedFileName)
- })
-
- it('uploaded dataset files show local link on edit', () => {
- // validate URL of uploaded CSV file
- cy.visit('/admin/dkan/datasets')
- cy.get('#edit-title').type(title)
- cy.get('#edit-submit-dkan-dataset-content').click()
- cy.get('tbody > :nth-child(1) > .views-field-nothing > a').click({force: true})
- cy.get('h1').should('contain', 'Edit Data')
- cy.get('#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl a')
- .invoke('attr', 'href')
- .should('contain', `uploaded_resources/${uploadedFileName}`)
- })
- })
-
-})
diff --git a/modules/json_form_widget/json_form_widget.module b/modules/json_form_widget/json_form_widget.module
index 19c957a320..444a8d4849 100644
--- a/modules/json_form_widget/json_form_widget.module
+++ b/modules/json_form_widget/json_form_widget.module
@@ -76,7 +76,7 @@ function _json_form_widget_build_count_property(array $button_element): array {
*/
function json_form_widget_field_widget_complete_form_alter(&$field_widget_complete_form, FormStateInterface $form_state, $context) {
if ($context['widget'] instanceof JsonFormWidget) {
- $form_state->has_json_form_widget = TRUE;
+ $form_state->set('has_json_form_widget', TRUE);
}
}
@@ -86,10 +86,10 @@ function json_form_widget_field_widget_complete_form_alter(&$field_widget_comple
* Add custom submit handler to form if it contains an upload_or_link element.
*/
function json_form_widget_form_alter(&$form, FormStateInterface $form_state, $form_id) {
- if (!isset($form['actions']['submit']) || !isset($form_state->has_json_form_widget)) {
+ if (!isset($form['actions']['submit'])) {
return;
}
- if ($form_state->has_json_form_widget) {
+ if ($form_state->get('has_json_form_widget')) {
$form['actions']['submit']['#submit'][] = 'json_form_widget_file_submit';
}
}
diff --git a/modules/json_form_widget/src/Plugin/Field/FieldWidget/JsonFormWidget.php b/modules/json_form_widget/src/Plugin/Field/FieldWidget/JsonFormWidget.php
index 6e8ae9824d..57a632e976 100644
--- a/modules/json_form_widget/src/Plugin/Field/FieldWidget/JsonFormWidget.php
+++ b/modules/json_form_widget/src/Plugin/Field/FieldWidget/JsonFormWidget.php
@@ -55,7 +55,7 @@ class JsonFormWidget extends WidgetBase {
protected ?string $schema;
/**
- * Constructs a WidgetBase object.
+ * Constructs a JsonFormWidget object.
*
* @param string $plugin_id
* The plugin_id for the widget.
diff --git a/modules/json_form_widget/tests/src/Functional/AdminDatasetFileUploadTest.php b/modules/json_form_widget/tests/src/Functional/AdminDatasetFileUploadTest.php
new file mode 100644
index 0000000000..493149fc68
--- /dev/null
+++ b/modules/json_form_widget/tests/src/Functional/AdminDatasetFileUploadTest.php
@@ -0,0 +1,265 @@
+container->get('plugin.manager.queue_worker');
+ /** @var \Drupal\Core\Queue\QueueFactory $queueFactory */
+ $queueFactory = $this->container->get('queue');
+ foreach ($relevantQueues as $queueName) {
+ $worker = $queueWorkerManager->createInstance($queueName);
+ $queue = $queueFactory->get($queueName);
+ while ($item = $queue->claimItem()) {
+ $worker->processItem($item->data);
+ $queue->deleteItem($item);
+ }
+ }
+ }
+
+ /**
+ * Test creating datasets.
+ *
+ * 11_admin_dataset_file_upload.spec.js : Admin dataset file upload : Create
+ * dataset with remote file.
+ */
+ public function testCreateDatasetWithRemoteFile() {
+ /** @var \Drupal\metastore\MetastoreService $metastore_service */
+ $metastore_service = $this->container->get('dkan.metastore.service');
+ /** @var \Drupal\metastore\ValidMetadataFactory $metadata_factory */
+ $metadata_factory = $this->container->get('dkan.metastore.valid_metadata');
+
+ $this->drupalLogin(
+ // @todo Figure out least possible admin permissions.
+ $this->drupalCreateUser([], NULL, TRUE)
+ );
+
+ // Since we don't have JavaScript, we can't use select2 or select_or_other
+ // to add publisher or keyword entities. We create them here with arbitrary
+ // UUIDs so that we can post the names to the form.
+ $publisher_name = uniqid();
+ $metastore_service->post('publisher',
+ $metastore_service->getValidMetadataFactory()->get(
+ json_encode((object) [
+ 'identifier' => '9deadc2f-50e0-512a-af7c-4323697d530d',
+ 'data' => ['name' => $publisher_name],
+ ]), 'publisher', ['method' => 'POST'])
+ );
+ // We need a keyword.
+ $keyword_data = uniqid();
+ $metastore_service->post('keyword',
+ $metastore_service->getValidMetadataFactory()->get(json_encode((object) [
+ 'identifier' => '05b2e74a-eb23-585b-9c1c-4d023e21e8a5',
+ 'data' => $keyword_data,
+ ]), 'keyword', ['method' => 'POST'])
+ );
+
+ $dataset_title = uniqid();
+ $file_url = 'https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv';
+
+ $assert = $this->assertSession();
+
+ // 11_admin_dataset_file_upload.spec.js : Create dataset with remote file :
+ // create the dataset, can fill up the form with distribution and submit.
+ $this->drupalGet('node/add/data');
+ $assert->statusCodeEquals(200);
+
+ $page = $this->getSession()->getPage();
+
+ // Use the form.
+ $this->drupalGet('node/add/data');
+ $assert->statusCodeEquals(200);
+ $this->submitForm([
+ 'edit-field-json-metadata-0-value-title' => $dataset_title,
+ 'edit-field-json-metadata-0-value-description' => 'DKANTEST distribution description.',
+ 'edit-field-json-metadata-0-value-accesslevel' => 'public',
+ 'edit-field-json-metadata-0-value-modified-date' => '2020-02-02',
+ 'edit-field-json-metadata-0-value-publisher-publisher-name' => $publisher_name,
+ 'edit-field-json-metadata-0-value-contactpoint-contactpoint-fn' => 'DKANTEST Contact Name',
+ 'edit-field-json-metadata-0-value-contactpoint-contactpoint-hasemail' => 'dkantest@test.com',
+ 'edit-field-json-metadata-0-value-keyword-keyword-0' => $keyword_data,
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-title' => 'distribution title test',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-description' => 'distribution description test',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-select' => 'csv',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl-file-url-type-remote' => 'remote',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl-file-url-remote' => $file_url,
+ ], 'Save');
+ $assert->statusCodeEquals(200);
+ $assert->pageTextContains('Data ' . $dataset_title . ' has been created.');
+
+ // Queues to do import.
+ $this->runQueues(['localize_import', 'datastore_import']);
+ // Did our file import?
+ $this->assertDatasetWasImported($dataset_title);
+
+ // 11_admin_dataset_file_upload.spec.js : Create dataset with remote file :
+ // uploaded dataset files show remote link on edit.
+ $this->drupalGet('admin/dkan/datasets');
+ $this->submitForm([
+ 'edit-title' => $dataset_title,
+ ], 'Filter');
+ $assert->statusCodeEquals(200);
+
+ $page->find('css', '.views-field-nothing > a')->click();
+ $assert->statusCodeEquals(200);
+
+ $assert->elementContains('css', 'h1', 'Edit Data');
+ $assert->elementAttributeContains(
+ 'css',
+ '#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl a',
+ 'href',
+ $file_url
+ );
+ }
+
+ /**
+ * Test creating datasets.
+ *
+ * 11_admin_dataset_file_upload.spec.js : Admin dataset file upload : Create
+ * dataset with file upload.
+ */
+ public function testCreateDatasetWithFileUpload() {
+ /** @var \Drupal\metastore\MetastoreService $metastore_service */
+ $metastore_service = $this->container->get('dkan.metastore.service');
+ /** @var \Drupal\metastore\ValidMetadataFactory $metadata_factory */
+ $metadata_factory = $this->container->get('dkan.metastore.valid_metadata');
+
+ $this->drupalLogin(
+ // @todo Figure out least possible admin permissions.
+ $this->drupalCreateUser([], NULL, TRUE)
+ );
+
+ // Since we don't have JavaScript, we can't use select2 or select_or_other
+ // to add publisher or keyword entities. We create them here with arbitrary
+ // UUIDs so that we can post the names to the form.
+ $publisher_name = uniqid();
+ $metastore_service->post('publisher',
+ $metastore_service->getValidMetadataFactory()->get(
+ json_encode((object) [
+ 'identifier' => '9deadc2f-50e0-512a-af7c-4323697d530d',
+ 'data' => ['name' => $publisher_name],
+ ]), 'publisher', ['method' => 'POST'])
+ );
+ // We need a keyword.
+ $keyword_data = uniqid();
+ $metastore_service->post('keyword',
+ $metastore_service->getValidMetadataFactory()->get(json_encode((object) [
+ 'identifier' => '05b2e74a-eb23-585b-9c1c-4d023e21e8a5',
+ 'data' => $keyword_data,
+ ]), 'keyword', ['method' => 'POST'])
+ );
+
+ // Title for our dataset.
+ $dataset_title = uniqid();
+ // The file we'll upload.
+ $upload_file = realpath(dirname(__DIR__, 4) . '/datastore/tests/data/Bike_Lane.csv');
+
+ $assert = $this->assertSession();
+
+ // 11_admin_dataset_file_upload.spec.js : Create dataset with remote file :
+ // create the dataset, can fill up the form with distribution and submit.
+ $this->drupalGet('node/add/data');
+ $assert->statusCodeEquals(200);
+
+ $page = $this->getSession()->getPage();
+
+ // Use the form.
+ $this->drupalGet('node/add/data');
+ $assert->statusCodeEquals(200);
+ // Add our file to the form.
+ $page->find('css', '#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl-upload')
+ ->attachFile('file://' . $upload_file);
+ $this->submitForm([
+ 'edit-field-json-metadata-0-value-title' => $dataset_title,
+ 'edit-field-json-metadata-0-value-description' => 'DKANTEST distribution description.',
+ 'edit-field-json-metadata-0-value-accesslevel' => 'public',
+ 'edit-field-json-metadata-0-value-modified-date' => '2020-02-02',
+ 'edit-field-json-metadata-0-value-publisher-publisher-name' => $publisher_name,
+ 'edit-field-json-metadata-0-value-contactpoint-contactpoint-fn' => 'DKANTEST Contact Name',
+ 'edit-field-json-metadata-0-value-contactpoint-contactpoint-hasemail' => 'dkantest@test.com',
+ 'edit-field-json-metadata-0-value-keyword-keyword-0' => $keyword_data,
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-title' => 'distribution title test',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-description' => 'distribution description test',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-select' => 'csv',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl-file-url-type-upload' => 'upload',
+ ], 'Save');
+ $assert->statusCodeEquals(200);
+ $assert->pageTextContains('Data ' . $dataset_title . ' has been created.');
+
+ // Queues to do import.
+ $this->runQueues(['localize_import', 'datastore_import']);
+ // Did our file import?
+ $this->assertDatasetWasImported($dataset_title);
+
+ // 11_admin_dataset_file_upload.spec.js : Create dataset with remote file :
+ // uploaded dataset files show remote link on edit.
+ $this->drupalGet('admin/dkan/datasets');
+ $this->submitForm([
+ 'edit-title' => $dataset_title,
+ ], 'Filter');
+ $assert->statusCodeEquals(200);
+
+ // Click on 'edit'.
+ $page->find('css', '.views-field-nothing > a')->click();
+ $assert->statusCodeEquals(200);
+
+ // Find the URL.
+ $assert->elementContains('css', 'h1', 'Edit Data');
+ $uploaded_file_url = $this->baseUrl . '/' . PublicStream::basePath() . '/uploaded_resources/' . basename($upload_file);
+ $assert->elementAttributeContains(
+ 'css',
+ '#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-downloadurl a',
+ 'href',
+ $uploaded_file_url
+ );
+ }
+
+ protected function assertDatasetWasImported(string $dataset_title) {
+ // Get the UUID for the dataset title.
+ /** @var \Drupal\node\NodeStorage $node_storage */
+ $node_storage = $this->container->get('entity_type.manager')
+ ->getStorage('node');
+ $node_ids = $node_storage->getQuery()
+ ->condition('type', 'data')
+ ->condition('title', $dataset_title)
+ ->accessCheck(FALSE)
+ ->execute();
+ $uuid = ($node_storage->load(reset($node_ids)))->uuid();
+
+ // Get the import status for the dataset.
+ /** @var \Drupal\common\DatasetInfo $info_service */
+ $info_service = $this->container->get('dkan.common.dataset_info');
+ $info = $info_service->gather($uuid);
+ $this->assertEquals(
+ 'done',
+ $info['latest_revision']['distributions'][0]['importer_status'] ?? 'not at all done'
+ );
+ }
+
+}
diff --git a/modules/json_form_widget/tests/src/Functional/AdminDatasetJsonFormTest.php b/modules/json_form_widget/tests/src/Functional/AdminDatasetJsonFormTest.php
new file mode 100644
index 0000000000..897cf40770
--- /dev/null
+++ b/modules/json_form_widget/tests/src/Functional/AdminDatasetJsonFormTest.php
@@ -0,0 +1,162 @@
+container->get('dkan.metastore.service');
+ /** @var \Drupal\metastore\ValidMetadataFactory $metadata_factory */
+ $metadata_factory = $this->container->get('dkan.metastore.valid_metadata');
+
+ $this->drupalLogin(
+ // @todo Figure out least possible admin permissions.
+ $this->drupalCreateUser([], NULL, TRUE)
+ );
+ $assert = $this->assertSession();
+
+ // 07_admin_dataset_json_form.spec.js : The dataset form has the correct
+ // required fields.
+ $this->drupalGet('node/add/data');
+ $assert->statusCodeEquals(200);
+
+ $page = $this->getSession()->getPage();
+
+ // These fields should be marked as required.
+ foreach ([
+ '#edit-field-json-metadata-0-value-title',
+ '#edit-field-json-metadata-0-value-description',
+ '#edit-field-json-metadata-0-value-accesslevel',
+ '#edit-field-json-metadata-0-value-modified-date',
+ '#edit-field-json-metadata-0-value-publisher-publisher-name',
+ '#edit-field-json-metadata-0-value-contactpoint-contactpoint-fn',
+ '#edit-field-json-metadata-0-value-contactpoint-contactpoint-hasemail',
+ ] as $locator) {
+ $this->assertEquals(
+ 'required',
+ $page->find('css', $locator)->getAttribute('required')
+ );
+ }
+
+ // 07_admin_dataset_json_form.spec.js : License and format fields are
+ // select_or_other elements in dataset form.
+ // These select elements have an '- Other -' option.
+ foreach ([
+ "#edit-field-json-metadata-0-value-license-select option[value='select_or_other']",
+ "#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-select option[value='select_or_other']",
+ ] as $locator) {
+ $item = $page->find('css', $locator);
+ $this->assertEquals('select_or_other', $item->getValue());
+ }
+ // Assert the existence of the 'other' text element for select_or_other
+ // fields.
+ foreach ([
+ '#edit-field-json-metadata-0-value-license-other.form-url',
+ '#edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-other.form-text',
+ ] as $locator) {
+ $this->assertNotNull($page->find('css', $locator));
+ }
+
+ // 07_admin_dataset_json_form.spec.js : User can create and edit a dataset
+ // with the json form UI. User can delete a dataset.
+ //
+ // Since we don't have JavaScript, we can't use select2 or select_or_other
+ // to add publisher or keyword entities. We create them here with arbitrary
+ // UUIDs so that we can post the names to the form.
+ $publisher_name = uniqid();
+ $metastore_service->post('publisher',
+ $metastore_service->getValidMetadataFactory()->get(
+ json_encode((object) [
+ 'identifier' => '9deadc2f-50e0-512a-af7c-4323697d530d',
+ 'data' => ['name' => $publisher_name],
+ ]), 'publisher', ['method' => 'POST'])
+ );
+ // We need a keyword.
+ $keyword_data = uniqid();
+ $metastore_service->post('keyword',
+ $metastore_service->getValidMetadataFactory()->get(json_encode((object) [
+ 'identifier' => '05b2e74a-eb23-585b-9c1c-4d023e21e8a5',
+ 'data' => $keyword_data,
+ ]), 'keyword', ['method' => 'POST'])
+ );
+
+ // Use the form.
+ $this->drupalGet('node/add/data');
+ $assert->statusCodeEquals(200);
+ $dataset_title = 'DKANTEST dataset title';
+ $this->submitForm([
+ 'edit-field-json-metadata-0-value-title' => $dataset_title,
+ 'edit-field-json-metadata-0-value-description' => 'DKANTEST dataset description.',
+ 'edit-field-json-metadata-0-value-accesslevel' => 'public',
+ 'edit-field-json-metadata-0-value-modified-date' => '2020-02-02',
+ 'edit-field-json-metadata-0-value-publisher-publisher-name' => $publisher_name,
+ 'edit-field-json-metadata-0-value-contactpoint-contactpoint-fn' => 'DKANTEST Contact Name',
+ 'edit-field-json-metadata-0-value-contactpoint-contactpoint-hasemail' => 'dkantest@test.com',
+ 'edit-field-json-metadata-0-value-keyword-keyword-0' => $keyword_data,
+ ], 'Save');
+ $assert->statusCodeEquals(200);
+ $assert->pageTextContains('Data DKANTEST dataset title has been created.');
+
+ // Confirm the default dkan admin view is filtered to show only datasets.
+ $this->drupalGet('admin/dkan/datasets');
+ foreach ($page->findAll('css', 'tbody tr') as $row) {
+ $this->assertStringContainsString(
+ 'dataset',
+ $row->find('css', 'td.views-field-field-data-type')->getText()
+ );
+ }
+
+ // Filter for our dataset.
+ $this->drupalGet('admin/dkan/datasets');
+ $this->submitForm(['edit-title' => $dataset_title], 'Filter');
+
+ // Edit the dataset.
+ $page->find('css', 'tbody > tr:first-of-type > .views-field-nothing > a')->click();
+ $this->assertNotNull($page->find('css', '#edit-field-json-metadata-0-value-title'));
+ $assert->fieldValueEquals('edit-field-json-metadata-0-value-title', $dataset_title);
+ $dataset_new_title = 'NEW dkantest dataset title';
+ $this->submitForm([
+ 'edit-field-json-metadata-0-value-title' => $dataset_new_title,
+ // R/P1Y means Annual.
+ 'edit-field-json-metadata-0-value-accrualperiodicity' => 'R/P1Y',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-title' => 'DKANTEST distribution title text',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-description' => 'DKANTEST distribution description text',
+ 'edit-field-json-metadata-0-value-distribution-distribution-0-distribution-format-select' => 'csv',
+ ], 'Save');
+ $assert->statusCodeEquals(200);
+ $assert->pageTextContains('Data ' . $dataset_new_title . ' has been updated.');
+
+ // User can delete the dataset.
+ $this->drupalGet('admin/dkan/datasets');
+ $this->submitForm([
+ 'edit-node-bulk-form-0' => TRUE,
+ 'edit-action' => 'node_delete_action',
+ ], 'Apply to selected items');
+ $assert->statusCodeEquals(200);
+ // Are you sure?
+ $page->find('css', '#edit-submit')->click();
+ $assert->pageTextContains('Deleted 1 content item.');
+ }
+
+}
diff --git a/modules/json_form_widget/tests/src/Unit/ArrayHelperTest.php b/modules/json_form_widget/tests/src/Unit/ArrayHelperTest.php
index 3d91fd9b10..41866d4752 100644
--- a/modules/json_form_widget/tests/src/Unit/ArrayHelperTest.php
+++ b/modules/json_form_widget/tests/src/Unit/ArrayHelperTest.php
@@ -19,6 +19,10 @@
/**
* Test class for ArrayHelper.
+ *
+ * @group dkan
+ * @group json_form_widget
+ * @group unit
*/
class ArrayHelperTest extends TestCase {
diff --git a/modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php b/modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php
index 1fdab5d1ff..97dabca550 100644
--- a/modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php
+++ b/modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php
@@ -22,6 +22,10 @@
/**
* Test class for JsonFormWidget.
+ *
+ * @group dkan
+ * @group json_form_widget
+ * @group unit
*/
class JsonFormBuilderTest extends TestCase {
diff --git a/modules/json_form_widget/tests/src/Unit/SchemaUiHandlerTest.php b/modules/json_form_widget/tests/src/Unit/SchemaUiHandlerTest.php
index c6b2008eea..4f39051a03 100644
--- a/modules/json_form_widget/tests/src/Unit/SchemaUiHandlerTest.php
+++ b/modules/json_form_widget/tests/src/Unit/SchemaUiHandlerTest.php
@@ -21,6 +21,10 @@
/**
* Test class for SchemaUiHandlerTest.
+ *
+ * @group dkan
+ * @group json_form_widget
+ * @group unit
*/
class SchemaUiHandlerTest extends TestCase {
diff --git a/modules/json_form_widget/tests/src/Unit/StringHelperTest.php b/modules/json_form_widget/tests/src/Unit/StringHelperTest.php
index a3473e5bf0..3b553b1fd9 100644
--- a/modules/json_form_widget/tests/src/Unit/StringHelperTest.php
+++ b/modules/json_form_widget/tests/src/Unit/StringHelperTest.php
@@ -13,6 +13,10 @@
/**
* Test class for StringHelper.
+ *
+ * @group dkan
+ * @group json_form_widget
+ * @group unit
*/
class StringHelperTest extends TestCase {
diff --git a/modules/json_form_widget/tests/src/Unit/ValueHandlerTest.php b/modules/json_form_widget/tests/src/Unit/ValueHandlerTest.php
index 95f79e1b0b..09495e3679 100644
--- a/modules/json_form_widget/tests/src/Unit/ValueHandlerTest.php
+++ b/modules/json_form_widget/tests/src/Unit/ValueHandlerTest.php
@@ -13,6 +13,10 @@
/**
* Test class for ValueHandlerTest.
+ *
+ * @group dkan
+ * @group json_form_widget
+ * @group unit
*/
class ValueHandlerTest extends TestCase {
diff --git a/phpunit.xml b/phpunit.xml
index 37a226bd18..01009b4f5b 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -14,8 +14,14 @@
tests
modules/common/tests
modules/datastore/tests
+ modules/datastore/modules/datastore_mysql_import/tests
modules/dkan_js_frontend/tests
+ modules/frontend/tests
+ modules/harvest/tests
+ modules/json_form_widget/tests
modules/metastore/tests
+ modules/metastore/modules/metastore_admin/tests
+ modules/metastore/modules/metastore_search/tests
modules/sample_content
./