function CreateTestContentEntitiesTrait::createContent

Same name in other branches
  1. 8.9.x core/modules/migrate_drupal/tests/src/Traits/CreateTestContentEntitiesTrait.php \Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait::createContent()
  2. 10 core/modules/migrate_drupal/tests/src/Traits/CreateTestContentEntitiesTrait.php \Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait::createContent()
  3. 11.x core/modules/migrate_drupal/tests/src/Traits/CreateTestContentEntitiesTrait.php \Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait::createContent()

Create several pieces of generic content.

5 calls to CreateTestContentEntitiesTrait::createContent()
MigrateDrupal6AuditIdsTest::testAllMigrationsWithIdConflicts in core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php
Tests all migrations with ID conflicts.
MigrateDrupal7AuditIdsTest::testAllMigrationsWithIdConflicts in core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php
Tests all migrations with ID conflicts.
MigrateNodeCompleteTest::setUp in core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeCompleteTest.php
MigrateNodeCompleteTest::setUp in core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php
MigrateUpgradeExecuteTestBase::setUp in core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php

File

core/modules/migrate_drupal/tests/src/Traits/CreateTestContentEntitiesTrait.php, line 55

Class

CreateTestContentEntitiesTrait
Provides helper methods for creating test content.

Namespace

Drupal\Tests\migrate_drupal\Traits

Code

protected function createContent() {
    $entity_type_manager = \Drupal::entityTypeManager();
    // @todo Remove aggregator in https://www.drupal.org/project/drupal/issues/3264120
    // Create an aggregator feed.
    if ($entity_type_manager->hasDefinition('aggregator_feed')) {
        $feed = $entity_type_manager->getStorage('aggregator_feed')
            ->create([
            'title' => 'feed',
            'url' => 'http://www.example.com',
        ]);
        $feed->save();
        // Create an aggregator feed item.
        $item = $entity_type_manager->getStorage('aggregator_item')
            ->create([
            'title' => 'feed item',
            'fid' => $feed->id(),
            'link' => 'http://www.example.com',
        ]);
        $item->save();
    }
    // Create a block content.
    if ($entity_type_manager->hasDefinition('block_content')) {
        $block = $entity_type_manager->getStorage('block_content')
            ->create([
            'info' => 'block',
            'type' => 'block',
        ]);
        $block->save();
    }
    // Create a node.
    if ($entity_type_manager->hasDefinition('node')) {
        $node = $entity_type_manager->getStorage('node')
            ->create([
            'type' => 'page',
            'title' => 'page',
        ]);
        $node->save();
        // Create a comment.
        if ($entity_type_manager->hasDefinition('comment')) {
            $comment = $entity_type_manager->getStorage('comment')
                ->create([
                'comment_type' => 'comment',
                'field_name' => 'comment',
                'entity_type' => 'node',
                'entity_id' => $node->id(),
            ]);
            $comment->save();
        }
    }
    // Create a file.
    if ($entity_type_manager->hasDefinition('file')) {
        $file = $entity_type_manager->getStorage('file')
            ->create([
            'uri' => 'public://example.txt',
        ]);
        $file->save();
    }
    // Create a menu link.
    if ($entity_type_manager->hasDefinition('menu_link_content')) {
        $menu_link = $entity_type_manager->getStorage('menu_link_content')
            ->create([
            'title' => 'menu link',
            'link' => [
                'uri' => 'http://www.example.com',
            ],
            'menu_name' => 'tools',
        ]);
        $menu_link->save();
    }
    // Create a taxonomy term.
    if ($entity_type_manager->hasDefinition('taxonomy_term')) {
        $term = $entity_type_manager->getStorage('taxonomy_term')
            ->create([
            'name' => 'term',
            'vid' => 'term',
        ]);
        $term->save();
    }
    // Create a user.
    if ($entity_type_manager->hasDefinition('user')) {
        $user = $entity_type_manager->getStorage('user')
            ->create([
            'name' => 'user',
            'mail' => 'user@example.com',
        ]);
        $user->save();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.