Completed
Pull Request — 8.x-1.x (#24)
by Dave
02:20
created

EmbedButtonAdminTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testButtonValidation() 0 22 1
B testEmbedButtonAdmin() 0 45 1
A testCKEditorButtonConflict() 0 13 1
1
<?php
2
3
/**
4
 * @file
5
 * Contains \Drupal\embed\Tests\EmbedButtonAdminTest.
6
 */
7
8
namespace Drupal\embed\Tests;
9
10
/**
11
 * Tests the administrative UI.
12
 *
13
 * @group embed
14
 */
15
class EmbedButtonAdminTest extends EmbedTestBase {
16
17
  /**
18
   * Tests the embed_button administration functionality.
19
   */
20
  public function testEmbedButtonAdmin() {
21
    // Ensure proper access to the Embed settings page.
22
    $this->drupalGet('admin/config/content/embed');
23
    $this->assertResponse(403);
24
25
    $this->drupalLogin($this->adminUser);
26
    $this->drupalGet('admin/config/content/embed');
27
    $this->assertResponse(200);
28
29
    // Add embed button.
30
    $this->clickLink('Add embed button');
31
    $button_id = strtolower($this->randomMachineName());
32
    $button_label = $this->randomMachineName();
33
    $edit = array(
34
      'id' => $button_id,
35
      'label' => $button_label,
36
      'type_id' => 'embed_test_default',
37
    );
38
    $this->drupalPostForm(NULL, $edit, 'Save');
39
    // Ensure that the newly created button is listed.
40
    $this->drupalGet('admin/config/content/embed');
41
    $this->assertText($button_label, 'Test embed_button appears on the list page');
42
43
    // Edit embed button.
44
    $this->drupalGet('admin/config/content/embed/button/manage/' . $button_id);
45
    $new_button_label = $this->randomMachineName();
46
    $edit = array(
47
      'label' => $new_button_label,
48
    );
49
    $this->drupalPostForm(NULL, $edit, 'Save');
50
    // Ensure that name and label has been changed.
51
    $this->drupalGet('admin/config/content/embed');
52
    $this->assertText($new_button_label, 'New label appears on the list page');
53
    $this->assertNoText($button_label, 'Old label does not appears on the list page');
54
55
    // Delete embed button.
56
    $this->drupalGet('admin/config/content/embed/button/manage/' . $button_id . '/delete');
57
    $this->drupalPostForm(NULL, array(), 'Delete');
58
    // Ensure that the deleted embed button no longer exists.
59
    $this->drupalGet('admin/config/content/embed/button/manage/' . $button_id);
60
    $this->assertResponse(404, 'Deleted embed button no longer exists.');
61
    // Ensure that the deleted button is no longer listed.
62
    $this->drupalGet('admin/config/content/embed');
63
    $this->assertNoText($button_label, 'Test embed_button does not appears on the list page');
64
  }
65
66
  public function testButtonValidation() {
67
    $this->drupalLogin($this->adminUser);
68
    $button_id = strtolower($this->randomMachineName());
69
    $edit = array(
70
      'id' => $button_id,
71
      'label' => $this->randomMachineName(),
72
      'type_id' => 'embed_test_aircraft',
73
    );
74
    $this->drupalPostAjaxForm('admin/config/content/embed/button/add', $edit, 'type_id');
75
    $this->assertFieldByName('type_settings[aircraft_type]', 'fixed-wing');
76
77
    $edit['type_settings[aircraft_type]'] = 'invalid';
78
    $this->drupalPostForm(NULL, $edit, 'Save');
79
    $this->assertText('Cannot select invalid aircraft type.');
80
81
    $edit['type_settings[aircraft_type]'] = 'helicopters';
82
    $this->drupalPostForm(NULL, $edit, 'Save');
83
    $this->assertText('Helicopters are just rotorcraft.');
84
85
    $this->drupalGet('admin/config/content/embed/button/manage/' . $button_id);
86
    $this->assertFieldByName('type_settings[aircraft_type]', 'rotorcraft');
87
  }
88
89
  public function testCKEditorButtonConflict() {
90
    $this->drupalLogin($this->adminUser);
91
    $this->drupalGet('admin/config/content/embed/button/add');
92
93
    $button_id = strtolower($this->randomMachineName());
0 ignored issues
show
Unused Code introduced by
$button_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
94
    $button_label = $this->randomMachineName();
95
    $edit = array(
96
      'id' => 'DrupalImage',
97
      'label' => $button_label,
98
      'type_id' => 'embed_test_default',
99
    );
100
    $this->drupalPostForm(NULL, $edit, 'Save');
101
  }
102
103
}
104