X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fparagraphs%2Fsrc%2FTests%2FClassic%2FParagraphsTypesTest.php;fp=web%2Fmodules%2Fcontrib%2Fparagraphs%2Fsrc%2FTests%2FClassic%2FParagraphsTypesTest.php;h=200db0fc5e9abe28595c22248dc890725f78625e;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=185bb94697fb8394cf7612249b5f9e63143531fa;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsTypesTest.php b/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsTypesTest.php index 185bb9469..200db0fc5 100644 --- a/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsTypesTest.php +++ b/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsTypesTest.php @@ -2,8 +2,10 @@ namespace Drupal\paragraphs\Tests\Classic; +use Drupal\paragraphs\Entity\ParagraphsType; + /** - * Tests paragraphs types. + * Tests Paragraphs types. * * @group paragraphs */ @@ -16,7 +18,7 @@ class ParagraphsTypesTest extends ParagraphsTestBase { $this->loginAsAdmin(); // Add a Paragraphed test content. - $this->addParagraphedContentType('paragraphed_test', 'paragraphs'); + $this->addParagraphedContentType('paragraphed_test', 'paragraphs', 'entity_reference_paragraphs'); $this->addParagraphsType('paragraph_type_test'); $this->addParagraphsType('text'); @@ -29,7 +31,8 @@ class ParagraphsTypesTest extends ParagraphsTestBase { // Add a test node with a Paragraph. $this->drupalGet('node/add/paragraphed_test'); $this->drupalPostAjaxForm(NULL, [], 'paragraphs_paragraph_type_test_add_more'); - $this->drupalPostForm(NULL, ['title[0][value]' => 'test_node'], t('Save and publish')); + $edit = ['title[0][value]' => 'test_node']; + $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertText('paragraphed_test test_node has been created.'); // Attempt to delete the paragraph type already used. @@ -39,4 +42,93 @@ class ParagraphsTypesTest extends ParagraphsTestBase { } + /** + * Tests the paragraph type icon settings. + */ + public function testParagraphTypeIcon() { + + /** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */ + $file_usage = \Drupal::service('file.usage'); + + /** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */ + $entity_repository = \Drupal::service('entity.repository'); + + $admin_user = $this->drupalCreateUser([ + 'administer paragraphs types', + 'access files overview', + ]); + $this->drupalLogin($admin_user); + // Add the paragraph type with icon. + $this->drupalGet('admin/structure/paragraphs_type/add'); + $this->assertText('Paragraph type icon'); + $test_files = $this->drupalGetTestFiles('image'); + $fileSystem = \Drupal::service('file_system'); + $edit = [ + 'label' => 'Test paragraph type', + 'id' => 'test_paragraph_type_icon', + 'files[icon_file]' => $fileSystem->realpath($test_files[0]->uri), + ]; + $this->drupalPostForm(NULL, $edit, t('Save and manage fields')); + $this->assertText('Saved the Test paragraph type Paragraphs type.'); + + // Check if the icon has been saved. + $this->drupalGet('admin/structure/paragraphs_type'); + $this->assertRaw('image-test.png'); + $this->clickLink('Edit'); + $this->assertText('image-test.png'); + + // Check that the icon file usage has been registered. + $paragraph_type = ParagraphsType::load('test_paragraph_type_icon'); + $file = $entity_repository->loadEntityByUuid('file', $paragraph_type->get('icon_uuid')); + $usages = $file_usage->listUsage($file); + $this->assertEqual($usages['paragraphs']['paragraphs_type']['test_paragraph_type_icon'], 1); + + // Tests calculateDependencies method. + $dependencies = $paragraph_type->getDependencies(); + $dependencies_uuid[] = explode(':', $dependencies['content'][0]); + $this->assertEqual($paragraph_type->get('icon_uuid'), $dependencies_uuid[0][2]); + + // Delete the icon. + $this->drupalGet('admin/structure/paragraphs_type/test_paragraph_type_icon'); + $this->drupalPostAjaxForm(NULL, [], 'icon_file_remove_button'); + $this->drupalPostForm(NULL, [], t('Save')); + + // Check that the icon file usage has been deregistered. + $usages = $file_usage->listUsage($file); + $this->assertEqual($usages, []); + } + + /** + * Test the paragraph type description settings. + */ + public function testParagraphTypeDescription() { + $admin_user = $this->drupalCreateUser(['administer paragraphs types']); + $this->drupalLogin($admin_user); + // Add the paragraph type with description. + $this->drupalGet('admin/structure/paragraphs_type/add'); + $this->assertText('Description'); + $label = 'Test paragraph type'; + $description_markup = 'Use Test paragraph type to test the functionality of descriptions.'; + $description_text = 'Use Test paragraph type to test the functionality of descriptions.'; + $edit = [ + 'label' => $label, + 'id' => 'test_paragraph_type_description', + 'description' => $description_markup, + ]; + $this->drupalPostForm(NULL, $edit, t('Save and manage fields')); + $this->assertText("Saved the $label Paragraphs type."); + + // Check if the description has been saved. + $this->drupalGet('admin/structure/paragraphs_type'); + $this->assertText('Description'); + $this->assertText($description_text); + $this->assertRaw($description_markup); + //Check if description is at Description column + $header_position = count($this->xpath('//table/thead/tr/th[.="Description"]/preceding-sibling::th')); + $row_position = count($this->xpath('//table/tbody/tr/td[.="' . $description_text . '"]/preceding-sibling::td')); + $this->assertEqual($header_position, $row_position); + $this->clickLink('Edit'); + $this->assertText('Use <em>Test paragraph type</em> to test the functionality of descriptions.'); + } + }