Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\book\Unit;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\book\BookManager;
|
Chris@18
|
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
|
Chris@0
|
7 use Drupal\Tests\UnitTestCase;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * @coversDefaultClass \Drupal\book\BookManager
|
Chris@0
|
11 * @group book
|
Chris@0
|
12 */
|
Chris@0
|
13 class BookManagerTest extends UnitTestCase {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * The mocked entity manager.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var \Drupal\Core\Entity\EntityManager|\PHPUnit_Framework_MockObject_MockObject
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $entityManager;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * The mocked config factory.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
|
Chris@0
|
26 */
|
Chris@0
|
27 protected $configFactory;
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * The mocked translation manager.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
|
Chris@0
|
33 */
|
Chris@0
|
34 protected $translation;
|
Chris@0
|
35
|
Chris@0
|
36 /**
|
Chris@0
|
37 * The mocked renderer.
|
Chris@0
|
38 *
|
Chris@0
|
39 * @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject
|
Chris@0
|
40 */
|
Chris@0
|
41 protected $renderer;
|
Chris@0
|
42
|
Chris@0
|
43 /**
|
Chris@0
|
44 * The tested book manager.
|
Chris@0
|
45 *
|
Chris@0
|
46 * @var \Drupal\book\BookManager
|
Chris@0
|
47 */
|
Chris@0
|
48 protected $bookManager;
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * Book outline storage.
|
Chris@0
|
52 *
|
Chris@0
|
53 * @var \Drupal\book\BookOutlineStorageInterface
|
Chris@0
|
54 */
|
Chris@0
|
55 protected $bookOutlineStorage;
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * {@inheritdoc}
|
Chris@0
|
59 */
|
Chris@0
|
60 protected function setUp() {
|
Chris@18
|
61 $this->entityManager = $this->createMock(EntityTypeManagerInterface::class);
|
Chris@0
|
62 $this->translation = $this->getStringTranslationStub();
|
Chris@0
|
63 $this->configFactory = $this->getConfigFactoryStub([]);
|
Chris@0
|
64 $this->bookOutlineStorage = $this->getMock('Drupal\book\BookOutlineStorageInterface');
|
Chris@0
|
65 $this->renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
|
Chris@0
|
66 $this->bookManager = new BookManager($this->entityManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer);
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * Tests the getBookParents() method.
|
Chris@0
|
71 *
|
Chris@0
|
72 * @dataProvider providerTestGetBookParents
|
Chris@0
|
73 */
|
Chris@0
|
74 public function testGetBookParents($book, $parent, $expected) {
|
Chris@0
|
75 $this->assertEquals($expected, $this->bookManager->getBookParents($book, $parent));
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 /**
|
Chris@0
|
79 * Provides test data for testGetBookParents.
|
Chris@0
|
80 *
|
Chris@0
|
81 * @return array
|
Chris@0
|
82 * The test data.
|
Chris@0
|
83 */
|
Chris@0
|
84 public function providerTestGetBookParents() {
|
Chris@0
|
85 $empty = [
|
Chris@0
|
86 'p1' => 0,
|
Chris@0
|
87 'p2' => 0,
|
Chris@0
|
88 'p3' => 0,
|
Chris@0
|
89 'p4' => 0,
|
Chris@0
|
90 'p5' => 0,
|
Chris@0
|
91 'p6' => 0,
|
Chris@0
|
92 'p7' => 0,
|
Chris@0
|
93 'p8' => 0,
|
Chris@0
|
94 'p9' => 0,
|
Chris@0
|
95 ];
|
Chris@0
|
96 return [
|
Chris@0
|
97 // Provides a book without an existing parent.
|
Chris@0
|
98 [
|
Chris@0
|
99 ['pid' => 0, 'nid' => 12],
|
Chris@0
|
100 [],
|
Chris@0
|
101 ['depth' => 1, 'p1' => 12] + $empty,
|
Chris@0
|
102 ],
|
Chris@0
|
103 // Provides a book with an existing parent.
|
Chris@0
|
104 [
|
Chris@0
|
105 ['pid' => 11, 'nid' => 12],
|
Chris@0
|
106 ['nid' => 11, 'depth' => 1, 'p1' => 11],
|
Chris@0
|
107 ['depth' => 2, 'p1' => 11, 'p2' => 12] + $empty,
|
Chris@0
|
108 ],
|
Chris@0
|
109 // Provides a book with two existing parents.
|
Chris@0
|
110 [
|
Chris@0
|
111 ['pid' => 11, 'nid' => 12],
|
Chris@0
|
112 ['nid' => 11, 'depth' => 2, 'p1' => 10, 'p2' => 11],
|
Chris@0
|
113 ['depth' => 3, 'p1' => 10, 'p2' => 11, 'p3' => 12] + $empty,
|
Chris@0
|
114 ],
|
Chris@0
|
115 ];
|
Chris@0
|
116 }
|
Chris@0
|
117
|
Chris@0
|
118 }
|