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