/**
  * Tests exportContentWithReferences().
  */
 public function testExportWithReferences()
 {
     \Drupal::service('module_installer')->install(['node', 'default_content']);
     \Drupal::service('router.builder')->rebuild();
     $this->defaultContentManager = \Drupal::service('default_content.manager');
     $user = User::create(['name' => 'my username']);
     $user->save();
     // Reload the user to get the proper casted values from the DB.
     $user = User::load($user->id());
     $node_type = NodeType::create(['type' => 'test']);
     $node_type->save();
     $node = Node::create(['type' => $node_type->id(), 'title' => 'test node', 'uid' => $user->id()]);
     $node->save();
     // Reload the node to get the proper casted values from the DB.
     $node = Node::load($node->id());
     /** @var \Symfony\Component\Serializer\Serializer $serializer */
     $serializer = \Drupal::service('serializer');
     \Drupal::service('rest.link_manager')->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
     $expected_node = $serializer->serialize($node, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
     $expected_user = $serializer->serialize($user, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
     $exported_by_entity_type = $this->defaultContentManager->exportContentWithReferences('node', $node->id());
     // Ensure that the node type is not tryed to be exported.
     $this->assertEqual(array_keys($exported_by_entity_type), ['node', 'user']);
     // Ensure the right UUIDs are exported.
     $this->assertEqual([$node->uuid()], array_keys($exported_by_entity_type['node']));
     $this->assertEqual([$user->uuid()], array_keys($exported_by_entity_type['user']));
     // Compare the actual serialized data.
     $this->assertEqual(reset($exported_by_entity_type['node']), $expected_node);
     $this->assertEqual(reset($exported_by_entity_type['user']), $expected_user);
 }
 /**
  * Tests the normalization of comments.
  */
 public function testComment()
 {
     $node_type = NodeType::create(['type' => 'example_type']);
     $node_type->save();
     $account = User::create(['name' => $this->randomMachineName()]);
     $account->save();
     // Add comment type.
     $this->container->get('entity.manager')->getStorage('comment_type')->create(array('id' => 'comment', 'label' => 'comment', 'target_entity_type_id' => 'node'))->save();
     $this->addDefaultCommentField('node', 'example_type');
     $node = Node::create(['title' => $this->randomMachineName(), 'uid' => $account->id(), 'type' => $node_type->id(), 'status' => NODE_PUBLISHED, 'promote' => 1, 'sticky' => 0, 'body' => [['value' => $this->randomMachineName(), 'format' => $this->randomMachineName()]]]);
     $node->save();
     $parent_comment = Comment::create(array('uid' => $account->id(), 'subject' => $this->randomMachineName(), 'comment_body' => ['value' => $this->randomMachineName(), 'format' => NULL], 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment'));
     $parent_comment->save();
     $comment = Comment::create(array('uid' => $account->id(), 'subject' => $this->randomMachineName(), 'comment_body' => ['value' => $this->randomMachineName(), 'format' => NULL], 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'pid' => $parent_comment->id(), 'mail' => '*****@*****.**', 'homepage' => 'http://buytaert.net'));
     $comment->save();
     $original_values = $comment->toArray();
     // Hostname will always be denied view access.
     // No value will exist for name as this is only for anonymous users.
     unset($original_values['hostname'], $original_values['name']);
     $normalized = $this->serializer->normalize($comment, $this->format, ['account' => $account]);
     // Assert that the hostname field does not appear at all in the normalized
     // data.
     $this->assertFalse(array_key_exists('hostname', $normalized), 'Hostname was not found in normalized comment data.');
     /** @var \Drupal\comment\CommentInterface $denormalized_comment */
     $denormalized_comment = $this->serializer->denormalize($normalized, 'Drupal\\comment\\Entity\\Comment', $this->format, ['account' => $account]);
     // Before comparing, unset values that are expected to differ.
     $denormalized_comment_values = $denormalized_comment->toArray();
     unset($denormalized_comment_values['hostname'], $denormalized_comment_values['name']);
     $this->assertEqual($original_values, $denormalized_comment_values, 'The expected comment values are restored after normalizing and denormalizing.');
 }
 /**
  * Adds a content type with a Paragraphs field.
  *
  * @param string $content_type_name
  *   Content type name to be used.
  * @param string $paragraphs_field_name
  *   Paragraphs field name to be used.
  */
 protected function addParagraphedContentType($content_type_name, $paragraphs_field_name)
 {
     // Create the content type.
     $node_type = NodeType::create(['type' => $content_type_name, 'name' => $content_type_name]);
     $node_type->save();
     $this->addParagraphsField($content_type_name, $paragraphs_field_name, 'node');
 }
  public function setUp() {
    parent::setup();

    $this->installConfig(array('pathauto', 'taxonomy', 'system', 'node'));

    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installEntitySchema('taxonomy_term');

    ConfigurableLanguage::createFromLangcode('fr')->save();

    $this->installSchema('node', array('node_access'));
    $this->installSchema('system', array('url_alias', 'sequences', 'router'));

    $type = NodeType::create(['type' => 'page']);
    $type->save();
    node_add_body_field($type);

    $this->nodePattern = $this->createPattern('node', '/content/[node:title]');
    $this->userPattern = $this->createPattern('user', '/users/[user:name]');

    \Drupal::service('router.builder')->rebuild();

    $this->currentUser = entity_create('user', array('name' => $this->randomMachineName()));
    $this->currentUser->save();
  }
Exemple #5
0
 protected function setUp()
 {
     parent::setUp();
     // Ensure the page node type exists.
     NodeType::create(['type' => 'page', 'name' => 'page'])->save();
     ViewTestData::createTestViews(get_class($this), array('field_test_views'));
 }
 /**
  * Tests the normalization of node translations.
  */
 public function testNodeTranslation()
 {
     $node_type = NodeType::create(['type' => 'example_type']);
     $node_type->save();
     $this->container->get('content_translation.manager')->setEnabled('node', 'example_type', TRUE);
     $user = User::create(['name' => $this->randomMachineName()]);
     $user->save();
     $node = Node::create(['title' => $this->randomMachineName(), 'uid' => $user->id(), 'type' => $node_type->id(), 'status' => NODE_PUBLISHED, 'langcode' => 'en', 'promote' => 1, 'sticky' => 0, 'body' => ['value' => $this->randomMachineName(), 'format' => $this->randomMachineName()], 'revision_log' => $this->randomString()]);
     $node->addTranslation('de', ['title' => 'German title', 'body' => ['value' => $this->randomMachineName(), 'format' => $this->randomMachineName()]]);
     $node->save();
     $original_values = $node->toArray();
     $translation = $node->getTranslation('de');
     $original_translation_values = $node->getTranslation('en')->toArray();
     $normalized = $this->serializer->normalize($node, $this->format);
     $this->assertContains(['lang' => 'en', 'value' => $node->getTitle()], $normalized['title'], 'Original language title has been normalized.');
     $this->assertContains(['lang' => 'de', 'value' => $translation->getTitle()], $normalized['title'], 'Translation language title has been normalized.');
     /** @var \Drupal\node\NodeInterface $denormalized_node */
     $denormalized_node = $this->serializer->denormalize($normalized, 'Drupal\\node\\Entity\\Node', $this->format);
     $this->assertSame($denormalized_node->language()->getId(), $denormalized_node->getUntranslated()->language()->getId(), 'Untranslated object is returned from serializer.');
     $this->assertSame('en', $denormalized_node->language()->getId());
     $this->assertTrue($denormalized_node->hasTranslation('de'));
     $this->assertSame($node->getTitle(), $denormalized_node->getTitle());
     $this->assertSame($translation->getTitle(), $denormalized_node->getTranslation('de')->getTitle());
     $this->assertEquals($original_values, $denormalized_node->toArray(), 'Node values are restored after normalizing and denormalizing.');
     $this->assertEquals($original_translation_values, $denormalized_node->getTranslation('en')->toArray(), 'Node values are restored after normalizing and denormalizing.');
 }
 public function testRecreateEntity()
 {
     $type_name = Unicode::strtolower($this->randomMachineName(16));
     $content_type = NodeType::create(['type' => $type_name, 'name' => 'Node type one']);
     $content_type->save();
     node_add_body_field($content_type);
     /** @var \Drupal\Core\Config\StorageInterface $active */
     $active = $this->container->get('config.storage');
     /** @var \Drupal\Core\Config\StorageInterface $sync */
     $sync = $this->container->get('config.storage.sync');
     $config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
     $this->copyConfig($active, $sync);
     // Delete the content type. This will also delete a field storage, a field,
     // an entity view display and an entity form display.
     $content_type->delete();
     $this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
     // Recreate with the same type - this will have a different UUID.
     $content_type = NodeType::create(['type' => $type_name, 'name' => 'Node type two']);
     $content_type->save();
     node_add_body_field($content_type);
     $this->configImporter->reset();
     // A node type, a field, an entity view display and an entity form display
     // will be recreated.
     $creates = $this->configImporter->getUnprocessedConfiguration('create');
     $deletes = $this->configImporter->getUnprocessedConfiguration('delete');
     $this->assertEqual(5, count($creates), 'There are 5 configuration items to create.');
     $this->assertEqual(5, count($deletes), 'There are 5 configuration items to delete.');
     $this->assertEqual(0, count($this->configImporter->getUnprocessedConfiguration('update')), 'There are no configuration items to update.');
     $this->assertIdentical($creates, array_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');
     $this->configImporter->import();
     // Verify that there is nothing more to import.
     $this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
     $content_type = NodeType::load($type_name);
     $this->assertEqual('Node type one', $content_type->label());
 }
 /**
  * Creates a new node type.
  *
  * @param string $label
  *   The human-readable label of the type to create.
  * @param string $machine_name
  *   The machine name of the type to create.
  *
  * @return NodeType
  *   The node type just created.
  */
 protected function createNodeType($label, $machine_name)
 {
     /** @var NodeType $node_type */
     $node_type = NodeType::create(['type' => $machine_name, 'label' => $label]);
     $node_type->save();
     return $node_type;
 }
 /**
  * Tests configuration renaming validation.
  */
 public function testRenameValidation()
 {
     // Create a test entity.
     $test_entity_id = $this->randomMachineName();
     $test_entity = entity_create('config_test', array('id' => $test_entity_id, 'label' => $this->randomMachineName()));
     $test_entity->save();
     $uuid = $test_entity->uuid();
     // Stage the test entity and then delete it from the active storage.
     $active = $this->container->get('config.storage');
     $sync = $this->container->get('config.storage.sync');
     $this->copyConfig($active, $sync);
     $test_entity->delete();
     // Create a content type with a matching UUID in the active storage.
     $content_type = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName(16)), 'name' => $this->randomMachineName(), 'uuid' => $uuid]);
     $content_type->save();
     // Confirm that the staged configuration is detected as a rename since the
     // UUIDs match.
     $this->configImporter->reset();
     $expected = array('node.type.' . $content_type->id() . '::config_test.dynamic.' . $test_entity_id);
     $renames = $this->configImporter->getUnprocessedConfiguration('rename');
     $this->assertIdentical($expected, $renames);
     // Try to import the configuration. We expect an exception to be thrown
     // because the staged entity is of a different type.
     try {
         $this->configImporter->import();
         $this->fail('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
     } catch (ConfigImporterException $e) {
         $this->pass('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
         $expected = array(SafeMarkup::format('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', array('@old_type' => 'node_type', '@new_type' => 'config_test', '@old_name' => 'node.type.' . $content_type->id(), '@new_name' => 'config_test.dynamic.' . $test_entity_id)));
         $this->assertEqual($expected, $this->configImporter->getErrors());
     }
 }
 /**
  * Prepare a node to get suggestions from.
  *
  * Creates a node with two file fields. The first one is not translatable,
  * the second one is. Both fields got two files attached, where one has
  * translatable content (title and atl-text) and the other one not.
  *
  * @return object
  *   The node which is prepared with all needed fields for the suggestions.
  */
 protected function prepareTranslationSuggestions()
 {
     // Create a content type with fields.
     // Only the first field is a translatable reference.
     $type = NodeType::create(['type' => $this->randomMachineName()]);
     $type->save();
     $content_translation_manager = \Drupal::service('content_translation.manager');
     $content_translation_manager->setEnabled('node', $type->id(), TRUE);
     $field1 = FieldStorageConfig::create(array('field_name' => 'field1', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field1->save();
     $field2 = FieldStorageConfig::create(array('field_name' => 'field2', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field2->save();
     // Create field instances on the content type.
     FieldConfig::create(array('field_storage' => $field1, 'bundle' => $type->id(), 'label' => 'Field 1', 'translatable' => FALSE, 'settings' => array()))->save();
     FieldConfig::create(array('field_storage' => $field2, 'bundle' => $type->id(), 'label' => 'Field 2', 'translatable' => TRUE, 'settings' => array()))->save();
     // Create a translatable body field.
     node_add_body_field($type);
     $field = FieldConfig::loadByName('node', $type->id(), 'body');
     $field->setTranslatable(TRUE);
     $field->save();
     // Create 4 nodes to be referenced.
     $references = array();
     for ($i = 0; $i < 4; $i++) {
         $references[$i] = Node::create(array('title' => $this->randomMachineName(), 'body' => $this->randomMachineName(), 'type' => $type->id()));
         $references[$i]->save();
     }
     // Create a node with two translatable and two non-translatable references.
     $node = Node::create(array('title' => $this->randomMachineName(), 'type' => $type->id(), 'language' => 'en', 'body' => $this->randomMachineName(), $field1->getName() => array(array('target_id' => $references[0]->id()), array('target_id' => $references[1]->id())), $field2->getName() => array(array('target_id' => $references[2]->id()), array('target_id' => $references[3]->id()))));
     $node->save();
     $link = MenuLinkContent::create(['link' => [['uri' => 'entity:node/' . $node->id()]], 'title' => 'Node menu link', 'menu_name' => 'main']);
     $link->save();
     $node->link = $link;
     return $node;
 }
 /**
  * Set the default field storage backend for fields created during tests.
  */
 protected function setUp()
 {
     parent::setUp();
     // Create a node type for testing.
     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
     $type->save();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     // Need at least one node type present.
     NodeType::create(['type' => 'testnodetype', 'name' => 'Test node type'])->save();
 }
 /**
  * Performs setup tasks before each individual test method is run.
  */
 public function setUp()
 {
     parent::setUp('content_access');
     // The parent method already installs most needed node and comment schemas,
     // but here we also need the comment statistics.
     $this->installSchema('comment', array('comment_entity_statistics'));
     // Create a node type for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     // Create anonymous user role.
     $role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
     $role->save();
     // Insert the anonymous user into the database, as the user table is inner
     // joined by \Drupal\comment\CommentStorage.
     User::create(array('uid' => 0, 'name' => ''))->save();
     // Create a node with attached comment.
     $this->nodes[0] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'test title'));
     $this->nodes[0]->save();
     $comment_type = CommentType::create(array('id' => 'comment', 'target_entity_type_id' => 'node'));
     $comment_type->save();
     $this->installConfig(array('comment'));
     $this->addDefaultCommentField('node', 'page');
     $comment = Comment::create(array('entity_type' => 'node', 'entity_id' => $this->nodes[0]->id(), 'field_name' => 'comment', 'body' => 'test body', 'comment_type' => $comment_type->id()));
     $comment->save();
     $this->comments[] = $comment;
     $this->nodes[1] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'some title'));
     $this->nodes[1]->save();
     $this->nodes[2] = Node::create(array('status' => NODE_NOT_PUBLISHED, 'type' => 'page', 'title' => 'other title'));
     $this->nodes[2]->save();
     // Also index users, to verify that they are unaffected by the processor.
     $this->index->set('datasources', array('entity:comment', 'entity:node', 'entity:user'));
     $this->index->save();
     $this->index = entity_load('search_api_index', $this->index->id(), TRUE);
 }
 /**
  * Tests the node type config entity.
  */
 public function testNodeType()
 {
     // Create an english test entity.
     $node_type = NodeType::create(array('type' => 'test', 'name' => 'Node type name', 'description' => 'Node type description', 'title_label' => 'Title label', 'langcode' => 'en'));
     $node_type->save();
     $job = tmgmt_job_create('en', 'de');
     $job->translator = 'test_translator';
     $job->save();
     $job_item = tmgmt_job_item_create('config', 'node_type', 'node.type.' . $node_type->id(), array('tjid' => $job->id()));
     $job_item->save();
     $source_plugin = $this->container->get('plugin.manager.tmgmt.source')->createInstance('config');
     $data = $source_plugin->getData($job_item);
     // Test the name property.
     $this->assertEqual($data['name']['#label'], 'Name');
     $this->assertEqual($data['name']['#text'], $node_type->label());
     $this->assertEqual($data['name']['#translate'], TRUE);
     $this->assertEqual($data['description']['#label'], 'Description');
     $this->assertEqual($data['description']['#text'], $node_type->getDescription());
     $this->assertEqual($data['description']['#translate'], TRUE);
     // Test item types.
     $this->assertEqual($source_plugin->getItemTypes()['node_type'], t('Content type'));
     // Now request a translation and save it back.
     $job->requestTranslation();
     $items = $job->getItems();
     $item = reset($items);
     $item->acceptTranslation();
     $data = $item->getData();
     // Check that the translations were saved correctly.
     $language_manager = \Drupal::languageManager();
     $language_manager->setConfigOverrideLanguage($language_manager->getLanguage('de'));
     $node_type = entity_load('node_type', $node_type->id());
     $this->assertEqual($node_type->label(), $data['name']['#translation']['#text']);
     $this->assertEqual($node_type->getDescription(), $data['description']['#translation']['#text']);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installEntitySchema('comment');
     $this->installEntitySchema('taxonomy_term');
     CommentType::create(['id' => 'comment_node_page', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_article', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_blog', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_book', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_forum', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_test_content_type', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'page', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'article', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'blog', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'book', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'forum', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'test_content_type', 'label' => $this->randomMachineName()])->save();
     Vocabulary::create(['vid' => 'test_vocabulary'])->save();
     // Give one unfortunate field instance invalid display settings to ensure
     // that the migration provides an empty array as a default (thus avoiding
     // an "unsupported operand types" fatal).
     Database::getConnection('default', 'migrate')->update('field_config_instance')->fields(array('data' => serialize(array('label' => 'Body', 'widget' => array('type' => 'text_textarea_with_summary', 'settings' => array('rows' => 20, 'summary_rows' => 5), 'weight' => -4, 'module' => 'text'), 'settings' => array('display_summary' => TRUE, 'text_processing' => 1, 'user_register_form' => FALSE), 'display' => array('default' => array('label' => 'hidden', 'type' => 'text_default', 'settings' => array(), 'module' => 'text', 'weight' => 0), 'teaser' => array('label' => 'hidden', 'type' => 'text_summary_or_trimmed', 'settings' => NULL, 'module' => 'text', 'weight' => 0)), 'required' => FALSE, 'description' => ''))))->condition('entity_type', 'node')->condition('bundle', 'article')->condition('field_name', 'body')->execute();
     $this->executeMigrations(['d7_field', 'd7_field_instance', 'd7_view_modes', 'd7_field_formatter_settings']);
 }
 /**
  * Implements setUp().
  */
 function setUp()
 {
     parent::setUp();
     NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
     NodeType::create(['type' => 'article', 'name' => 'Article'])->save();
     $web_user = $this->drupalCreateUser(array('create page content'));
     $this->drupalLogin($web_user);
 }
 /**
  * Creates a new node type.
  *
  * @param string $label
  *   The human-readable label of the type to create.
  * @param string $machine_name
  *   The machine name of the type to create.
  *
  * @return NodeType
  *   The node type just created.
  */
 protected function createNodeType($label, $machine_name)
 {
     /** @var NodeType $node_type */
     $node_type = NodeType::create(['type' => $machine_name, 'label' => $label]);
     $node_type->setThirdPartySetting('content_moderation', 'enabled', TRUE);
     $node_type->save();
     return $node_type;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('filter', 'node'));
     $node_type = NodeType::create(['type' => 'article', 'name' => 'Article']);
     $node_type->save();
     node_add_body_field($node_type);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $node_type = NodeType::create(['type' => 'article', 'name' => t('Article')]);
     $node_type->save();
     $this->nodeAuthor = $this->drupalCreateUser(['create article content', 'skip comment approval', 'post comments', 'edit own comments', 'access comments', 'administer nodes']);
     $this->commentAdmin = $this->drupalCreateUser(['administer comments', 'create article content', 'edit own comments', 'skip comment approval', 'post comments', 'access comments', 'administer nodes']);
     $this->addDefaultCommentField('node', 'article');
 }
 /**
  * Tests the dependency between ImageStyle and entity display components.
  */
 public function testEntityDisplayDependency()
 {
     // Create two image styles.
     /** @var \Drupal\image\ImageStyleInterface $style */
     $style = ImageStyle::create(['name' => 'main_style']);
     $style->save();
     /** @var \Drupal\image\ImageStyleInterface $replacement */
     $replacement = ImageStyle::create(['name' => 'replacement_style']);
     $replacement->save();
     // Create a node-type, named 'note'.
     $node_type = NodeType::create(['type' => 'note']);
     $node_type->save();
     // Create an image field and attach it to the 'note' node-type.
     FieldStorageConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'type' => 'image'])->save();
     FieldConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'bundle' => 'note'])->save();
     // Create the default entity view display and set the 'sticker' field to use
     // the 'main_style' images style in formatter.
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['image_style' => 'main_style']]);
     $view_display->save();
     // Create the default entity form display and set the 'sticker' field to use
     // the 'main_style' images style in the widget.
     /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
     $form_display = EntityFormDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['preview_image_style' => 'main_style']]);
     $form_display->save();
     // Check that the entity displays exists before dependency removal.
     $this->assertNotNull(EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull(EntityFormDisplay::load($form_display->id()));
     // Delete the 'main_style' image style. Before that, emulate the UI process
     // of selecting a replacement style by setting the replacement image style
     // ID in the image style storage.
     /** @var \Drupal\image\ImageStyleStorageInterface $storage */
     $storage = $this->container->get('entity.manager')->getStorage($style->getEntityTypeId());
     $storage->setReplacementId('main_style', 'replacement_style');
     $style->delete();
     // Check that the entity displays exists after dependency removal.
     $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id()));
     // Check that the 'sticker' formatter component exists in both displays.
     $this->assertNotNull($formatter = $view_display->getComponent('sticker'));
     $this->assertNotNull($widget = $form_display->getComponent('sticker'));
     // Check that both displays are using now 'replacement_style' for images.
     $this->assertSame('replacement_style', $formatter['settings']['image_style']);
     $this->assertSame('replacement_style', $widget['settings']['preview_image_style']);
     // Delete the 'replacement_style' without setting a replacement image style.
     $replacement->delete();
     // The entity view and form displays exists after dependency removal.
     $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id()));
     // The 'sticker' formatter component should be hidden in view display.
     $this->assertNull($view_display->getComponent('sticker'));
     $this->assertTrue($view_display->get('hidden')['sticker']);
     // The 'sticker' widget component should be active in form displays, but the
     // image preview should be disabled.
     $this->assertNotNull($widget = $form_display->getComponent('sticker'));
     $this->assertSame('', $widget['settings']['preview_image_style']);
 }
Exemple #21
0
 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "Camelids" node type.
     NodeType::create(['name' => 'Camelids', 'type' => 'camelids'])->save();
     // Create a "Llama" node.
     $node = Node::create(['type' => 'camelids']);
     $node->setTitle('Llama')->setPublished(TRUE)->save();
     return $node;
 }
 protected function setUp()
 {
     parent::setUp();
     $node_type_id = strtolower($this->randomMachineName(8));
     $node_type = NodeType::create(['type' => $node_type_id, 'name' => $node_type_id]);
     $node_type->save();
     FieldStorageConfig::create(['field_name' => 'test_text', 'entity_type' => 'node', 'type' => 'text'])->save();
     FieldConfig::create(['field_name' => 'test_text', 'entity_type' => 'node', 'label' => 'Test', 'bundle' => $node_type_id])->save();
     $this->node = Node::create(['type' => $node_type_id, 'test_text' => array(array('value' => 'Apple', 'format' => NULL), array('value' => 'Banana'), array('value' => 'Carrot'))]);
 }
Exemple #23
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     $this->installEntitySchema('node');
     $node_type = NodeType::create(['type' => 'page', 'name' => 'Basic page', 'description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page."]);
     $node_type->save();
     $node_type = NodeType::create(['type' => 'article', 'name' => 'Article', 'description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts."]);
     $node_type->save();
 }
 protected function setUp()
 {
     parent::setUp();
     // Create an Article node type.
     $article = NodeType::create(array('type' => 'article'));
     $article->save();
     // Test as a non-admin.
     $normal_user = $this->createUser(array(), array('access content'));
     \Drupal::currentUser()->setAccount($normal_user);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp($modules = [])
 {
     parent::setUp();
     $this->admin_user = $this->drupalCreateUser(['administer content types', 'administer node fields']);
     $this->drupalLogin($this->admin_user);
     $node_type = NodeType::create(['type' => 'article', 'name' => 'Article', 'description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts."]);
     $node_type->save();
     entity_create('field_storage_config', array('field_name' => 'field_body', 'entity_type' => 'node', 'type' => 'text_with_summary'))->save();
     entity_create('field_config', array('field_name' => 'field_body', 'label' => 'Body', 'entity_type' => 'node', 'bundle' => 'article'))->save();
 }
Exemple #26
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installEntitySchema('user');
     $this->installEntitySchema('comment');
     $node_type = NodeType::create(['type' => 'page', 'name' => t('Page')]);
     $node_type->save();
     $this->installConfig(['comment']);
     $this->addDefaultCommentField('node', 'page');
 }
Exemple #27
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     ViewTestData::createTestViews(get_class($this), ['views_test_config']);
     // Disable automatic live preview to make the sequence of calls clearer.
     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
     $this->account = $this->drupalCreateUser(['administer views']);
     $this->drupalLogin($this->account);
     NodeType::create(['type' => 'page'])->save();
     FieldConfig::create(['entity_type' => 'node', 'field_name' => 'body', 'bundle' => 'page'])->save();
 }
 /**
  * Tests with both contexts mapped to the same user.
  */
 protected function testContextAvailable()
 {
     NodeType::create(['type' => 'example', 'name' => 'Example'])->save();
     /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
     $condition = \Drupal::service('plugin.manager.condition')->createInstance('condition_test_optional_context')->setContextMapping(['node' => 'node']);
     $definition = new ContextDefinition('entity:node');
     $node = Node::create(['type' => 'example']);
     $contexts['node'] = new Context($definition, $node);
     \Drupal::service('context.handler')->applyContextMapping($condition, $contexts);
     $this->assertFalse($condition->execute());
 }
Exemple #29
0
 protected function setUp()
 {
     parent::setUp();
     // Create the node bundles required for testing.
     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
     $type->save();
     $type = NodeType::create(['type' => 'article', 'name' => 'article']);
     $type->save();
     $type = NodeType::create(['type' => 'test', 'name' => 'test']);
     $type->save();
 }
Exemple #30
0
 protected function setUp()
 {
     parent::setUp();
     // Create the node bundles required for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     // Enable two additional languages.
     ConfigurableLanguage::createFromLangcode('de')->save();
     ConfigurableLanguage::createFromLangcode('it')->save();
     $this->installSchema('node', 'node_access');
 }