Update to Drupal 8.2.2. For more information, see https://www.drupal.org/project/drupal/releases/8.2.2
This commit is contained in:
parent
23ffed3665
commit
507b45a0ed
378 changed files with 11434 additions and 5542 deletions
|
@ -156,9 +156,12 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
}
|
||||
}
|
||||
elseif ($current_bid) {
|
||||
// Only display this block when the user is browsing a book.
|
||||
$query = \Drupal::entityQuery('node');
|
||||
$nid = $query->condition('nid', $node->book['bid'], '=')->execute();
|
||||
// Only display this block when the user is browsing a book and do
|
||||
// not show unpublished books.
|
||||
$nid = \Drupal::entityQuery('node')
|
||||
->condition('nid', $node->book['bid'], '=')
|
||||
->condition('status', NODE_PUBLISHED)
|
||||
->execute();
|
||||
|
||||
// Only show the block if the user has view access for the top-level node.
|
||||
if ($nid) {
|
||||
|
|
|
@ -570,34 +570,6 @@ class BookTest extends WebTestBase {
|
|||
$this->assertEqual($child->id(), $second->book['bid'], '3rd-level child node is now second level when top-level node is deleted.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests re-ordering of books.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests outline of a book.
|
||||
*/
|
||||
|
@ -752,4 +724,29 @@ class BookTest extends WebTestBase {
|
|||
$this->assertEqual($book_node->book['bid'], $this->book->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the book navigation block when book is unpublished.
|
||||
*
|
||||
* There was a fatal error with "Show block only on book pages" block mode.
|
||||
*/
|
||||
public function testBookNavigationBlockOnUnpublishedBook() {
|
||||
// Create a new book.
|
||||
$this->createBook();
|
||||
|
||||
// Create administrator user.
|
||||
$administratorUser = $this->drupalCreateUser(['administer blocks', 'administer nodes', 'bypass node access']);
|
||||
$this->drupalLogin($administratorUser);
|
||||
|
||||
// Enable the block with "Show block only on book pages" mode.
|
||||
$this->drupalPlaceBlock('book_navigation', ['block_mode' => 'book pages']);
|
||||
|
||||
// Unpublish book node.
|
||||
$edit = [];
|
||||
$this->drupalPostForm('node/' . $this->book->id() . '/edit', $edit, t('Save and unpublish'));
|
||||
|
||||
// Test node page.
|
||||
$this->drupalGet('node/' . $this->book->id());
|
||||
$this->assertText($this->book->label(), 'Unpublished book with "Show block only on book pages" book navigation settings.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\book\FunctionalJavascript;
|
||||
|
||||
use Behat\Mink\Exception\ExpectationException;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Tests Book javascript functionality.
|
||||
*
|
||||
* @group book
|
||||
*/
|
||||
class BookJavascriptTest extends JavascriptTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['book'];
|
||||
|
||||
/**
|
||||
* Tests re-ordering of books.
|
||||
*/
|
||||
public function testBookOrdering() {
|
||||
$book = Node::create([
|
||||
'type' => 'book',
|
||||
'title' => 'Book',
|
||||
'book' => ['bid' => 'new'],
|
||||
]);
|
||||
$book->save();
|
||||
$page1 = Node::create([
|
||||
'type' => 'book',
|
||||
'title' => '1st page',
|
||||
'book' => ['bid' => $book->id(), 'pid' => $book->id(), 'weight' => 0],
|
||||
]);
|
||||
$page1->save();
|
||||
$page2 = Node::create([
|
||||
'type' => 'book',
|
||||
'title' => '2nd page',
|
||||
'book' => ['bid' => $book->id(), 'pid' => $book->id(), 'weight' => 1],
|
||||
]);
|
||||
$page2->save();
|
||||
|
||||
// Head to admin screen and attempt to re-order.
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer book outlines']));
|
||||
$this->drupalGet('admin/structure/book/' . $book->id());
|
||||
|
||||
$page = $this->getSession()->getPage();
|
||||
|
||||
$weight_select1 = $page->findField("table[book-admin-{$page1->id()}][weight]");
|
||||
$weight_select2 = $page->findField("table[book-admin-{$page2->id()}][weight]");
|
||||
|
||||
// Check that rows weight selects are hidden.
|
||||
$this->assertFalse($weight_select1->isVisible());
|
||||
$this->assertFalse($weight_select2->isVisible());
|
||||
|
||||
// Check that '2nd page' row is heavier than '1st page' row.
|
||||
$this->assertGreaterThan($weight_select1->getValue(), $weight_select2->getValue());
|
||||
|
||||
// Check that '1st page' precedes the '2nd page'.
|
||||
$this->assertOrderInPage(['1st page', '2nd page']);
|
||||
|
||||
// Check that the 'unsaved changes' text is not present in the message area.
|
||||
$this->assertSession()->pageTextNotContains('You have unsaved changes.');
|
||||
|
||||
// Drag and drop the '1st page' row over the '2nd page' row.
|
||||
// @todo: Test also the reverse, '2nd page' over '1st page', when
|
||||
// https://www.drupal.org/node/2769825 is fixed.
|
||||
// @see https://www.drupal.org/node/2769825
|
||||
$dragged = $this->xpath("//tr[@data-drupal-selector='edit-table-book-admin-{$page1->id()}']//a[@class='tabledrag-handle']")[0];
|
||||
$target = $this->xpath("//tr[@data-drupal-selector='edit-table-book-admin-{$page2->id()}']//a[@class='tabledrag-handle']")[0];
|
||||
$dragged->dragTo($target);
|
||||
|
||||
// Give javascript some time to manipulate the DOM.
|
||||
$this->getSession()->wait(1000, 'jQuery(".tabledrag-changed-warning").is(":visible")');
|
||||
|
||||
// Check that the 'unsaved changes' text appeared in the message area.
|
||||
$this->assertSession()->pageTextContains('You have unsaved changes.');
|
||||
|
||||
// Check that '2nd page' page precedes the '1st page'.
|
||||
$this->assertOrderInPage(['2nd page', '1st page']);
|
||||
|
||||
$this->submitForm([], 'Save book pages');
|
||||
$this->assertSession()->pageTextContains(new FormattableMarkup('Updated book @book.', ['@book' => $book->getTitle()]));
|
||||
|
||||
// Check that page reordering was done in the backend for drag-n-drop.
|
||||
$page1 = Node::load($page1->id());
|
||||
$page2 = Node::load($page2->id());
|
||||
$this->assertGreaterThan($page2->book['weight'], $page1->book['weight']);
|
||||
|
||||
// Check again that '2nd page' is on top after form submit in the UI.
|
||||
$this->assertOrderInPage(['2nd page', '1st page']);
|
||||
|
||||
// Toggle row weight selects as visible.
|
||||
$page->findButton('Show row weights')->click();
|
||||
|
||||
// Check that rows weight selects are visible.
|
||||
$this->assertTrue($weight_select1->isVisible());
|
||||
$this->assertTrue($weight_select2->isVisible());
|
||||
|
||||
// Check that '1st page' row became heavier than '2nd page' row.
|
||||
$this->assertGreaterThan($weight_select2->getValue(), $weight_select1->getValue());
|
||||
|
||||
// Reverse again using the weight fields. Use the current values so the test
|
||||
// doesn't rely on knowing the values in the select boxes.
|
||||
$value1 = $weight_select1->getValue();
|
||||
$value2 = $weight_select2->getValue();
|
||||
$weight_select1->setValue($value2);
|
||||
$weight_select2->setValue($value1);
|
||||
|
||||
// Toggle row weight selects back to hidden.
|
||||
$page->findButton('Hide row weights')->click();
|
||||
|
||||
// Check that rows weight selects are hidden again.
|
||||
$this->assertFalse($weight_select1->isVisible());
|
||||
$this->assertFalse($weight_select2->isVisible());
|
||||
|
||||
$this->submitForm([], 'Save book pages');
|
||||
$this->assertSession()->pageTextContains(new FormattableMarkup('Updated book @book.', ['@book' => $book->getTitle()]));
|
||||
|
||||
// Check that the '1st page' is first again.
|
||||
$this->assertOrderInPage(['1st page', '2nd page']);
|
||||
|
||||
// Check that page reordering was done in the backend for manual weight
|
||||
// field usage.
|
||||
$page1 = Node::load($page1->id());
|
||||
$page2 = Node::load($page2->id());
|
||||
$this->assertGreaterThan($page2->book['weight'], $page1->book['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that several pieces of markup are in a given order in the page.
|
||||
*
|
||||
* @param string[] $items
|
||||
* An ordered list of strings.
|
||||
*
|
||||
* @throws \Behat\Mink\Exception\ExpectationException
|
||||
* When any of the given string is not found.
|
||||
*
|
||||
* @todo Remove this once https://www.drupal.org/node/2817657 is committed.
|
||||
*/
|
||||
protected function assertOrderInPage(array $items) {
|
||||
$session = $this->getSession();
|
||||
$text = $session->getPage()->getHtml();
|
||||
$strings = [];
|
||||
foreach ($items as $item) {
|
||||
if (($pos = strpos($text, $item)) === FALSE) {
|
||||
throw new ExpectationException("Cannot find '$item' in the page", $session->getDriver());
|
||||
}
|
||||
$strings[$pos] = $item;
|
||||
}
|
||||
ksort($strings);
|
||||
$ordered = implode(', ', array_map(function ($item) {
|
||||
return "'$item'";
|
||||
}, $items));
|
||||
$this->assertSame($items, array_values($strings), "Found strings, ordered as: $ordered.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\book\Kernel\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* @covers \Drupal\book\Plugin\migrate\source\d6\Book
|
||||
* @group book
|
||||
*/
|
||||
class BookTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['book', 'migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['book'] = [
|
||||
[
|
||||
'mlid' => '1',
|
||||
'nid' => '4',
|
||||
'bid' => '4',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['menu_links'] = [
|
||||
[
|
||||
'menu_name' => 'book-toc-1',
|
||||
'mlid' => '1',
|
||||
'plid' => '0',
|
||||
'link_path' => 'node/4',
|
||||
'router_path' => 'node/%',
|
||||
'link_title' => 'Test top book title',
|
||||
'options' => 'a:0:{}',
|
||||
'module' => 'book',
|
||||
'hidden' => '0',
|
||||
'external' => '0',
|
||||
'has_children' => '1',
|
||||
'expanded' => '0',
|
||||
'weight' => '-10',
|
||||
'depth' => '1',
|
||||
'customized' => '0',
|
||||
'p1' => '1',
|
||||
'p2' => '0',
|
||||
'p3' => '0',
|
||||
'p4' => '0',
|
||||
'p5' => '0',
|
||||
'p6' => '0',
|
||||
'p7' => '0',
|
||||
'p8' => '0',
|
||||
'p9' => '0',
|
||||
'updated' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'nid' => '4',
|
||||
'bid' => '4',
|
||||
'mlid' => '1',
|
||||
'plid' => '0',
|
||||
'weight' => '-10',
|
||||
'p1' => '1',
|
||||
'p2' => '0',
|
||||
'p3' => '0',
|
||||
'p4' => '0',
|
||||
'p5' => '0',
|
||||
'p6' => '0',
|
||||
'p7' => '0',
|
||||
'p8' => '0',
|
||||
'p9' => '0',
|
||||
],
|
||||
];
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\book\Unit\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\book\Plugin\migrate\source\d6\Book;
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\book\Plugin\migrate\source\d6\Book
|
||||
* @group book
|
||||
*/
|
||||
class BookTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = Book::class;
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'd6_book',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'nid' => '4',
|
||||
'bid' => '4',
|
||||
'mlid' => '1',
|
||||
'plid' => '0',
|
||||
'weight' => '-10',
|
||||
'p1' => '1',
|
||||
'p2' => '0',
|
||||
'p3' => '0',
|
||||
'p4' => '0',
|
||||
'p5' => '0',
|
||||
'p6' => '0',
|
||||
'p7' => '0',
|
||||
'p8' => '0',
|
||||
'p9' => '0',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['book'] = array(
|
||||
array(
|
||||
'mlid' => '1',
|
||||
'nid' => '4',
|
||||
'bid' => '4',
|
||||
),
|
||||
);
|
||||
$this->databaseContents['menu_links'] = array(
|
||||
array(
|
||||
'menu_name' => 'book-toc-1',
|
||||
'mlid' => '1',
|
||||
'plid' => '0',
|
||||
'link_path' => 'node/4',
|
||||
'router_path' => 'node/%',
|
||||
'link_title' => 'Test top book title',
|
||||
'options' => 'a:0:{}',
|
||||
'module' => 'book',
|
||||
'hidden' => '0',
|
||||
'external' => '0',
|
||||
'has_children' => '1',
|
||||
'expanded' => '0',
|
||||
'weight' => '-10',
|
||||
'depth' => '1',
|
||||
'customized' => '0',
|
||||
'p1' => '1',
|
||||
'p2' => '0',
|
||||
'p3' => '0',
|
||||
'p4' => '0',
|
||||
'p5' => '0',
|
||||
'p6' => '0',
|
||||
'p7' => '0',
|
||||
'p8' => '0',
|
||||
'p9' => '0',
|
||||
'updated' => '0',
|
||||
),
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue