Chris@0: entityManager = $this->createMock(EntityTypeManagerInterface::class); Chris@0: $this->translation = $this->getStringTranslationStub(); Chris@0: $this->configFactory = $this->getConfigFactoryStub([]); Chris@0: $this->bookOutlineStorage = $this->getMock('Drupal\book\BookOutlineStorageInterface'); Chris@0: $this->renderer = $this->getMock('\Drupal\Core\Render\RendererInterface'); Chris@0: $this->bookManager = new BookManager($this->entityManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the getBookParents() method. Chris@0: * Chris@0: * @dataProvider providerTestGetBookParents Chris@0: */ Chris@0: public function testGetBookParents($book, $parent, $expected) { Chris@0: $this->assertEquals($expected, $this->bookManager->getBookParents($book, $parent)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provides test data for testGetBookParents. Chris@0: * Chris@0: * @return array Chris@0: * The test data. Chris@0: */ Chris@0: public function providerTestGetBookParents() { Chris@0: $empty = [ Chris@0: 'p1' => 0, Chris@0: 'p2' => 0, Chris@0: 'p3' => 0, Chris@0: 'p4' => 0, Chris@0: 'p5' => 0, Chris@0: 'p6' => 0, Chris@0: 'p7' => 0, Chris@0: 'p8' => 0, Chris@0: 'p9' => 0, Chris@0: ]; Chris@0: return [ Chris@0: // Provides a book without an existing parent. Chris@0: [ Chris@0: ['pid' => 0, 'nid' => 12], Chris@0: [], Chris@0: ['depth' => 1, 'p1' => 12] + $empty, Chris@0: ], Chris@0: // Provides a book with an existing parent. Chris@0: [ Chris@0: ['pid' => 11, 'nid' => 12], Chris@0: ['nid' => 11, 'depth' => 1, 'p1' => 11], Chris@0: ['depth' => 2, 'p1' => 11, 'p2' => 12] + $empty, Chris@0: ], Chris@0: // Provides a book with two existing parents. Chris@0: [ Chris@0: ['pid' => 11, 'nid' => 12], Chris@0: ['nid' => 11, 'depth' => 2, 'p1' => 10, 'p2' => 11], Chris@0: ['depth' => 3, 'p1' => 10, 'p2' => 11, 'p3' => 12] + $empty, Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: Chris@0: }