You are here

protected function MediaBridgeFileTest::setUp in Open Social 10.3.x

Same name and namespace in other branches
  1. 10.0.x modules/custom/social_graphql/tests/src/Kernel/MediaBridgeFileTest.php \Drupal\Tests\social_graphql\Kernel\MediaBridgeFileTest::setUp()
  2. 10.1.x modules/custom/social_graphql/tests/src/Kernel/MediaBridgeFileTest.php \Drupal\Tests\social_graphql\Kernel\MediaBridgeFileTest::setUp()
  3. 10.2.x modules/custom/social_graphql/tests/src/Kernel/MediaBridgeFileTest.php \Drupal\Tests\social_graphql\Kernel\MediaBridgeFileTest::setUp()

Set the default field storage backend for fields created during tests.

Overrides FieldKernelTestBase::setUp

File

modules/custom/social_graphql/tests/src/Kernel/MediaBridgeFileTest.php, line 52

Class

MediaBridgeFileTest
Tests that the MediaBridge works with FileItems.

Namespace

Drupal\Tests\social_graphql\Kernel

Code

protected function setUp() {
  parent::setUp();

  // Borrowed from \Drupal\Tests\image\Kernel\ImageItemTest.
  // Sets up an entity and file for our testing.
  $this
    ->installEntitySchema('user');
  $this
    ->installConfig([
    'user',
  ]);

  // Give anonymous users permission to access content, so they can view and
  // download public files.
  $anonymous_role = Role::load(Role::ANONYMOUS_ID);
  $anonymous_role
    ->grantPermission('access content');
  $anonymous_role
    ->save();
  $this
    ->installEntitySchema('file');
  $this
    ->installSchema('file', [
    'file_usage',
  ]);
  FieldStorageConfig::create([
    'field_name' => 'image_test',
    'entity_type' => 'entity_test',
    'type' => 'image',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => 'entity_test',
    'field_name' => 'image_test',
    'bundle' => 'entity_test',
    'settings' => [
      'file_extensions' => 'jpg',
    ],
  ])
    ->save();
  \Drupal::service('file_system')
    ->copy($this->root . '/core/misc/druplicon.png', 'public://social_graphql-example.jpg');
  $this->image = File::create([
    'uri' => 'public://social_graphql-example.jpg',
  ]);
  $this->image
    ->save();
  $this->imageFactory = $this->container
    ->get('image.factory');

  // Ensure we can access our data provider.
  $this->dataProducerPluginManager = $this->container
    ->get('plugin.manager.graphql.data_producer');
}