public function FileEntityAdminTest::testUsageView in File Entity (fieldable files) 8.2
Tests the file usage view.
File
- tests/
src/ Functional/ FileEntityAdminTest.php, line 309
Class
- FileEntityAdminTest
- Test file administration page functionality.
Namespace
Drupal\Tests\file_entity\FunctionalCode
public function testUsageView() {
$this->container
->get('module_installer')
->install(array(
'node',
));
\Drupal::service('router.builder')
->rebuild();
$file = $this
->createFileEntity(array(
'uid' => $this->userAdmin,
));
// @todo Next line causes an exception, core issue https://www.drupal.org/node/2462283
$this
->drupalLogin($this->userAdmin);
// Check the usage links on the file overview.
$this
->drupalGet('admin/content/files');
$this
->assertLink('0 places');
$this
->assertNoLink('1 place');
// Check the usage view.
$this
->clickLink('0 places');
$this
->assertText('This file is not currently used.');
// Attach a file field to article nodes.
$content_type = $this
->drupalCreateContentType();
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'used_file',
'entity_type' => 'node',
'type' => 'file',
));
$field_storage
->save();
$field_instance = FieldConfig::create(array(
'field_storage' => $field_storage,
'entity_type' => 'node',
'bundle' => $content_type
->id(),
));
$field_instance
->save();
// Create a node using a file.
$node = Node::create(array(
'title' => 'An article that uses a file',
'type' => $content_type
->id(),
'used_file' => array(
'target_id' => $file
->id(),
'display' => 1,
'description' => '',
),
));
$node
->save();
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache();
\Drupal::entityTypeManager()
->getStorage('file')
->resetCache();
// Check that the usage link is updated.
$this
->drupalGet('admin/content/files');
$this
->assertLink('1 place');
// Check that the using node shows up on the usage view.
$this
->clickLink('1 place');
$this
->assertLink('An article that uses a file');
// Check local tasks.
$this
->clickLink('View');
$this
->assertResponse(200);
$this
->clickLink('Usage');
$this
->assertResponse(200);
}