Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / tests / src / Kernel / ParagraphsIsChangedTest.php
1 <?php
2
3 namespace Drupal\Tests\paragraphs\Kernel;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\KernelTests\KernelTestBase;
8 use Drupal\paragraphs\Entity\Paragraph;
9 use Drupal\paragraphs\Entity\ParagraphsType;
10
11 /**
12  * Tests \Drupal\Paragraphs\Entity\Paragraph::isChanged().
13  *
14  * @group paragraphs
15  */
16 class ParagraphsIsChangedTest extends KernelTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = [
22     'paragraphs',
23     'user',
24     'system',
25     'field',
26     'entity_reference_revisions',
27     'file',
28   ];
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function setUp() {
34     parent::setUp();
35     $this->installEntitySchema('user');
36     $this->installEntitySchema('paragraph');
37     $this->installSchema('system', ['sequences']);
38     \Drupal::moduleHandler()->loadInclude('paragraphs', 'install');
39
40     // Create a text paragraph type.
41     $paragraph_type = ParagraphsType::create([
42       'label' => 'text_paragraph',
43       'id' => 'text_paragraph',
44     ]);
45     $paragraph_type->save();
46     $this->addParagraphsField('text_paragraph', 'text', 'string');
47   }
48
49   /**
50    * Tests the functionality of the isChanged() function.
51    */
52   public function testIsChanged() {
53     // Create a paragraph.
54     $paragraph = Paragraph::create([
55       'title' => 'Paragraph',
56       'type' => 'text_paragraph',
57       'text' => 'Text Paragraph',
58     ]);
59     $this->assertTrue($paragraph->isChanged(), 'The paragraph is a new entity.');
60
61     // Save the paragraph and assert no changes.
62     $paragraph->save();
63     $this->assertFalse($paragraph->isChanged(), 'Paragraph::isChanged() found no changes after the entity has been saved.');
64
65     // Update the revision author field, which should be skipped from checking
66     // for changes in Paragraph::isChanged().
67     $paragraph->setRevisionAuthorId(3);
68     $this->assertFalse($paragraph->isChanged(), 'Paragraph::isChanged() found no changes after updating revision_uid field.');
69
70     $paragraph->set('text', 'New text');
71     $this->assertTrue($paragraph->isChanged(), 'Paragraph::isChanged() found changes after updating text field.');
72   }
73
74   /**
75    * Adds a field to a given paragraph type.
76    *
77    * @param string $paragraph_type_name
78    *   Paragraph type name to be used.
79    * @param string $field_name
80    *   Paragraphs field name to be used.
81    * @param string $field_type
82    *   Type of the field.
83    * @param array $field_edit
84    *   Edit settings for the field.
85    */
86   protected function addParagraphsField($paragraph_type_name, $field_name, $field_type, array $field_edit = []) {
87     // Add a paragraphs field.
88     $field_storage = FieldStorageConfig::create([
89       'field_name' => $field_name,
90       'entity_type' => 'paragraph',
91       'type' => $field_type,
92       'cardinality' => '-1',
93       'settings' => $field_edit,
94     ]);
95     $field_storage->save();
96     $field = FieldConfig::create([
97       'field_storage' => $field_storage,
98       'bundle' => $paragraph_type_name,
99       'settings' => [
100         'handler' => 'default:paragraph',
101         'handler_settings' => ['target_bundles' => NULL],
102       ],
103     ]);
104     $field->save();
105   }
106
107 }