You are here

public function ParagraphsIsChangedTest::testIsChanged in Paragraphs 8

Tests the functionality of the isChanged() function.

File

tests/src/Kernel/ParagraphsIsChangedTest.php, line 52

Class

ParagraphsIsChangedTest
Tests \Drupal\Paragraphs\Entity\Paragraph::isChanged().

Namespace

Drupal\Tests\paragraphs\Kernel

Code

public function testIsChanged() {

  // Create a paragraph.
  $paragraph = Paragraph::create([
    'title' => 'Paragraph',
    'type' => 'text_paragraph',
    'text' => 'Text Paragraph',
  ]);
  $this
    ->assertTrue($paragraph
    ->isChanged(), 'The paragraph is a new entity.');

  // Save the paragraph and assert no changes.
  $paragraph
    ->save();
  $this
    ->assertFalse($paragraph
    ->isChanged(), 'Paragraph::isChanged() found no changes after the entity has been saved.');
  $paragraph
    ->set('text', 'New text');
  $this
    ->assertTrue($paragraph
    ->isChanged(), 'Paragraph::isChanged() found changes after updating text field.');
}