public function BookTest::testBookOrdering

Tests re-ordering of books.

File

drupal/core/modules/book/lib/Drupal/book/Tests/BookTest.php, line 489
Definition of Drupal\book\Tests\BookTest.

Class

BookTest
Tests the functionality of the Book module.

Namespace

Drupal\book\Tests

Code

public function testBookOrdering() {

  // Create new book.
  $nodes = $this
    ->createBook();
  $book = $this->book;
  $this
    ->drupalLogin($this->admin_user);
  $node1 = $this
    ->createBookNode($book->nid);
  $node2 = $this
    ->createBookNode($book->nid);
  $plid = $node1->book['mlid'];

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

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