View source
<?php
namespace Drupal\ds\Tests;
class EntitiesTest extends FastTestBase {
public static $modules = array(
'node',
'field_ui',
'taxonomy',
'block',
'ds',
'ds_test',
'layout_plugin',
'ds_switch_view_mode',
);
protected function setup() {
parent::setup();
\Drupal::configFactory()
->getEditable('ds.settings')
->set('field_template', TRUE)
->save();
}
public function testDsNodeEntity() {
$node = $this
->entitiesTestSetup();
$this
->drupalGet('node/' . $node
->id(), array(
'query' => array(
'store_suggestions' => 1,
),
));
$cache = $this->container
->get('cache.default')
->get('ds_test_suggestions');
$hook_suggestions = $cache->data;
$expected_hook_suggestions = array(
'ds_2col_stacked__node',
'ds_2col_stacked__node_full',
'ds_2col_stacked__node_article',
'ds_2col_stacked__node_article_full',
'ds_2col_stacked__node__1',
);
$this
->assertEqual($hook_suggestions, $expected_hook_suggestions);
$this
->drupalGet('node/' . $node
->id());
$this
->assertRaw('node--view-mode-full', 'Template file found (in full view mode)');
$this
->assertRaw('<div class="field field--name-dynamic-token-fieldnode-token-field field--type-ds field--label-hidden field__item">', t('Token field found'));
$xpath = $this
->xpath('//div[@class="field field--name-dynamic-token-fieldnode-token-field field--type-ds field--label-hidden field__item"]');
$this
->assertEqual((string) $xpath[0]->p, $node
->getTitle(), 'Token field content found');
$this
->assertRaw('group-header', 'Template found (region header)');
$this
->assertRaw('group-footer', 'Template found (region footer)');
$this
->assertRaw('group-left', 'Template found (region left)');
$this
->assertRaw('group-right', 'Template found (region right)');
$this
->assertRaw('<div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">', 'Submitted by line found');
$xpath = $this
->xpath('//div[@class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item"]');
$this
->assertText('Submitted by ' . (string) $xpath[0]->a->span . ' on', 'Submitted by line found');
$teaser = array(
'layout' => 'ds_2col',
);
$teaser_assert = array(
'regions' => array(
'left' => '<td colspan="8">' . t('Left') . '</td>',
'right' => '<td colspan="8">' . t('Right') . '</td>',
),
);
$this
->dsSelectLayout($teaser, $teaser_assert, 'admin/structure/types/manage/article/display/teaser');
$fields = array(
'fields[dynamic_token_field:node-token_field][region]' => 'left',
'fields[body][region]' => 'right',
'fields[node_links][region]' => 'right',
);
$this
->dsConfigureUi($fields, 'admin/structure/types/manage/article/display/teaser');
$edit = array(
'ds_switch' => 'teaser',
);
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save and keep published'));
$this
->assertRaw('node--view-mode-teaser', 'Switched to teaser mode');
$this
->assertRaw('group-left', 'Template found (region left)');
$this
->assertRaw('group-right', 'Template found (region right)');
$this
->assertNoRaw('group-header', 'Template found (no region header)');
$this
->assertNoRaw('group-footer', 'Template found (no region footer)');
$edit = array(
'ds_switch' => '',
);
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save and keep published'));
$this
->assertRaw('node--view-mode-full', 'Switched to full mode again');
$block = array(
'name' => 'Test block field',
);
$this
->dsCreateBlockField($block);
$fields = array(
'fields[dynamic_block_field:node-test_block_field][region]' => 'left',
'fields[dynamic_token_field:node-token_field][region]' => 'hidden',
'fields[body][region]' => 'hidden',
'fields[node_links][region]' => 'hidden',
);
$this
->dsConfigureUi($fields);
$this
->drupalGet('node/' . $node
->id());
$this
->assertRaw('field--name-dynamic-block-fieldnode-test-block-field');
$edit = array(
'display_modes_custom[revision]' => '1',
);
$this
->drupalPostForm('admin/structure/types/manage/article/display', $edit, t('Save'));
$edit = array(
'fs3[override_node_revision]' => TRUE,
'fs3[override_node_revision_view_mode]' => 'revision',
);
$this
->drupalPostForm('admin/structure/ds/settings', $edit, t('Save configuration'));
$edit = array(
'layout' => 'ds_2col',
);
$assert = array(
'regions' => array(
'left' => '<td colspan="8">' . t('Left') . '</td>',
'right' => '<td colspan="8">' . t('Right') . '</td>',
),
);
$this
->dsSelectLayout($edit, $assert, 'admin/structure/types/manage/article/display/revision');
$edit = array(
'fields[body][region]' => 'left',
'fields[node_link][region]' => 'right',
'fields[node_author][region]' => 'right',
);
$this
->dsConfigureUi($edit, 'admin/structure/types/manage/article/display/revision');
$edit = array(
'revision' => TRUE,
'revision_log[0][value]' => 'Test revision',
);
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save and keep published'));
$this
->drupalGet('node/' . $node
->id() . '/revisions');
$this
->assertText('Test revision');
$this
->drupalGet('node/' . $node
->id() . '/revisions/1/view');
$this
->assertText('Body', 'Body label');
$this
->drupalGet('node/' . $node
->id());
$this
->assertNoText('Body', 'No Body label');
$edit = array(
'ds_switch' => '',
'field_tags[0][target_id]' => 'Tag 1',
'field_tags[1][target_id]' => 'Tag 2',
);
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save and keep published'));
$edit = array(
'fields[field_tags][region]' => 'right',
'fields[field_tags][type]' => 'entity_reference_label',
);
$this
->dsConfigureUi($edit, 'admin/structure/types/manage/article/display');
$this
->drupalGet('node/' . $node
->id());
$this
->assertText('Tag 1');
$this
->assertText('Tag 2');
$edit = array(
'fields[field_tags][settings_edit_form][third_party_settings][ds][ds_limit]' => '1',
);
$this
->dsEditLimitSettings($edit, 'field_tags');
$this
->drupalGet('node/' . $node
->id());
$this
->assertText('Tag 1');
$this
->assertNoText('Tag 2');
$edit = array(
'fields[node_title][region]' => 'right',
);
$this
->dsConfigureUi($edit, 'admin/structure/types/manage/article/display');
$edit = array(
'title[0][value]' => 'Hi, I am an article <script>alert(\'with a javascript tag in the title\');</script>',
);
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save and keep published'));
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="field field--name-node-title field--type-ds field--label-hidden field__item"]/h2');
$this
->assertTrimEqual($xpath[0], 'Hi, I am an article <script>alert(\'with a javascript tag in the title\');</script>');
}
}