BlockContentTestBase.php in Zircon Profile 8.0
File
core/modules/block_content/src/Tests/Views/BlockContentTestBase.php
View source
<?php
namespace Drupal\block_content\Tests\Views;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
abstract class BlockContentTestBase extends ViewTestBase {
protected $adminUser;
protected $permissions = array(
'administer blocks',
);
public static $modules = array(
'block',
'block_content',
'block_content_test_views',
);
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->createBlockContentType(array(
'id' => 'basic',
));
$this->adminUser = $this
->drupalCreateUser($this->permissions);
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), array(
'block_content_test_views',
));
}
}
protected function createBlockContent(array $settings = array()) {
$status = 0;
$settings += array(
'info' => $this
->randomMachineName(),
'type' => 'basic',
'langcode' => 'en',
);
if ($block_content = entity_create('block_content', $settings)) {
$status = $block_content
->save();
}
$this
->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content %info.', array(
'%info' => $block_content
->label(),
)));
return $block_content;
}
protected function createBlockContentType(array $values = array()) {
if (!isset($values['id'])) {
do {
$id = strtolower($this
->randomMachineName(8));
} while (BlockContentType::load($id));
}
else {
$id = $values['id'];
}
$values += array(
'id' => $id,
'label' => $id,
'revision' => FALSE,
);
$bundle = entity_create('block_content_type', $values);
$status = $bundle
->save();
block_content_add_body_field($bundle
->id());
$this
->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content type %bundle.', array(
'%bundle' => $bundle
->id(),
)));
return $bundle;
}
}