Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Classic / ParagraphsTypesTest.php
1 <?php
2
3 namespace Drupal\paragraphs\Tests\Classic;
4
5 use Drupal\paragraphs\Entity\ParagraphsType;
6
7 /**
8  * Tests Paragraphs types.
9  *
10  * @group paragraphs
11  */
12 class ParagraphsTypesTest extends ParagraphsTestBase {
13
14   /**
15    * Tests the deletion of Paragraphs types.
16    */
17   public function testRemoveTypesWithContent() {
18     $this->loginAsAdmin();
19
20     // Add a Paragraphed test content.
21     $this->addParagraphedContentType('paragraphed_test', 'paragraphs', 'entity_reference_paragraphs');
22     $this->addParagraphsType('paragraph_type_test');
23     $this->addParagraphsType('text');
24
25     // Attempt to delete the content type not used yet.
26     $this->drupalGet('admin/structure/paragraphs_type');
27     $this->clickLink(t('Delete'));
28     $this->assertText('This action cannot be undone.');
29     $this->clickLink(t('Cancel'));
30
31     // Add a test node with a Paragraph.
32     $this->drupalGet('node/add/paragraphed_test');
33     $this->drupalPostAjaxForm(NULL, [], 'paragraphs_paragraph_type_test_add_more');
34     $edit = ['title[0][value]' => 'test_node'];
35     $this->drupalPostForm(NULL, $edit, t('Save'));
36     $this->assertText('paragraphed_test test_node has been created.');
37
38     // Attempt to delete the paragraph type already used.
39     $this->drupalGet('admin/structure/paragraphs_type');
40     $this->clickLink(t('Delete'));
41     $this->assertText('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.');
42
43   }
44
45   /**
46    * Tests the paragraph type icon settings.
47    */
48   public function testParagraphTypeIcon() {
49
50     /** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
51     $file_usage = \Drupal::service('file.usage');
52
53     /** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
54     $entity_repository = \Drupal::service('entity.repository');
55
56     $admin_user = $this->drupalCreateUser([
57       'administer paragraphs types',
58       'access files overview',
59     ]);
60     $this->drupalLogin($admin_user);
61     // Add the paragraph type with icon.
62     $this->drupalGet('admin/structure/paragraphs_type/add');
63     $this->assertText('Paragraph type icon');
64     $test_files = $this->drupalGetTestFiles('image');
65     $fileSystem = \Drupal::service('file_system');
66     $edit = [
67       'label' => 'Test paragraph type',
68       'id' => 'test_paragraph_type_icon',
69       'files[icon_file]' => $fileSystem->realpath($test_files[0]->uri),
70     ];
71     $this->drupalPostForm(NULL, $edit, t('Save and manage fields'));
72     $this->assertText('Saved the Test paragraph type Paragraphs type.');
73
74     // Check if the icon has been saved.
75     $this->drupalGet('admin/structure/paragraphs_type');
76     $this->assertRaw('image-test.png');
77     $this->clickLink('Edit');
78     $this->assertText('image-test.png');
79
80     // Check that the icon file usage has been registered.
81     $paragraph_type = ParagraphsType::load('test_paragraph_type_icon');
82     $file = $entity_repository->loadEntityByUuid('file', $paragraph_type->get('icon_uuid'));
83     $usages = $file_usage->listUsage($file);
84     $this->assertEqual($usages['paragraphs']['paragraphs_type']['test_paragraph_type_icon'], 1);
85
86     // Tests calculateDependencies method.
87     $dependencies = $paragraph_type->getDependencies();
88     $dependencies_uuid[] = explode(':', $dependencies['content'][0]);
89     $this->assertEqual($paragraph_type->get('icon_uuid'), $dependencies_uuid[0][2]);
90
91     // Delete the icon.
92     $this->drupalGet('admin/structure/paragraphs_type/test_paragraph_type_icon');
93     $this->drupalPostAjaxForm(NULL, [], 'icon_file_remove_button');
94     $this->drupalPostForm(NULL, [], t('Save'));
95
96     // Check that the icon file usage has been deregistered.
97     $usages = $file_usage->listUsage($file);
98     $this->assertEqual($usages, []);
99   }
100
101   /**
102    * Test the paragraph type description settings.
103    */
104   public function testParagraphTypeDescription() {
105     $admin_user = $this->drupalCreateUser(['administer paragraphs types']);
106     $this->drupalLogin($admin_user);
107     // Add the paragraph type with description.
108     $this->drupalGet('admin/structure/paragraphs_type/add');
109     $this->assertText('Description');
110     $label = 'Test paragraph type';
111     $description_markup = 'Use <em>Test paragraph type</em> to test the functionality of descriptions.';
112     $description_text = 'Use Test paragraph type to test the functionality of descriptions.';
113     $edit = [
114       'label' => $label,
115       'id' => 'test_paragraph_type_description',
116       'description' => $description_markup,
117     ];
118     $this->drupalPostForm(NULL, $edit, t('Save and manage fields'));
119     $this->assertText("Saved the $label Paragraphs type.");
120
121     // Check if the description has been saved.
122     $this->drupalGet('admin/structure/paragraphs_type');
123     $this->assertText('Description');
124     $this->assertText($description_text);
125     $this->assertRaw($description_markup);
126     //Check if description is at Description column
127     $header_position = count($this->xpath('//table/thead/tr/th[.="Description"]/preceding-sibling::th'));
128     $row_position = count($this->xpath('//table/tbody/tr/td[.="' . $description_text . '"]/preceding-sibling::td'));
129     $this->assertEqual($header_position, $row_position);
130     $this->clickLink('Edit');
131     $this->assertText('Use &lt;em&gt;Test paragraph type&lt;/em&gt; to test the functionality of descriptions.');
132   }
133
134 }