3 namespace Drupal\Tests\book\Unit;
5 use Drupal\book\BookManager;
6 use Drupal\Tests\UnitTestCase;
9 * @coversDefaultClass \Drupal\book\BookManager
12 class BookManagerTest extends UnitTestCase {
15 * The mocked entity manager.
17 * @var \Drupal\Core\Entity\EntityManager|\PHPUnit_Framework_MockObject_MockObject
19 protected $entityManager;
22 * The mocked config factory.
24 * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
26 protected $configFactory;
29 * The mocked translation manager.
31 * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
33 protected $translation;
36 * The mocked renderer.
38 * @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject
43 * The tested book manager.
45 * @var \Drupal\book\BookManager
47 protected $bookManager;
50 * Book outline storage.
52 * @var \Drupal\book\BookOutlineStorageInterface
54 protected $bookOutlineStorage;
59 protected function setUp() {
60 $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
61 $this->translation = $this->getStringTranslationStub();
62 $this->configFactory = $this->getConfigFactoryStub([]);
63 $this->bookOutlineStorage = $this->getMock('Drupal\book\BookOutlineStorageInterface');
64 $this->renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
65 $this->bookManager = new BookManager($this->entityManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer);
69 * Tests the getBookParents() method.
71 * @dataProvider providerTestGetBookParents
73 public function testGetBookParents($book, $parent, $expected) {
74 $this->assertEquals($expected, $this->bookManager->getBookParents($book, $parent));
78 * Provides test data for testGetBookParents.
83 public function providerTestGetBookParents() {
96 // Provides a book without an existing parent.
98 ['pid' => 0, 'nid' => 12],
100 ['depth' => 1, 'p1' => 12] + $empty,
102 // Provides a book with an existing parent.
104 ['pid' => 11, 'nid' => 12],
105 ['nid' => 11, 'depth' => 1, 'p1' => 11],
106 ['depth' => 2, 'p1' => 11, 'p2' => 12] + $empty,
108 // Provides a book with two existing parents.
110 ['pid' => 11, 'nid' => 12],
111 ['nid' => 11, 'depth' => 2, 'p1' => 10, 'p2' => 11],
112 ['depth' => 3, 'p1' => 10, 'p2' => 11, 'p3' => 12] + $empty,