You are here

public function EntityAnalyserTest::testEntityPreviewWithUnsavedNode in Real-time SEO for Drupal 8.2

Tests that the entity preview works with unsaved nodes.

File

tests/src/Kernel/EntityAnalyserTest.php, line 93

Class

EntityAnalyserTest
Tests the entity analyzer.

Namespace

Drupal\Tests\yoast_seo\Kernel

Code

public function testEntityPreviewWithUnsavedNode() {

  // Can't use createNode because it saves the node, which we don't want.
  $unsaved_node = Node::create([
    'type' => 'article',
    'title' => $this
      ->randomMachineName(8),
    'body' => [
      [
        'value' => $this
          ->randomMachineName(32),
        'format' => filter_default_format(),
      ],
    ],
    'uid' => 0,
  ]);
  $preview_data = $this->entityAnalyzer
    ->createEntityPreview($unsaved_node);
  $this
    ->assertNotEmpty($preview_data['title']);
  $this
    ->assertNotEmpty($preview_data['text']);
  $this
    ->assertEmpty($preview_data['url']);
}