Select Git revision
Forked from
project / drupal
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
BlockContentCreationTest.php 8.47 KiB
<?php
/**
* @file
* Contains \Drupal\block_content\Tests\BlockContentCreationTest.
*/
namespace Drupal\block_content\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Database;
use Drupal\block_content\Entity\BlockContent;
/**
* Create a block and test saving it.
*
* @group block_content
*/
class BlockContentCreationTest extends BlockContentTestBase {
/**
* Modules to enable.
*
* Enable dummy module that implements hook_block_insert() for exceptions.
*
* @var array
*/
public static $modules = array('block_content_test', 'dblog', 'field_ui');
/**
* Sets the test up.
*/
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->adminUser);
}
/**
* Creates a "Basic page" block and verifies its consistency in the database.
*/
public function testBlockContentCreation() {
// Add a new view mode and verify if it is selected as expected.
$this->drupalLogin($this->drupalCreateUser(array('administer display modes')));
$this->drupalGet('admin/structure/display-modes/view/add/block_content');
$edit = array(
'id' => 'test_view_mode',
'label' => 'Test View Mode',
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Saved the %label view mode.', array('%label' => $edit['label'])));
$this->drupalLogin($this->adminUser);
// Create a block.
$edit = array();
$edit['info[0][value]'] = 'Test Block';
$edit['body[0][value]'] = $this->randomMachineName(16);
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
// Check that the Basic block has been created.
$this->assertRaw(format_string('!block %name has been created.', array(
'!block' => 'basic',
'%name' => $edit['info[0][value]']
)), 'Basic block created.');
// Change the view mode.
$view_mode['settings[view_mode]'] = 'test_view_mode';
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
// Go to the configure page and verify that the new view mode is correct.