diff -u b/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php --- b/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -261,8 +261,8 @@ } if (!$node->book['bid'] || $nid === 'new' || $node->book['original_bid'] === 0) { // The node is not currently in the hierarchy. - $options = [0 => $this->t('- None -')] + $options; - } + $options = [0 => $this->t('- None -')] + $options; + } // Add a drop-down to select the destination book. $form['book']['bid'] = [ diff -u b/core/modules/book/tests/src/Unit/BookManagerTest.php b/core/modules/book/tests/src/Unit/BookManagerTest.php --- b/core/modules/book/tests/src/Unit/BookManagerTest.php +++ b/core/modules/book/tests/src/Unit/BookManagerTest.php @@ -56,7 +56,21 @@ protected $bookOutlineStorage; /** - * The mocked form state + * {@inheritdoc} + */ + protected function setUp() { + $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class); + $this->translation = $this->getStringTranslationStub(); + $this->configFactory = $this->getConfigFactoryStub([]); + $this->bookOutlineStorage = $this->createMock('Drupal\book\BookOutlineStorageInterface'); + $this->renderer = $this->createMock('\Drupal\Core\Render\RendererInterface'); + $this->bookManager = new BookManager($this->entityTypeManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer); + } + */ + protected $bookOutlineStorage; + + /** + * The mocked form state. * * @var \Drupal\Core\Form\FormState */ @@ -70,7 +84,7 @@ protected $node; /** - * The mocked User + * The mocked User. * * @var \Drupal\user\Entity\User */ @@ -79,7 +93,7 @@ /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class); $book_id = [ 'nid' => 'new', @@ -107,9 +121,9 @@ $config = [ 'book.settings' => [ 'allowed_types' => [ - 'page' - ] - ] + 'page', + ], + ], ]; $this->configFactory = $this->getConfigFactoryStub($config); $this->bookOutlineStorage = $this->createMock('Drupal\book\BookOutlineStorageInterface'); @@ -117,20 +131,6 @@ $container = new ContainerBuilder(); $container->set('config.factory', $this->configFactory); \Drupal::setContainer($container); - $this->bookManager = new BookManager($this->entityTypeManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer); - } - */ - protected $bookOutlineStorage; - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class); - $this->translation = $this->getStringTranslationStub(); - $this->configFactory = $this->getConfigFactoryStub([]); - $this->bookOutlineStorage = $this->createMock('Drupal\book\BookOutlineStorageInterface'); - $this->renderer = $this->createMock('\Drupal\Core\Render\RendererInterface'); $this->languageManager = $this->createMock('Drupal\Core\Language\LanguageManagerInterface'); $this->entityRepository = $this->createMock('Drupal\Core\Entity\EntityRepositoryInterface'); $this->bookManager = new BookManager($this->entityTypeManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer, $this->languageManager, $this->entityRepository); @@ -194,21 +194,21 @@ $this->node->expects($this->any()) ->method('getType') ->willReturn('page'); - $addform = $this->bookManager->addFormElements($form, $this->form_state, $this->node, $this->account); - $this->assertArrayHasKey('book', $addform); + $add_form = $this->bookManager->addFormElements($form, $this->form_state, $this->node, $this->account); + $this->assertArrayHasKey('book', $form); } /** * Testing the Book Outline form element in node add article form. - * When the Book setting is not enabled for the Content Type 'Article' + * When the Book setting is not enabled for the Content Type 'Article'. */ public function testAddFormElementsNodeAddWithoutBook() { $form = []; $this->node->expects($this->any()) ->method('getType') - ->willReturn('artilce'); - $addform = $this->bookManager->addFormElements($form, $this->form_state, $this->node, $this->account); - $this->assertArrayNotHasKey('book', $addform); + ->willReturn('article'); + $add_form = $this->bookManager->addFormElements($form, $this->form_state, $this->node, $this->account); + $this->assertArrayNotHasKey('book', $form); } }