function BookTest::testSaveBookLink

Same name in other branches
  1. 8.9.x core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testSaveBookLink()
  2. 10 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testSaveBookLink()
  3. 11.x core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testSaveBookLink()

Tests that saveBookLink() returns something.

File

core/modules/book/tests/src/Functional/BookTest.php, line 542

Class

BookTest
Create a book, add pages, and test book interface.

Namespace

Drupal\Tests\book\Functional

Code

public function testSaveBookLink() {
    $book_manager = \Drupal::service('book.manager');
    // Mock a link for a new book.
    $link = [
        'nid' => 1,
        'has_children' => 0,
        'original_bid' => 0,
        'pid' => 0,
        'weight' => 0,
        'bid' => 0,
    ];
    $new = TRUE;
    // Save the link.
    $return = $book_manager->saveBookLink($link, $new);
    // Add the link defaults to $link so we have something to compare to the return from saveBookLink().
    $link = $book_manager->getLinkDefaults($link['nid']);
    // Test the return from saveBookLink.
    $this->assertEquals($return, $link);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.