annotate core/modules/book/tests/src/Unit/BookManagerTest.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents 4c8ae668cc8c
children af1871eacc83
rev   line source
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@0 6 use Drupal\Tests\UnitTestCase;
Chris@0 7
Chris@0 8 /**
Chris@0 9 * @coversDefaultClass \Drupal\book\BookManager
Chris@0 10 * @group book
Chris@0 11 */
Chris@0 12 class BookManagerTest extends UnitTestCase {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * The mocked entity manager.
Chris@0 16 *
Chris@0 17 * @var \Drupal\Core\Entity\EntityManager|\PHPUnit_Framework_MockObject_MockObject
Chris@0 18 */
Chris@0 19 protected $entityManager;
Chris@0 20
Chris@0 21 /**
Chris@0 22 * The mocked config factory.
Chris@0 23 *
Chris@0 24 * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
Chris@0 25 */
Chris@0 26 protected $configFactory;
Chris@0 27
Chris@0 28 /**
Chris@0 29 * The mocked translation manager.
Chris@0 30 *
Chris@0 31 * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
Chris@0 32 */
Chris@0 33 protected $translation;
Chris@0 34
Chris@0 35 /**
Chris@0 36 * The mocked renderer.
Chris@0 37 *
Chris@0 38 * @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject
Chris@0 39 */
Chris@0 40 protected $renderer;
Chris@0 41
Chris@0 42 /**
Chris@0 43 * The tested book manager.
Chris@0 44 *
Chris@0 45 * @var \Drupal\book\BookManager
Chris@0 46 */
Chris@0 47 protected $bookManager;
Chris@0 48
Chris@0 49 /**
Chris@0 50 * Book outline storage.
Chris@0 51 *
Chris@0 52 * @var \Drupal\book\BookOutlineStorageInterface
Chris@0 53 */
Chris@0 54 protected $bookOutlineStorage;
Chris@0 55
Chris@0 56 /**
Chris@0 57 * {@inheritdoc}
Chris@0 58 */
Chris@0 59 protected function setUp() {
Chris@0 60 $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
Chris@0 61 $this->translation = $this->getStringTranslationStub();
Chris@0 62 $this->configFactory = $this->getConfigFactoryStub([]);
Chris@0 63 $this->bookOutlineStorage = $this->getMock('Drupal\book\BookOutlineStorageInterface');
Chris@0 64 $this->renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
Chris@0 65 $this->bookManager = new BookManager($this->entityManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer);
Chris@0 66 }
Chris@0 67
Chris@0 68 /**
Chris@0 69 * Tests the getBookParents() method.
Chris@0 70 *
Chris@0 71 * @dataProvider providerTestGetBookParents
Chris@0 72 */
Chris@0 73 public function testGetBookParents($book, $parent, $expected) {
Chris@0 74 $this->assertEquals($expected, $this->bookManager->getBookParents($book, $parent));
Chris@0 75 }
Chris@0 76
Chris@0 77 /**
Chris@0 78 * Provides test data for testGetBookParents.
Chris@0 79 *
Chris@0 80 * @return array
Chris@0 81 * The test data.
Chris@0 82 */
Chris@0 83 public function providerTestGetBookParents() {
Chris@0 84 $empty = [
Chris@0 85 'p1' => 0,
Chris@0 86 'p2' => 0,
Chris@0 87 'p3' => 0,
Chris@0 88 'p4' => 0,
Chris@0 89 'p5' => 0,
Chris@0 90 'p6' => 0,
Chris@0 91 'p7' => 0,
Chris@0 92 'p8' => 0,
Chris@0 93 'p9' => 0,
Chris@0 94 ];
Chris@0 95 return [
Chris@0 96 // Provides a book without an existing parent.
Chris@0 97 [
Chris@0 98 ['pid' => 0, 'nid' => 12],
Chris@0 99 [],
Chris@0 100 ['depth' => 1, 'p1' => 12] + $empty,
Chris@0 101 ],
Chris@0 102 // Provides a book with an existing parent.
Chris@0 103 [
Chris@0 104 ['pid' => 11, 'nid' => 12],
Chris@0 105 ['nid' => 11, 'depth' => 1, 'p1' => 11],
Chris@0 106 ['depth' => 2, 'p1' => 11, 'p2' => 12] + $empty,
Chris@0 107 ],
Chris@0 108 // Provides a book with two existing parents.
Chris@0 109 [
Chris@0 110 ['pid' => 11, 'nid' => 12],
Chris@0 111 ['nid' => 11, 'depth' => 2, 'p1' => 10, 'p2' => 11],
Chris@0 112 ['depth' => 3, 'p1' => 10, 'p2' => 11, 'p3' => 12] + $empty,
Chris@0 113 ],
Chris@0 114 ];
Chris@0 115 }
Chris@0 116
Chris@0 117 }