Chris@0: drupalGet($row_plugin_url);
Chris@0: $this->assertFieldByName('row[type]', 'fields', 'The default row plugin selected in the UI should be fields.');
Chris@0:
Chris@0: $edit = [
Chris@0: 'row[type]' => 'test_row'
Chris@0: ];
Chris@0: $this->drupalPostForm(NULL, $edit, t('Apply'));
Chris@0: $this->assertFieldByName('row_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
Chris@0: $random_name = $this->randomMachineName();
Chris@0: $edit = [
Chris@0: 'row_options[test_option]' => $random_name
Chris@0: ];
Chris@0: $this->drupalPostForm(NULL, $edit, t('Apply'));
Chris@0: $this->drupalGet($row_options_url);
Chris@0: $this->assertFieldByName('row_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
Chris@0:
Chris@0: $this->drupalPostForm($view_edit_url, [], t('Save'));
Chris@0: $this->assertLink(t('Test row plugin'), 0, 'Make sure the test row plugin is shown in the UI');
Chris@0:
Chris@0: $view = Views::getView($view_name);
Chris@0: $view->initDisplay();
Chris@0: $row = $view->display_handler->getOption('row');
Chris@0: $this->assertEqual($row['type'], 'test_row', 'Make sure that the test_row got saved as used row plugin.');
Chris@0: $this->assertEqual($row['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.');
Chris@0:
Chris@0: // Change the row plugin to fields using ajax.
Chris@0: // Note: this is the best approximation we can achieve, because we cannot
Chris@0: // simulate the 'openDialog' command in
Chris@0: // WebTestBase::drupalProcessAjaxResponse(), hence we have to make do.
Chris@0: $row_plugin_url_ajax = str_replace('/nojs/', '/ajax/', $row_plugin_url);
Chris@0: $ajax_settings = [
Chris@0: 'accepts' => 'application/vnd.drupal-ajax',
Chris@0: 'submit' => [
Chris@0: '_triggering_element_name' => 'op',
Chris@0: '_triggering_element_value' => 'Apply',
Chris@0: ],
Chris@0: 'url' => $row_plugin_url_ajax,
Chris@0: ];
Chris@0: $this->drupalPostAjaxForm($row_plugin_url, ['row[type]' => 'fields'], NULL, $row_plugin_url_ajax, [], [], NULL, $ajax_settings);
Chris@0: $this->drupalGet($row_plugin_url);
Chris@0: $this->assertResponse(200);
Chris@0: $this->assertFieldByName('row[type]', 'fields', 'Make sure that the fields got saved as used row plugin.');
Chris@0:
Chris@0: // Ensure that entity row plugins appear.
Chris@0: $view_name = 'content';
Chris@0: $row_plugin_url = "admin/structure/views/nojs/display/$view_name/default/row";
Chris@0: $row_options_url = "admin/structure/views/nojs/display/$view_name/default/row_options";
Chris@0:
Chris@0: $this->drupalGet($row_plugin_url);
Chris@0: $this->assertFieldByName('row[type]', 'entity:node');
Chris@0: $this->drupalPostForm(NULL, ['row[type]' => 'entity:node'], t('Apply'));
Chris@0: $this->assertUrl($row_options_url);
Chris@0: $this->assertFieldByName('row_options[view_mode]', 'teaser');
Chris@0:
Chris@0: // Change the teaser label to have markup so we can test escaping.
Chris@0: $teaser = EntityViewMode::load('node.teaser');
Chris@0: $teaser->set('label', 'Teaser markup');
Chris@0: $teaser->save();
Chris@0: $this->drupalGet('admin/structure/views/view/frontpage/edit/default');
Chris@0: $this->assertEscaped('Teaser markup');
Chris@0: }
Chris@0:
Chris@0: }