/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installConfig(['node']); entity_create('node_type', array('type' => 'test_page'))->save(); entity_create('node_type', array('type' => 'story'))->save(); // Create the node preview view mode. EntityViewMode::create(array('id' => 'node.preview', 'targetEntityType' => 'node'))->save(); // Add some id mappings for the dependant migrations. $id_mappings = array('d6_view_modes' => array(array(array(1), array('node', 'preview')), array(array(4), array('node', 'rss')), array(array('teaser'), array('node', 'teaser')), array(array('full'), array('node', 'full'))), 'd6_field_instance' => array(array(array('fieldname', 'page'), array('node', 'fieldname', 'page'))), 'd6_field' => array(array(array('field_test'), array('node', 'field_test')), array(array('field_test_two'), array('node', 'field_test_two')), array(array('field_test_three'), array('node', 'field_test_three')), array(array('field_test_email'), array('node', 'field_test_email')), array(array('field_test_link'), array('node', 'field_test_link')), array(array('field_test_filefield'), array('node', 'field_test_filefield')), array(array('field_test_imagefield'), array('node', 'field_test_imagefield')), array(array('field_test_phone'), array('node', 'field_test_phone')), array(array('field_test_date'), array('node', 'field_test_date')), array(array('field_test_datestamp'), array('node', 'field_test_datestamp')), array(array('field_test_datetime'), array('node', 'field_test_datetime')), array(array('field_test_exclude_unset'), array('node', 'field_test_exclude_unset')))); $this->prepareMigrations($id_mappings); $this->executeMigration('d6_field_formatter_settings'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); entity_create('node_type', array('type' => 'test_page'))->save(); entity_create('node_type', array('type' => 'story'))->save(); // Create the node preview view mode. EntityViewMode::create(array('id' => 'node.preview', 'targetEntityType' => 'node'))->save(); // Add some id mappings for the dependant migrations. $id_mappings = array('d6_view_modes' => array(array(array(1), array('node', 'preview')), array(array(4), array('node', 'rss')), array(array('teaser'), array('node', 'teaser')), array(array('full'), array('node', 'full'))), 'd6_field_instance' => array(array(array('fieldname', 'page'), array('node', 'fieldname', 'page'))), 'd6_field' => array(array(array('field_test'), array('node', 'field_test')), array(array('field_test_two'), array('node', 'field_test_two')), array(array('field_test_three'), array('node', 'field_test_three')), array(array('field_test_email'), array('node', 'field_test_email')), array(array('field_test_link'), array('node', 'field_test_link')), array(array('field_test_filefield'), array('node', 'field_test_filefield')), array(array('field_test_imagefield'), array('node', 'field_test_imagefield')), array(array('field_test_phone'), array('node', 'field_test_phone')), array(array('field_test_date'), array('node', 'field_test_date')), array(array('field_test_datestamp'), array('node', 'field_test_datestamp')), array(array('field_test_datetime'), array('node', 'field_test_datetime')), array(array('field_test_exclude_unset'), array('node', 'field_test_exclude_unset')))); $this->prepareMigrations($id_mappings); $migration = entity_load('migration', 'd6_field_formatter_settings'); $dumps = array($this->getDumpDirectory() . '/ContentNodeFieldInstance.php', $this->getDumpDirectory() . '/ContentNodeField.php', $this->getDumpDirectory() . '/ContentFieldTest.php', $this->getDumpDirectory() . '/ContentFieldTestTwo.php', $this->getDumpDirectory() . '/ContentFieldMultivalue.php'); $this->prepare($migration, $dumps); $executable = new MigrateExecutable($migration, $this); $executable->import(); }
/** * Ensures that entity types with bundles do not break following entity types. */ public function testFieldUIRoutes() { $this->drupalGet('entity_test_no_id/structure/entity_test/fields'); $this->assertText('No fields are present yet.'); $this->drupalGet('admin/config/people/accounts/fields'); $this->assertTitle('Manage fields | Drupal'); $this->assertLocalTasks(); // Test manage display tabs and titles. $this->drupalGet('admin/config/people/accounts/display/compact'); $this->assertResponse(403); $this->drupalGet('admin/config/people/accounts/display'); $this->assertTitle('Manage display | Drupal'); $this->assertLocalTasks(); $edit = array('display_modes_custom[compact]' => TRUE); $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('admin/config/people/accounts/display/compact'); $this->assertTitle('Manage display | Drupal'); $this->assertLocalTasks(); // Test manage form display tabs and titles. $this->drupalGet('admin/config/people/accounts/form-display/register'); $this->assertResponse(403); $this->drupalGet('admin/config/people/accounts/form-display'); $this->assertTitle('Manage form display | Drupal'); $this->assertLocalTasks(); $edit = array('display_modes_custom[register]' => TRUE); $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertResponse(200); $this->drupalGet('admin/config/people/accounts/form-display/register'); $this->assertTitle('Manage form display | Drupal'); $this->assertLocalTasks(); $this->assert(count($this->xpath('//ul/li[1]/a[contains(text(), :text)]', array(':text' => 'Default'))) == 1, 'Default secondary tab is in first position.'); // Create new view mode and verify it's available on the Manage Display // screen after enabling it. EntityViewMode::create(array('id' => 'user.test', 'label' => 'Test', 'targetEntityType' => 'user'))->save(); $this->container->get('router.builder')->rebuildIfNeeded(); $edit = array('display_modes_custom[test]' => TRUE); $this->drupalPostForm('admin/config/people/accounts/display', $edit, t('Save')); $this->assertLink('Test'); // Create new form mode and verify it's available on the Manage Form // Display screen after enabling it. EntityFormMode::create(array('id' => 'user.test', 'label' => 'Test', 'targetEntityType' => 'user'))->save(); $this->container->get('router.builder')->rebuildIfNeeded(); $edit = array('display_modes_custom[test]' => TRUE); $this->drupalPostForm('admin/config/people/accounts/form-display', $edit, t('Save')); $this->assertLink('Test'); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->installEntitySchema('user'); $this->installEntitySchema('node'); // Create the article content type with a text field. $node_type = NodeType::create(['type' => 'article']); $node_type->save(); $field_storage = FieldStorageConfig::create(['field_name' => 'test_field', 'entity_type' => 'node', 'type' => 'text']); $field_storage->save(); $field = FieldConfig::create(['field_name' => 'test_field', 'entity_type' => 'node', 'bundle' => 'article', 'label' => 'Test field']); $field->save(); $view_mode = EntityViewMode::create(['id' => 'node.token', 'targetEntityType' => 'node']); $view_mode->save(); $entity_display = entity_get_display('node', 'article', 'token'); $entity_display->setComponent('test_field', ['type' => 'text_default']); $entity_display->save(); }
/** * {@inheritdoc} */ protected function setUpFixtures() { $this->installEntitySchema('user'); $this->installEntitySchema('entity_test'); $this->installConfig(['entity_test']); EntityViewMode::create(['id' => 'entity_test.foobar', 'targetEntityType' => 'entity_test', 'status' => TRUE, 'enabled' => TRUE, 'label' => 'My view mode'])->save(); $display = EntityViewDisplay::create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'foobar', 'label' => 'My view mode', 'status' => TRUE]); $display->save(); $field_storage = FieldStorageConfig::create(['field_name' => 'test_field', 'entity_type' => 'entity_test', 'type' => 'string']); $field_storage->save(); $field_config = FieldConfig::create(['field_name' => 'test_field', 'entity_type' => 'entity_test', 'bundle' => 'entity_test']); $field_config->save(); // Create some test entities. for ($i = 1; $i <= 3; $i++) { EntityTest::create(['name' => "Article title {$i}", 'test_field' => "Test {$i}"])->save(); } $this->user = User::create(['name' => 'test user']); $this->user->save(); parent::setUpFixtures(); }
/** * Tests view mode setting integration. * * @see comment_entity_view_display_presave() * @see CommentDefaultFormatter::calculateDependencies() */ public function testViewMode() { $mode = Unicode::strtolower($this->randomMachineName()); // Create a new comment view mode and a view display entity. EntityViewMode::create(['id' => "comment.{$mode}", 'targetEntityType' => 'comment', 'settings' => ['comment_type' => 'comment']])->save(); EntityViewDisplay::create(['targetEntityType' => 'comment', 'bundle' => 'comment', 'mode' => $mode])->setStatus(TRUE)->save(); // Create a comment field attached to a host 'entity_test' entity. FieldStorageConfig::create(['entity_type' => 'entity_test', 'type' => 'comment', 'field_name' => $field_name = Unicode::strtolower($this->randomMachineName()), 'settings' => ['comment_type' => 'comment']])->save(); FieldConfig::create(['entity_type' => 'entity_test', 'bundle' => 'entity_test', 'field_name' => $field_name])->save(); $component = ['type' => 'comment_default', 'settings' => ['view_mode' => $mode, 'pager_id' => 0]]; // Create a new 'entity_test' view display on host entity that uses the // custom comment display in field formatter to show the field. EntityViewDisplay::create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default'])->setComponent($field_name, $component)->setStatus(TRUE)->save(); $host_display_id = 'entity_test.entity_test.default'; $comment_display_id = "comment.comment.{$mode}"; // Disable the "comment.comment.$mode" display. EntityViewDisplay::load($comment_display_id)->setStatus(FALSE)->save(); /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $host_display */ $host_display = EntityViewDisplay::load($host_display_id); // Check that the field formatter has been disabled on host view display. $this->assertNull($host_display->getComponent($field_name)); $this->assertTrue($host_display->get('hidden')[$field_name]); // Check that the proper warning has been logged. $arguments = ['@id' => $host_display_id, '@name' => $field_name, '@display' => EntityViewMode::load("comment.{$mode}")->label(), '@mode' => $mode]; $logged = (bool) Database::getConnection()->select('watchdog')->fields('watchdog', ['wid'])->condition('type', 'system')->condition('message', "View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.")->condition('variables', serialize($arguments))->execute()->fetchField(); $this->assertTrue($logged); // Re-enable the comment view display. EntityViewDisplay::load($comment_display_id)->setStatus(TRUE)->save(); // Re-enable the comment field formatter on host entity view display. EntityViewDisplay::load($host_display_id)->setComponent($field_name, $component)->save(); // Delete the "comment.$mode" view mode. EntityViewMode::load("comment.{$mode}")->delete(); // Check that the comment view display entity has been deleted too. $this->assertNull(EntityViewDisplay::load($comment_display_id)); /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */ $host_display = EntityViewDisplay::load($host_display_id); // Check that the field formatter has been disabled on host view display. $this->assertNull($host_display->getComponent($field_name)); $this->assertTrue($host_display->get('hidden')[$field_name]); }
protected function setUp() { parent::setUp(); // Create a field and its storage. $this->fieldName = 'test_field'; $this->label = $this->randomMachineName(); $this->cardinality = 4; $field_storage = array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => $this->cardinality); $field = array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $this->label); $this->displayOptions = array('default' => array('type' => 'field_test_default', 'settings' => array('test_formatter_setting' => $this->randomMachineName())), 'teaser' => array('type' => 'field_test_default', 'settings' => array('test_formatter_setting' => $this->randomMachineName()))); FieldStorageConfig::create($field_storage)->save(); FieldConfig::create($field)->save(); // Create a display for the default view mode. entity_get_display($field['entity_type'], $field['bundle'], 'default')->setComponent($this->fieldName, $this->displayOptions['default'])->save(); // Create a display for the teaser view mode. EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save(); entity_get_display($field['entity_type'], $field['bundle'], 'teaser')->setComponent($this->fieldName, $this->displayOptions['teaser'])->save(); // Create an entity with values. $this->values = $this->_generateTestFieldValues($this->cardinality); $this->entity = EntityTest::create(); $this->entity->{$this->fieldName}->setValue($this->values); $this->entity->save(); }
/** * Tests deleting field. */ public function testDeleteField() { $field_name = 'test_field'; // Create a field storage and a field. $field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field')); $field_storage->save(); $field = FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => 'entity_test')); $field->save(); // Create default and teaser entity display. EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save(); EntityViewDisplay::create(array('targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default'))->setComponent($field_name)->save(); EntityViewDisplay::create(array('targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'teaser'))->setComponent($field_name)->save(); // Check the component exists. $display = entity_get_display('entity_test', 'entity_test', 'default'); $this->assertTrue($display->getComponent($field_name)); $display = entity_get_display('entity_test', 'entity_test', 'teaser'); $this->assertTrue($display->getComponent($field_name)); // Delete the field. $field->delete(); // Check that the component has been removed from the entity displays. $display = entity_get_display('entity_test', 'entity_test', 'default'); $this->assertFalse($display->getComponent($field_name)); $display = entity_get_display('entity_test', 'entity_test', 'teaser'); $this->assertFalse($display->getComponent($field_name)); }
/** * Tests the comment formatter configured with a custom comment view mode. */ public function testViewMode() { $this->drupalLogin($this->webUser); $this->drupalGet($this->node->toUrl()); $comment_text = $this->randomMachineName(); // Post a comment. $this->postComment($this->node, $comment_text); // Comment displayed in 'default' display mode found and has body text. $comment_element = $this->cssSelect('.comment-wrapper'); $this->assertTrue(!empty($comment_element)); $this->assertRaw('<p>' . $comment_text . '</p>'); // Create a new comment entity view mode. $mode = Unicode::strtolower($this->randomMachineName()); EntityViewMode::create(['targetEntityType' => 'comment', 'id' => "comment.{$mode}"])->save(); // Create the corresponding entity view display for article node-type. Note // that this new view display mode doesn't contain the comment body. EntityViewDisplay::create(['targetEntityType' => 'comment', 'bundle' => 'comment', 'mode' => $mode])->setStatus(TRUE)->save(); /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $node_display */ $node_display = EntityViewDisplay::load('node.article.default'); $formatter = $node_display->getComponent('comment'); // Change the node comment field formatter to use $mode mode instead of // 'default' mode. $formatter['settings']['view_mode'] = $mode; $node_display->setComponent('comment', $formatter)->save(); // Reloading the node page to show the same node with its same comment but // with a different display mode. $this->drupalGet($this->node->toUrl()); // The comment should exist but without the body text because we used $mode // mode this time. $comment_element = $this->cssSelect('.comment-wrapper'); $this->assertTrue(!empty($comment_element)); $this->assertNoRaw('<p>' . $comment_text . '</p>'); }
/** * Test tokens on node with the token view mode overriding default formatters. */ public function testTokenViewMode() { $value = 'A really long string that should be trimmed by the special formatter on token view we are going to have.'; // The formatter we are going to use will eventually call Unicode::strlen. // This expects that the Unicode has already been explicitly checked, which // happens in DrupalKernel. But since that doesn't run in kernel tests, we // explicitly call this here. Unicode::check(); // Create a node with a value in the text field and test its token. $entity = Node::create(['title' => 'Test node title', 'type' => 'article', 'test_field' => ['value' => $value, 'format' => $this->testFormat->id()]]); $entity->save(); $this->assertTokens('node', ['node' => $entity], ['test_field' => Markup::create($value)]); // Now, create a token view mode which sets a different format for // test_field. When replacing tokens, this formatter should be picked over // the default formatter for the field type. // @see field_tokens(). $view_mode = EntityViewMode::create(['id' => 'node.token', 'targetEntityType' => 'node']); $view_mode->save(); $entity_display = entity_get_display('node', 'article', 'token'); $entity_display->setComponent('test_field', ['type' => 'text_trimmed', 'settings' => ['trim_length' => 50]]); $entity_display->save(); $this->assertTokens('node', ['node' => $entity], ['test_field' => Markup::create(substr($value, 0, 50))]); }