Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

public function ParagraphsIsChangedTest::testIsChanged

Tests the functionality of the isChanged() function.

File

paragraphs/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.');
}