class BlockFormTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/block/tests/src/Unit/BlockFormTest.php \Drupal\Tests\block\Unit\BlockFormTest
@coversDefaultClass \Drupal\block\BlockForm @group block
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\block\Unit\BlockFormTest
Expanded class hierarchy of BlockFormTest
File
- core/
modules/ block/ tests/ src/ Unit/ BlockFormTest.php, line 17 - Contains \Drupal\Tests\block\Unit\BlockFormTest.
Namespace
Drupal\Tests\block\UnitView source
class BlockFormTest extends UnitTestCase {
/**
* The condition plugin manager.
*
* @var \Drupal\Core\Executable\ExecutableManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $conditionManager;
/**
* The block storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storage;
/**
* The language manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $language;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $themeHandler;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* The mocked context repository.
*
* @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $contextRepository;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->conditionManager = $this
->getMock('Drupal\\Core\\Executable\\ExecutableManagerInterface');
$this->language = $this
->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$this->contextRepository = $this
->getMock('Drupal\\Core\\Plugin\\Context\\ContextRepositoryInterface');
$this->entityManager = $this
->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->storage = $this
->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
$this->themeHandler = $this
->getMock('Drupal\\Core\\Extension\\ThemeHandlerInterface');
$this->entityManager
->expects($this
->any())
->method('getStorage')
->will($this
->returnValue($this->storage));
}
/**
* Tests the unique machine name generator.
*
* @see \Drupal\block\BlockForm::getUniqueMachineName()
*/
public function testGetUniqueMachineName() {
$blocks = array();
$blocks['test'] = $this
->getBlockMockWithMachineName('test');
$blocks['other_test'] = $this
->getBlockMockWithMachineName('other_test');
$blocks['other_test_1'] = $this
->getBlockMockWithMachineName('other_test');
$blocks['other_test_2'] = $this
->getBlockMockWithMachineName('other_test');
$query = $this
->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
$query
->expects($this
->exactly(5))
->method('condition')
->will($this
->returnValue($query));
$query
->expects($this
->exactly(5))
->method('execute')
->will($this
->returnValue(array(
'test',
'other_test',
'other_test_1',
'other_test_2',
)));
$this->storage
->expects($this
->exactly(5))
->method('getQuery')
->will($this
->returnValue($query));
$block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->contextRepository, $this->language, $this->themeHandler);
// Ensure that the block with just one other instance gets the next available
// name suggestion.
$this
->assertEquals('test_2', $block_form_controller
->getUniqueMachineName($blocks['test']));
// Ensure that the block with already three instances (_0, _1, _2) gets the
// 4th available name.
$this
->assertEquals('other_test_3', $block_form_controller
->getUniqueMachineName($blocks['other_test']));
$this
->assertEquals('other_test_3', $block_form_controller
->getUniqueMachineName($blocks['other_test_1']));
$this
->assertEquals('other_test_3', $block_form_controller
->getUniqueMachineName($blocks['other_test_2']));
// Ensure that a block without an instance yet gets the suggestion as
// unique machine name.
$last_block = $this
->getBlockMockWithMachineName('last_test');
$this
->assertEquals('last_test', $block_form_controller
->getUniqueMachineName($last_block));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockFormTest:: |
protected | property | The condition plugin manager. | |
BlockFormTest:: |
protected | property | The mocked context repository. | |
BlockFormTest:: |
protected | property | The entity manager. | |
BlockFormTest:: |
protected | property | The language manager service. | |
BlockFormTest:: |
protected | property | The block storage. | |
BlockFormTest:: |
protected | property | The theme handler. | |
BlockFormTest:: |
protected | function |
Overrides UnitTestCase:: |
|
BlockFormTest:: |
public | function | Tests the unique machine name generator. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. |