You are here

public function BookTest::testBookOrdering in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/book/src/Tests/BookTest.php \Drupal\book\Tests\BookTest::testBookOrdering()

Tests re-ordering of books.

File

core/modules/book/src/Tests/BookTest.php, line 503
Contains \Drupal\book\Tests\BookTest.

Class

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

Namespace

Drupal\book\Tests

Code

public function testBookOrdering() {

  // Create new book.
  $this
    ->createBook();
  $book = $this->book;
  $this
    ->drupalLogin($this->adminUser);
  $node1 = $this
    ->createBookNode($book
    ->id());
  $node2 = $this
    ->createBookNode($book
    ->id());
  $pid = $node1->book['nid'];

  // Head to admin screen and attempt to re-order.
  $this
    ->drupalGet('admin/structure/book/' . $book
    ->id());
  $edit = array(
    "table[book-admin-{$node1->id()}][weight]" => 1,
    "table[book-admin-{$node2->id()}][weight]" => 2,
    // Put node 2 under node 1.
    "table[book-admin-{$node2->id()}][pid]" => $pid,
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Save book pages'));

  // Verify weight was updated.
  $this
    ->assertFieldByName("table[book-admin-{$node1->id()}][weight]", 1);
  $this
    ->assertFieldByName("table[book-admin-{$node2->id()}][weight]", 2);
  $this
    ->assertFieldByName("table[book-admin-{$node2->id()}][pid]", $pid);
}