class OnlyOneAdminToolbarTest in Allow a content type only once (Only One) 8
Tests the Language class methods.
@group onlyone @group onlyone_admin_toolbar @coversDefaultClass \Drupal\onlyone_admin_toolbar\OnlyOneAdminToolbar
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\onlyone_admin_toolbar\Unit\OnlyOneAdminToolbarTest
Expanded class hierarchy of OnlyOneAdminToolbarTest
File
- modules/
onlyone_admin_toolbar/ tests/ src/ Unit/ OnlyOneAdminToolbarTest.php, line 15
Namespace
Drupal\Tests\onlyone_admin_toolbar\UnitView source
class OnlyOneAdminToolbarTest extends UnitTestCase {
/**
* A config factory instance.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configFactory;
/**
* A route builder instance.
*
* @var \Drupal\Core\Routing\RouteBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $routeBuilder;
/**
* The OnlyOneAdminToolbar Object.
*
* @var \Drupal\onlyone_admin_toolbar\OnlyOneAdminToolbar
*/
protected $onlyOneAdminToolbar;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Config factory mock.
$this->configFactory = $this
->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
// Route builder mock.
$this->routeBuilder = $this
->createMock('Drupal\\Core\\Routing\\RouteBuilderInterface');
// Creating the object.
$this->onlyOneAdminToolbar = new OnlyOneAdminToolbar($this->configFactory, $this->routeBuilder);
}
/**
* Tests the OnlyOneAdminToolbar::rebuildMenu() method.
*
* @param string $content_type
* Content type machine name.
* @param array $content_types_list
* Array of content types machine names.
*
* @covers ::rebuildMenu
* @dataProvider providerRebuildMenu
*/
public function testRebuildMenu($content_type, array $content_types_list) {
// ImmutableConfig mock.
$config = $this
->createMock('Drupal\\Core\\Config\\ImmutableConfig');
// ImmutableConfig::get mock.
$config
->expects($this
->any())
->method('get')
->with('onlyone_node_types')
->willReturn($content_types_list);
// Mocking get method.
$this->configFactory
->expects($this
->any())
->method('get')
->with('onlyone.settings')
->willReturn($config);
// Mocking rebuild method.
$this->routeBuilder
->expects($this
->any())
->method('rebuild')
->willReturn(TRUE);
// Testing the function.
$this
->assertNull($this->onlyOneAdminToolbar
->rebuildMenu($content_type));
}
/**
* Data provider for testRebuildMenu().
*
* @return array
* An array of arrays, each containing:
* - 'content_type' - Content type machine name.
* - 'content_types_list' - Array of content types machine names.
*
* @see testRebuildMenu()
*/
public function providerRebuildMenu() {
$content_types_list = [
'page',
'forum',
'article',
];
$tests['configured content type'] = [
'page',
$content_types_list,
];
$tests['configured content type'] = [
'article',
$content_types_list,
];
$tests['not configured content type'] = [
'blog',
$content_types_list,
];
$tests['not configured content type'] = [
'log',
$content_types_list,
];
return $tests;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OnlyOneAdminToolbarTest:: |
protected | property | A config factory instance. | |
OnlyOneAdminToolbarTest:: |
protected | property | The OnlyOneAdminToolbar Object. | |
OnlyOneAdminToolbarTest:: |
protected | property | A route builder instance. | |
OnlyOneAdminToolbarTest:: |
public | function | Data provider for testRebuildMenu(). | |
OnlyOneAdminToolbarTest:: |
public | function |
Overrides UnitTestCase:: |
|
OnlyOneAdminToolbarTest:: |
public | function | Tests the OnlyOneAdminToolbar::rebuildMenu() method. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |