function BookMultilingualTest::testMultilingualBookManager
Same name in other branches
- 9 core/modules/book/tests/src/Kernel/BookMultilingualTest.php \Drupal\Tests\book\Kernel\BookMultilingualTest::testMultilingualBookManager()
- 10 core/modules/book/tests/src/Kernel/BookMultilingualTest.php \Drupal\Tests\book\Kernel\BookMultilingualTest::testMultilingualBookManager()
Tests various book manager methods return correct translations.
@dataProvider langcodesProvider
File
-
core/
modules/ book/ tests/ src/ Kernel/ BookMultilingualTest.php, line 172
Class
- BookMultilingualTest
- Tests multilingual books.
Namespace
Drupal\Tests\book\KernelCode
public function testMultilingualBookManager(string $langcode) {
$this->setCurrentLanguage($langcode);
/** @var \Drupal\book\BookManagerInterface $bm */
$bm = $this->container
->get('book.manager');
$books = $bm->getAllBooks();
$this->assertNotEmpty($books);
foreach ($books as $book) {
$bid = (int) $book['bid'];
$build = $bm->bookTreeOutput($bm->bookTreeAllData($bid));
$items = $build['#items'];
$this->assertBookItemIsCorrectlyTranslated($items[$bid], $langcode);
$this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 1], $langcode);
$this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 1]['below'][$bid + 3], $langcode);
$this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 1]['below'][$bid + 4], $langcode);
$this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 2], $langcode);
$this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 2]['below'][$bid + 5], $langcode);
$this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 2]['below'][$bid + 6], $langcode);
$toc = $bm->getTableOfContents($bid, 4);
// Root entry does not have an indent.
$this->assertToCEntryIsCorrectlyTranslated($toc, $langcode, $bid, '');
// The direct children of the root have one indent.
$this->assertToCEntryIsCorrectlyTranslated($toc, $langcode, $bid + 1, '--');
$this->assertToCEntryIsCorrectlyTranslated($toc, $langcode, $bid + 2, '--');
// Their children have two indents.
$this->assertToCEntryIsCorrectlyTranslated($toc, $langcode, $bid + 3, '----');
$this->assertToCEntryIsCorrectlyTranslated($toc, $langcode, $bid + 4, '----');
$this->assertToCEntryIsCorrectlyTranslated($toc, $langcode, $bid + 5, '----');
$this->assertToCEntryIsCorrectlyTranslated($toc, $langcode, $bid + 6, '----');
// $bid might be a string.
$this->assertSame([
$bid + 0,
$bid + 1,
$bid + 3,
$bid + 4,
$bid + 2,
$bid + 5,
$bid + 6,
], array_keys($toc));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.