Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
122
core/modules/book/tests/src/Unit/BookManagerTest.php
Normal file
122
core/modules/book/tests/src/Unit/BookManagerTest.php
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\book\Unit\BookManagerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\book\Unit;
|
||||
|
||||
use Drupal\book\BookManager;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\book\BookManager
|
||||
* @group book
|
||||
*/
|
||||
class BookManagerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The mocked entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManager|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The mocked config factory.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* The mocked translation manager.
|
||||
*
|
||||
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $translation;
|
||||
|
||||
/**
|
||||
* The mocked renderer.
|
||||
*
|
||||
* @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $renderer;
|
||||
|
||||
/**
|
||||
* The tested book manager.
|
||||
*
|
||||
* @var \Drupal\book\BookManager
|
||||
*/
|
||||
protected $bookManager;
|
||||
|
||||
/**
|
||||
* Book outline storage.
|
||||
*
|
||||
* @var \Drupal\book\BookOutlineStorageInterface
|
||||
*/
|
||||
protected $bookOutlineStorage;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->translation = $this->getStringTranslationStub();
|
||||
$this->configFactory = $this->getConfigFactoryStub(array());
|
||||
$this->bookOutlineStorage = $this->getMock('Drupal\book\BookOutlineStorageInterface');
|
||||
$this->renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
|
||||
$this->bookManager = new BookManager($this->entityManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getBookParents() method.
|
||||
*
|
||||
* @dataProvider providerTestGetBookParents
|
||||
*/
|
||||
public function testGetBookParents($book, $parent, $expected) {
|
||||
$this->assertEquals($expected, $this->bookManager->getBookParents($book, $parent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for testGetBookParents.
|
||||
*
|
||||
* @return array
|
||||
* The test data.
|
||||
*/
|
||||
public function providerTestGetBookParents() {
|
||||
$empty = array(
|
||||
'p1' => 0,
|
||||
'p2' => 0,
|
||||
'p3' => 0,
|
||||
'p4' => 0,
|
||||
'p5' => 0,
|
||||
'p6' => 0,
|
||||
'p7' => 0,
|
||||
'p8' => 0,
|
||||
'p9' => 0,
|
||||
);
|
||||
return array(
|
||||
// Provides a book without an existing parent.
|
||||
array(
|
||||
array('pid' => 0, 'nid' => 12),
|
||||
array(),
|
||||
array('depth' => 1, 'p1' => 12) + $empty,
|
||||
),
|
||||
// Provides a book with an existing parent.
|
||||
array(
|
||||
array('pid' => 11, 'nid' => 12),
|
||||
array('nid' => 11, 'depth' => 1, 'p1' => 11,),
|
||||
array('depth' => 2, 'p1' => 11, 'p2' => 12) + $empty,
|
||||
),
|
||||
// Provides a book with two existing parents.
|
||||
array(
|
||||
array('pid' => 11, 'nid' => 12),
|
||||
array('nid' => 11, 'depth' => 2, 'p1' => 10, 'p2' => 11),
|
||||
array('depth' => 3, 'p1' => 10, 'p2' => 11, 'p3' => 12) + $empty,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
100
core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
Normal file
100
core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\book\Unit\BookUninstallValidatorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\book\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\book\BookUninstallValidator
|
||||
* @group book
|
||||
*/
|
||||
class BookUninstallValidatorTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\book\BookUninstallValidator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $bookUninstallValidator;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->bookUninstallValidator = $this->getMockBuilder('Drupal\book\BookUninstallValidator')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['hasBookOutlines', 'hasBookNodes'])
|
||||
->getMock();
|
||||
$this->bookUninstallValidator->setStringTranslation($this->getStringTranslationStub());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateNotBook() {
|
||||
$this->bookUninstallValidator->expects($this->never())
|
||||
->method('hasBookOutlines');
|
||||
$this->bookUninstallValidator->expects($this->never())
|
||||
->method('hasBookNodes');
|
||||
|
||||
$module = 'not_book';
|
||||
$expected = [];
|
||||
$reasons = $this->bookUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateEntityQueryWithoutResults() {
|
||||
$this->bookUninstallValidator->expects($this->once())
|
||||
->method('hasBookOutlines')
|
||||
->willReturn(FALSE);
|
||||
$this->bookUninstallValidator->expects($this->once())
|
||||
->method('hasBookNodes')
|
||||
->willReturn(FALSE);
|
||||
|
||||
$module = 'book';
|
||||
$expected = [];
|
||||
$reasons = $this->bookUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateEntityQueryWithResults() {
|
||||
$this->bookUninstallValidator->expects($this->once())
|
||||
->method('hasBookOutlines')
|
||||
->willReturn(FALSE);
|
||||
$this->bookUninstallValidator->expects($this->once())
|
||||
->method('hasBookNodes')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$module = 'book';
|
||||
$expected = ['To uninstall Book, delete all content that has the Book content type'];
|
||||
$reasons = $this->bookUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateOutlineStorage() {
|
||||
$this->bookUninstallValidator->expects($this->once())
|
||||
->method('hasBookOutlines')
|
||||
->willReturn(TRUE);
|
||||
$this->bookUninstallValidator->expects($this->never())
|
||||
->method('hasBookNodes');
|
||||
|
||||
$module = 'book';
|
||||
$expected = ['To uninstall Book, delete all content that is part of a book'];
|
||||
$reasons = $this->bookUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
}
|
70
core/modules/book/tests/src/Unit/Menu/BookLocalTasksTest.php
Normal file
70
core/modules/book/tests/src/Unit/Menu/BookLocalTasksTest.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\book\Unit\Menu\BookLocalTasksTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\book\Unit\Menu;
|
||||
|
||||
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
|
||||
|
||||
/**
|
||||
* Tests existence of book local tasks.
|
||||
*
|
||||
* @group book
|
||||
*/
|
||||
class BookLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->directoryList = array(
|
||||
'book' => 'core/modules/book',
|
||||
'node' => 'core/modules/node',
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests local task existence.
|
||||
*
|
||||
* @dataProvider getBookAdminRoutes
|
||||
*/
|
||||
public function testBookAdminLocalTasks($route) {
|
||||
|
||||
$this->assertLocalTasks($route, array(
|
||||
0 => array('book.admin', 'book.settings'),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function getBookAdminRoutes() {
|
||||
return array(
|
||||
array('book.admin'),
|
||||
array('book.settings'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests local task existence.
|
||||
*
|
||||
* @dataProvider getBookNodeRoutes
|
||||
*/
|
||||
public function testBookNodeLocalTasks($route) {
|
||||
$this->assertLocalTasks($route, array(
|
||||
0 => array('entity.node.book_outline_form', 'entity.node.canonical', 'entity.node.edit_form', 'entity.node.delete_form', 'entity.node.version_history',),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function getBookNodeRoutes() {
|
||||
return array(
|
||||
array('entity.node.canonical'),
|
||||
array('entity.node.book_outline_form'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue