Completed
Pull Request — 8.x-1.x (#5)
by Vijay
02:37
created

VideoBundleTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 30 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 40
rs 10
wmc 2
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testMediaBundleCreationFromModule() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Drupal\media\Tests;
4
5
use Drupal\simpletest\WebTestBase;
6
7
/**
8
 * Ensures that media bundle for videos can be created.
9
 *
10
 * @group media
11
 */
12
class VideoBundleTest extends WebTestBase {
13
14
    /**
15
     * Modules to enable.
16
     *
17
     * @var array
18
     */
19
    public static $modules = ['media', 'media_entity', 'video_embed_field', 'video_embed_media',];
20
21
    /**
22
     * The test media bundle.
23
     *
24
     * @var \Drupal\media_entity\MediaBundleInterface
25
     */
26
    protected $testBundle;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function setUp() {
32
        parent::setUp();
33
        $this->testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('video');
34
    }
35
36
    /**
37
     * Tests video media bundle creation from config files.
38
     */
39 View Code Duplication
    public function testMediaBundleCreationFromModule() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
        $type_configuration = [
41
            'source_field' => 'field_media_video_embed_field'
42
        ];
43
44
        $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
45
        $this->assertEqual($this->testBundle->get('label'), 'Video', 'Correct label detected.');
46
        $this->assertEqual($this->testBundle->get('description'), 'Use Video for embedding videos hosted by YouTube, Vimeo, or some other provider.', 'Correct description detected.');
47
        $this->assertEqual($this->testBundle->get('type'), 'video_embed_field', 'Correct plugin ID detected.');
48
        $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
49
        $this->assertEqual($this->testBundle->get('field_map'), [], 'Correct field map detected.');
50
    }
51
}
52