updated core
This commit is contained in:
@@ -10,8 +10,8 @@ dependencies:
|
||||
- user
|
||||
configure: entity.block_content.collection
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
* Defines Javascript behaviors for the block_content module.
|
||||
*/
|
||||
|
||||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Sets summaries about revision and translation of block content.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches summary behaviour block content form tabs.
|
||||
*
|
||||
* Specifically, it updates summaries to the revision information and the
|
||||
* translation options.
|
||||
*/
|
||||
Drupal.behaviors.blockContentDetailsSummaries = {
|
||||
attach: function (context) {
|
||||
var $context = $(context);
|
||||
$context.find('.block-content-form-revision-information').drupalSetSummary(function (context) {
|
||||
var $revisionContext = $(context);
|
||||
var revisionCheckbox = $revisionContext.find('.js-form-item-revision input');
|
||||
|
||||
// Return 'New revision' if the 'Create new revision' checkbox is checked,
|
||||
// or if the checkbox doesn't exist, but the revision log does. For users
|
||||
// without the "Administer content" permission the checkbox won't appear,
|
||||
// but the revision log will if the content type is set to auto-revision.
|
||||
if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $revisionContext.find('.js-form-item-revision-log textarea').length)) {
|
||||
return Drupal.t('New revision');
|
||||
}
|
||||
|
||||
return Drupal.t('No revision');
|
||||
});
|
||||
|
||||
$context.find('fieldset.block-content-translation-options').drupalSetSummary(function (context) {
|
||||
var $translationContext = $(context);
|
||||
var translate;
|
||||
var $checkbox = $translationContext.find('.js-form-item-translation-translate input');
|
||||
|
||||
if ($checkbox.size()) {
|
||||
translate = $checkbox.is(':checked') ? Drupal.t('Needs to be updated') : Drupal.t('Does not need to be updated');
|
||||
}
|
||||
else {
|
||||
$checkbox = $translationContext.find('.js-form-item-translation-retranslate input');
|
||||
translate = $checkbox.is(':checked') ? Drupal.t('Flag other translations as outdated') : Drupal.t('Do not flag other translations as outdated');
|
||||
}
|
||||
|
||||
return translate;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal);
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Tests the Custom Block entity's cache tags.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('block_content');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$block_content_type = BlockContentType::create(array(
|
||||
'id' => 'basic',
|
||||
'label' => 'basic',
|
||||
'revision' => FALSE
|
||||
));
|
||||
$block_content_type->save();
|
||||
block_content_add_body_field($block_content_type->id());
|
||||
|
||||
// Create a "Llama" custom block.
|
||||
$block_content = BlockContent::create(array(
|
||||
'info' => 'Llama',
|
||||
'type' => 'basic',
|
||||
'body' => array(
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
),
|
||||
));
|
||||
$block_content->save();
|
||||
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Drupal\block_content\BlockContentAccessControlHandler::checkAccess()
|
||||
*/
|
||||
protected function getAccessCacheContextsForEntity(EntityInterface $entity) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Each comment must have a comment body, which always has a text format.
|
||||
*/
|
||||
protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) {
|
||||
return ['config:filter.format.plain_text'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the block is cached with the correct contexts and tags.
|
||||
*/
|
||||
public function testBlock() {
|
||||
$block = $this->drupalPlaceBlock('block_content:' . $this->entity->uuid());
|
||||
$build = $this->container->get('entity.manager')->getViewBuilder('block')->view($block, 'block');
|
||||
|
||||
// Render the block.
|
||||
// @todo The request stack manipulation won't be necessary once
|
||||
// https://www.drupal.org/node/2367555 is fixed and the
|
||||
// corresponding $request->isMethodSafe() checks are removed from
|
||||
// Drupal\Core\Render\Renderer.
|
||||
$request_stack = $this->container->get('request_stack');
|
||||
$request_stack->push(new Request());
|
||||
$this->container->get('renderer')->renderRoot($build);
|
||||
$request_stack->pop();
|
||||
|
||||
// Expected keys, contexts, and tags for the block.
|
||||
// @see \Drupal\block\BlockViewBuilder::viewMultiple()
|
||||
$expected_block_cache_keys = ['entity_view', 'block', $block->id()];
|
||||
$expected_block_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'];
|
||||
$expected_block_cache_tags = Cache::mergeTags(['block_view', 'rendered'], $block->getCacheTags());
|
||||
$expected_block_cache_tags = Cache::mergeTags($expected_block_cache_tags, $block->getPlugin()->getCacheTags());
|
||||
|
||||
// Expected contexts and tags for the BlockContent entity.
|
||||
// @see \Drupal\Core\Entity\EntityViewBuilder::getBuildDefaults().
|
||||
$expected_entity_cache_contexts = ['theme'];
|
||||
$expected_entity_cache_tags = Cache::mergeTags(['block_content_view'], $this->entity->getCacheTags());
|
||||
$expected_entity_cache_tags = Cache::mergeTags($expected_entity_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity));
|
||||
|
||||
// Verify that what was render cached matches the above expectations.
|
||||
$cid = $this->createCacheId($expected_block_cache_keys, $expected_block_cache_contexts);
|
||||
$redirected_cid = $this->createCacheId($expected_block_cache_keys, Cache::mergeContexts($expected_block_cache_contexts, $expected_entity_cache_contexts));
|
||||
$this->verifyRenderCache($cid, Cache::mergeTags($expected_block_cache_tags, $expected_entity_cache_tags), ($cid !== $redirected_cid) ? $redirected_cid : NULL);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,302 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* 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 and
|
||||
* field_ui to edit display settings.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block_content_test', 'dblog', 'field_ui');
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = array(
|
||||
'administer blocks',
|
||||
'administer block_content display'
|
||||
);
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
$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.');
|
||||
|
||||
// Check that the view mode setting is hidden because only one exists.
|
||||
$this->assertNoFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting hidden because only one exists');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
// Check that attempting to create another block with the same value for
|
||||
// 'info' returns an error.
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('A custom block with block description %value already exists.', array(
|
||||
'%value' => $edit['info[0][value]']
|
||||
)));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a "Basic page" block with multiple view modes.
|
||||
*/
|
||||
public function testBlockContentCreationMultipleViewModes() {
|
||||
// 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.');
|
||||
|
||||
// Save our block permanently
|
||||
$this->drupalPostForm(NULL, NULL, t('Save block'));
|
||||
|
||||
// Set test_view_mode as a custom display to be available on the list.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->drupalGet('admin/structure/block/block-content/types');
|
||||
$this->clickLink(t('Manage display'));
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/basic/display');
|
||||
$custom_view_mode = array(
|
||||
'display_modes_custom[test_view_mode]' => 1,
|
||||
);
|
||||
$this->drupalPostForm(NULL, $custom_view_mode, t('Save'));
|
||||
|
||||
// Go to the configure page and change the view mode.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
|
||||
// Test the available view mode options.
|
||||
$this->assertOption('edit-settings-view-mode', 'default', 'The default view mode is available.');
|
||||
$this->assertOption('edit-settings-view-mode', 'test_view_mode', 'The test view mode is available.');
|
||||
|
||||
$view_mode['settings[view_mode]'] = 'test_view_mode';
|
||||
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
|
||||
|
||||
// Check that the view mode setting is shown because more than one exists.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting shown because multiple exist');
|
||||
|
||||
// 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 the view mode has changed.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]/option[@selected="selected"]/@value', 'test_view_mode', 'View mode changed to Test View Mode');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
// Check that attempting to create another block with the same value for
|
||||
// 'info' returns an error.
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('A custom block with block description %value already exists.', array(
|
||||
'%value' => $edit['info[0][value]']
|
||||
)));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a default custom block.
|
||||
*
|
||||
* Creates a custom block from defaults and ensures that the 'basic block'
|
||||
* type is being used.
|
||||
*/
|
||||
public function testDefaultBlockContentCreation() {
|
||||
$edit = array();
|
||||
$edit['info[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
// Don't pass the custom block type in the url so the default is forced.
|
||||
$this->drupalPostForm('block/add', $edit, t('Save'));
|
||||
|
||||
// Check that the block has been created and that it is a basic block.
|
||||
$this->assertRaw(format_string('@block %name has been created.', array(
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
)), 'Basic block created.');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Default Custom Block found in database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a transaction rolls back the failed creation.
|
||||
*/
|
||||
public function testFailedBlockCreation() {
|
||||
// Create a block.
|
||||
try {
|
||||
$this->createBlockContent('fail_creation');
|
||||
$this->fail('Expected exception has not been thrown.');
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->pass('Expected exception has been thrown.');
|
||||
}
|
||||
|
||||
if (Database::getConnection()->supportsTransactions()) {
|
||||
// Check that the block does not exist in the database.
|
||||
$id = db_select('block_content_field_data', 'b')
|
||||
->fields('b', array('id'))
|
||||
->condition('info', 'fail_creation')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertFalse($id, 'Transactions supported, and block not found in database.');
|
||||
}
|
||||
else {
|
||||
// Check that the block exists in the database.
|
||||
$id = db_select('block_content_field_data', 'b')
|
||||
->fields('b', array('id'))
|
||||
->condition('info', 'fail_creation')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertTrue($id, 'Transactions not supported, and block found in database.');
|
||||
|
||||
// Check that the failed rollback was logged.
|
||||
$records = db_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Explicit rollback failed%'")->fetchAll();
|
||||
$this->assertTrue(count($records) > 0, 'Transactions not supported, and rollback error logged to watchdog.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deleting a block.
|
||||
*/
|
||||
public function testBlockDelete() {
|
||||
// Create a block.
|
||||
$edit = array();
|
||||
$edit['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body = $this->randomMachineName(16);
|
||||
$edit['body[0][value]'] = $body;
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Place the block.
|
||||
$instance = array(
|
||||
'id' => Unicode::strtolower($edit['info[0][value]']),
|
||||
'settings[label]' => $edit['info[0][value]'],
|
||||
'region' => 'sidebar_first',
|
||||
);
|
||||
$block = BlockContent::load(1);
|
||||
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default');
|
||||
$this->drupalPostForm($url, $instance, t('Save block'));
|
||||
|
||||
$block = BlockContent::load(1);
|
||||
|
||||
// Test getInstances method.
|
||||
$this->assertEqual(1, count($block->getInstances()));
|
||||
|
||||
// Navigate to home page.
|
||||
$this->drupalGet('');
|
||||
$this->assertText($body);
|
||||
|
||||
// Delete the block.
|
||||
$this->drupalGet('block/1/delete');
|
||||
$this->assertText(\Drupal::translation()->formatPlural(1, 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instance.'));
|
||||
|
||||
$this->drupalPostForm(NULL, array(), 'Delete');
|
||||
$this->assertRaw(t('The custom block %name has been deleted.', array('%name' => $edit['info[0][value]'])));
|
||||
|
||||
// Create another block and force the plugin cache to flush.
|
||||
$edit2 = array();
|
||||
$edit2['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body2 = $this->randomMachineName(16);
|
||||
$edit2['body[0][value]'] = $body2;
|
||||
$this->drupalPostForm('block/add/basic', $edit2, t('Save'));
|
||||
|
||||
$this->assertNoRaw('Error message');
|
||||
|
||||
// Create another block with no instances, and test we don't get a
|
||||
// confirmation message about deleting instances.
|
||||
$edit3 = array();
|
||||
$edit3['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body = $this->randomMachineName(16);
|
||||
$edit3['body[0][value]'] = $body;
|
||||
$this->drupalPostForm('block/add/basic', $edit3, t('Save'));
|
||||
|
||||
// Show the delete confirm form.
|
||||
$this->drupalGet('block/3/delete');
|
||||
$this->assertNoText('This will also remove');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that placed content blocks create a dependency in the block placement.
|
||||
*/
|
||||
public function testConfigDependencies() {
|
||||
$block = $this->createBlockContent();
|
||||
// Place the block.
|
||||
$block_placement_id = Unicode::strtolower($block->label());
|
||||
$instance = array(
|
||||
'id' => $block_placement_id,
|
||||
'settings[label]' => $block->label(),
|
||||
'region' => 'sidebar_first',
|
||||
);
|
||||
$block = BlockContent::load(1);
|
||||
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default');
|
||||
$this->drupalPostForm($url, $instance, t('Save block'));
|
||||
|
||||
$dependencies = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('content', array($block->getConfigDependencyName()));
|
||||
$block_placement = reset($dependencies);
|
||||
$this->assertEqual($block_placement_id, $block_placement->id(), "The block placement config entity has a dependency on the block content entity.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
/**
|
||||
* Tests the listing of custom blocks.
|
||||
*
|
||||
* Tests the fallback block content list when Views is disabled.
|
||||
*
|
||||
* @group block_content
|
||||
* @see \Drupal\block\BlockContentListBuilder
|
||||
* @see \Drupal\block_content\Tests\BlockContentListViewsTest
|
||||
*/
|
||||
class BlockContentListTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_content', 'config_translation');
|
||||
|
||||
/**
|
||||
* Tests the custom block listing page.
|
||||
*/
|
||||
public function testListing() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer blocks', 'translate configuration')));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Test for the page title.
|
||||
$this->assertTitle(t('Custom block library') . ' | Drupal');
|
||||
|
||||
// Test for the table.
|
||||
$element = $this->xpath('//div[@class="layout-content"]//table');
|
||||
$this->assertTrue($element, 'Configuration entity list table found.');
|
||||
|
||||
// Test the table header.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
|
||||
$this->assertEqual(count($elements), 2, 'Correct number of table header cells found.');
|
||||
|
||||
// Test the contents of each th cell.
|
||||
$expected_items = array(t('Block description'), t('Operations'));
|
||||
foreach ($elements as $key => $element) {
|
||||
$this->assertEqual($element[0], $expected_items[$key]);
|
||||
}
|
||||
|
||||
$label = 'Antelope';
|
||||
$new_label = 'Albatross';
|
||||
// Add a new entity using the operations link.
|
||||
$link_text = t('Add custom block');
|
||||
$this->assertLink($link_text);
|
||||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = array();
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td', $label, 'Label found for added block.');
|
||||
|
||||
// Check the number of table row cells.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td');
|
||||
$this->assertEqual(count($elements), 2, 'Correct number of table row cells found.');
|
||||
// Check the contents of each row cell. The first cell contains the label,
|
||||
// the second contains the machine name, and the third contains the
|
||||
// operations list.
|
||||
$this->assertIdentical((string) $elements[0], $label);
|
||||
|
||||
// Edit the entity using the operations link.
|
||||
$blocks = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(array('info' => $label));
|
||||
$block = reset($blocks);
|
||||
if (!empty($block)) {
|
||||
$this->assertLinkByHref('block/' . $block->id());
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', array('%label' => $label)) . ' | Drupal'));
|
||||
$edit = array('info[0][value]' => $new_label);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
$this->fail('Did not find Albatross block in the database.');
|
||||
}
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td', $new_label, 'Label found for updated custom block.');
|
||||
|
||||
// Delete the added entity using the operations link.
|
||||
$this->assertLinkByHref('block/' . $block->id() . '/delete');
|
||||
$delete_text = t('Delete');
|
||||
$this->clickLink($delete_text);
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', array('%label' => $new_label)) . ' | Drupal'));
|
||||
$this->drupalPostForm(NULL, array(), $delete_text);
|
||||
|
||||
// Verify that the text of the label and machine name does not appear in
|
||||
// the list (though it may appear elsewhere on the page).
|
||||
$this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.');
|
||||
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertText(t('There is no Custom block yet.'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
/**
|
||||
* Tests the Views-powered listing of custom blocks.
|
||||
*
|
||||
* @group block_content
|
||||
* @see \Drupal\block\BlockContentListBuilder
|
||||
* @see \Drupal\block_content\Tests\BlockContentListTest
|
||||
*/
|
||||
class BlockContentListViewsTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'config_translation', 'views'];
|
||||
|
||||
/**
|
||||
* Tests the custom block listing page.
|
||||
*/
|
||||
public function testListing() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer blocks', 'translate configuration')));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Test for the page title.
|
||||
$this->assertTitle(t('Custom block library') . ' | Drupal');
|
||||
|
||||
// Test for the exposed filters.
|
||||
$this->assertFieldByName('info');
|
||||
$this->assertFieldByName('type');
|
||||
|
||||
// Test for the table.
|
||||
$element = $this->xpath('//div[@class="layout-content"]//table');
|
||||
$this->assertTrue($element, 'Views table found.');
|
||||
|
||||
// Test the table header.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
|
||||
$this->assertEqual(count($elements), 4, 'Correct number of table header cells found.');
|
||||
|
||||
// Test the contents of each th cell.
|
||||
$expected_items = ['Block description', 'Block type', 'Updated', 'Operations'];
|
||||
foreach ($elements as $key => $element) {
|
||||
if ($element->xpath('a')) {
|
||||
$this->assertIdentical(trim((string) $element->xpath('a')[0]), $expected_items[$key]);
|
||||
}
|
||||
else {
|
||||
$this->assertIdentical(trim((string) $element[0]), $expected_items[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$label = 'Antelope';
|
||||
$new_label = 'Albatross';
|
||||
// Add a new entity using the operations link.
|
||||
$link_text = t('Add custom block');
|
||||
$this->assertLink($link_text);
|
||||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = array();
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td/a', $label, 'Label found for added block.');
|
||||
|
||||
// Check the number of table row cells.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr/td');
|
||||
$this->assertEqual(count($elements), 4, 'Correct number of table row cells found.');
|
||||
// Check the contents of each row cell. The first cell contains the label,
|
||||
// the second contains the machine name, and the third contains the
|
||||
// operations list.
|
||||
$this->assertIdentical((string) $elements[0]->xpath('a')[0], $label);
|
||||
|
||||
// Edit the entity using the operations link.
|
||||
$blocks = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(array('info' => $label));
|
||||
$block = reset($blocks);
|
||||
if (!empty($block)) {
|
||||
$this->assertLinkByHref('block/' . $block->id());
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', array('%label' => $label)) . ' | Drupal'));
|
||||
$edit = array('info[0][value]' => $new_label);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
$this->fail('Did not find Albatross block in the database.');
|
||||
}
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td/a', $new_label, 'Label found for updated custom block.');
|
||||
|
||||
// Delete the added entity using the operations link.
|
||||
$this->assertLinkByHref('block/' . $block->id() . '/delete');
|
||||
$delete_text = t('Delete');
|
||||
$this->clickLink($delete_text);
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', array('%label' => $new_label)) . ' | Drupal'));
|
||||
$this->drupalPostForm(NULL, array(), $delete_text);
|
||||
|
||||
// Verify that the text of the label and machine name does not appear in
|
||||
// the list (though it may appear elsewhere on the page).
|
||||
$this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.');
|
||||
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertText('There are no custom blocks available.');
|
||||
$this->assertLink('custom block');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
/**
|
||||
* Create a block and test block access by attempting to view the block.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentPageViewTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block_content_test');
|
||||
|
||||
/**
|
||||
* Checks block edit and fallback functionality.
|
||||
*/
|
||||
public function testPageEdit() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$block = $this->createBlockContent();
|
||||
|
||||
// Attempt to view the block.
|
||||
$this->drupalGet('block-content/' . $block->id());
|
||||
|
||||
// Assert response was '200' and not '403 Access denied'.
|
||||
$this->assertResponse('200', 'User was able the view the block');
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertRaw(t('This block is broken or missing. You may be missing content or you might need to enable the original module.'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Create a block with revisions.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentRevisionsTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Stores blocks created during the test.
|
||||
* @var array
|
||||
*/
|
||||
protected $blocks;
|
||||
|
||||
/**
|
||||
* Stores log messages used during the test.
|
||||
* @var array
|
||||
*/
|
||||
protected $revisionLogs;
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create initial block.
|
||||
$block = $this->createBlockContent('initial');
|
||||
|
||||
$blocks = array();
|
||||
$logs = array();
|
||||
|
||||
// Get original block.
|
||||
$blocks[] = $block->getRevisionId();
|
||||
$logs[] = '';
|
||||
|
||||
// Create three revisions.
|
||||
$revision_count = 3;
|
||||
for ($i = 0; $i < $revision_count; $i++) {
|
||||
$block->setNewRevision(TRUE);
|
||||
$block->setRevisionLog($this->randomMachineName(32));
|
||||
$logs[] = $block->getRevisionLog();
|
||||
$block->save();
|
||||
$blocks[] = $block->getRevisionId();
|
||||
}
|
||||
|
||||
$this->blocks = $blocks;
|
||||
$this->revisionLogs = $logs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks block revision related operations.
|
||||
*/
|
||||
public function testRevisions() {
|
||||
$blocks = $this->blocks;
|
||||
$logs = $this->revisionLogs;
|
||||
|
||||
foreach ($blocks as $delta => $revision_id) {
|
||||
// Confirm the correct revision text appears.
|
||||
$loaded = entity_revision_load('block_content', $revision_id);
|
||||
// Verify revision log is the same.
|
||||
$this->assertEqual($loaded->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision @revision', array(
|
||||
'@revision' => $loaded->getRevisionId(),
|
||||
)));
|
||||
}
|
||||
|
||||
// Confirm that this is the default revision.
|
||||
$this->assertTrue($loaded->isDefaultRevision(), 'Third block revision is the default one.');
|
||||
|
||||
// Make a new revision and set it to not be default.
|
||||
// This will create a new revision that is not "front facing".
|
||||
// Save this as a non-default revision.
|
||||
$loaded->setNewRevision();
|
||||
$loaded->isDefaultRevision(FALSE);
|
||||
$loaded->body = $this->randomMachineName(8);
|
||||
$loaded->save();
|
||||
|
||||
$this->drupalGet('block/' . $loaded->id());
|
||||
$this->assertNoText($loaded->body->value, 'Revision body text is not present on default version of block.');
|
||||
|
||||
// Verify that the non-default revision id is greater than the default
|
||||
// revision id.
|
||||
$default_revision = BlockContent::load($loaded->id());
|
||||
$this->assertTrue($loaded->getRevisionId() > $default_revision->getRevisionId(), 'Revision id is greater than default revision id.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Tests $block_content->save() for saving content.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentSaveTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block_content_test');
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether custom block IDs are saved properly during an import.
|
||||
*/
|
||||
public function testImport() {
|
||||
// Custom block ID must be a number that is not in the database.
|
||||
$max_id = db_query('SELECT MAX(id) FROM {block_content}')->fetchField();
|
||||
$test_id = $max_id + mt_rand(1000, 1000000);
|
||||
$info = $this->randomMachineName(8);
|
||||
$block_array = array(
|
||||
'info' => $info,
|
||||
'body' => array('value' => $this->randomMachineName(32)),
|
||||
'type' => 'basic',
|
||||
'id' => $test_id
|
||||
);
|
||||
$block = BlockContent::create($block_array);
|
||||
$block->enforceIsNew(TRUE);
|
||||
$block->save();
|
||||
|
||||
// Verify that block_submit did not wipe the provided id.
|
||||
$this->assertEqual($block->id(), $test_id, 'Block imported using provide id');
|
||||
|
||||
// Test the import saved.
|
||||
$block_by_id = BlockContent::load($test_id);
|
||||
$this->assertTrue($block_by_id, 'Custom block load by block ID.');
|
||||
$this->assertIdentical($block_by_id->body->value, $block_array['body']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests determining changes in hook_block_presave().
|
||||
*
|
||||
* Verifies the static block load cache is cleared upon save.
|
||||
*/
|
||||
public function testDeterminingChanges() {
|
||||
// Initial creation.
|
||||
$block = $this->createBlockContent('test_changes');
|
||||
$this->assertEqual($block->getChangedTime(), REQUEST_TIME, 'Creating a block sets default "changed" timestamp.');
|
||||
|
||||
// Update the block without applying changes.
|
||||
$block->save();
|
||||
$this->assertEqual($block->label(), 'test_changes', 'No changes have been determined.');
|
||||
|
||||
// Apply changes.
|
||||
$block->setInfo('updated');
|
||||
$block->save();
|
||||
|
||||
// The hook implementations block_content_test_block_content_presave() and
|
||||
// block_content_test_block_content_update() determine changes and change
|
||||
// the title as well as programmatically set the 'changed' timestamp.
|
||||
$this->assertEqual($block->label(), 'updated_presave_update', 'Changes have been determined.');
|
||||
$this->assertEqual($block->getChangedTime(), 979534800, 'Saving a custom block uses "changed" timestamp set in presave hook.');
|
||||
|
||||
// Test the static block load cache to be cleared.
|
||||
$block = BlockContent::load($block->id());
|
||||
$this->assertEqual($block->label(), 'updated_presave', 'Static cache has been cleared.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests saving a block on block insert.
|
||||
*
|
||||
* This test ensures that a block has been fully saved when
|
||||
* hook_block_content_insert() is invoked, so that the block can be saved again
|
||||
* in a hook implementation without errors.
|
||||
*
|
||||
* @see block_test_block_insert()
|
||||
*/
|
||||
public function testBlockContentSaveOnInsert() {
|
||||
// block_content_test_block_content_insert() triggers a save on insert if the
|
||||
// title equals 'new'.
|
||||
$block = $this->createBlockContent('new');
|
||||
$this->assertEqual($block->label(), 'BlockContent ' . $block->id(), 'Custom block saved on block insert.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,8 @@ abstract class BlockContentTestBase extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Profile to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $profile = 'testing';
|
||||
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
|
||||
|
||||
/**
|
||||
* Tests the block content translation UI.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
'language',
|
||||
'content_translation',
|
||||
'block',
|
||||
'field_ui',
|
||||
'block_content'
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultCacheContexts = [
|
||||
'languages:language_interface',
|
||||
'session',
|
||||
'theme',
|
||||
'url.path',
|
||||
'url.query_args',
|
||||
'user.permissions',
|
||||
'user.roles:authenticated',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityTypeId = 'block_content';
|
||||
$this->bundle = 'basic';
|
||||
$this->testLanguageSelector = FALSE;
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setupBundle() {
|
||||
// Create the basic bundle since it is provided by standard.
|
||||
$bundle = BlockContentType::create(array(
|
||||
'id' => $this->bundle,
|
||||
'label' => $this->bundle,
|
||||
'revision' => FALSE
|
||||
));
|
||||
$bundle->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTranslatorPermissions() {
|
||||
return array_merge(parent::getTranslatorPermissions(), array(
|
||||
'translate any entity',
|
||||
'access administration pages',
|
||||
'administer blocks',
|
||||
'administer block_content fields'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block.
|
||||
*
|
||||
* @param bool|string $title
|
||||
* (optional) Title of block. When no value is given uses a random name.
|
||||
* Defaults to FALSE.
|
||||
* @param bool|string $bundle
|
||||
* (optional) Bundle name. When no value is given, defaults to
|
||||
* $this->bundle. Defaults to FALSE.
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContent
|
||||
* Created custom block.
|
||||
*/
|
||||
protected function createBlockContent($title = FALSE, $bundle = FALSE) {
|
||||
$title = $title ?: $this->randomMachineName();
|
||||
$bundle = $bundle ?: $this->bundle;
|
||||
$block_content = BlockContent::create(array(
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en'
|
||||
));
|
||||
$block_content->save();
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNewEntityValues($langcode) {
|
||||
return array('info' => Unicode::strtolower($this->randomMachineName())) + parent::getNewEntityValues($langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit array containing the values to be posted.
|
||||
*/
|
||||
protected function getEditValues($values, $langcode, $new = FALSE) {
|
||||
$edit = parent::getEditValues($values, $langcode, $new);
|
||||
foreach ($edit as $property => $value) {
|
||||
if ($property == 'info') {
|
||||
$edit['info[0][value]'] = $value;
|
||||
unset($edit[$property]);
|
||||
}
|
||||
}
|
||||
return $edit;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doTestBasicTranslation() {
|
||||
parent::doTestBasicTranslation();
|
||||
|
||||
// Ensure that a block translation can be created using the same description
|
||||
// as in the original language.
|
||||
$default_langcode = $this->langcodes[0];
|
||||
$values = $this->getNewEntityValues($default_langcode);
|
||||
$storage = \Drupal::entityManager()->getStorage($this->entityTypeId);
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
||||
$entity = $storage->create(array('type' => 'basic') + $values);
|
||||
$entity->save();
|
||||
$entity->addTranslation('it', $values);
|
||||
|
||||
try {
|
||||
$message = 'Blocks can have translations with the same "info" value.';
|
||||
$entity->save();
|
||||
$this->pass($message);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->fail($message);
|
||||
}
|
||||
|
||||
// Check that the translate operation link is shown.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->assertLinkByHref('block/' . $entity->id() . '/translations');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that no metadata is stored for a disabled bundle.
|
||||
*/
|
||||
public function testDisabledBundle() {
|
||||
// Create a bundle that does not have translation enabled.
|
||||
$disabled_bundle = $this->randomMachineName();
|
||||
$bundle = BlockContentType::create(array(
|
||||
'id' => $disabled_bundle,
|
||||
'label' => $disabled_bundle,
|
||||
'revision' => FALSE
|
||||
));
|
||||
$bundle->save();
|
||||
|
||||
// Create a block content for each bundle.
|
||||
$enabled_block_content = $this->createBlockContent();
|
||||
$disabled_block_content = $this->createBlockContent(FALSE, $bundle->id());
|
||||
|
||||
// Make sure that only a single row was inserted into the block table.
|
||||
$rows = db_query('SELECT * FROM {block_content_field_data} WHERE id = :id', array(':id' => $enabled_block_content->id()))->fetchAll();
|
||||
$this->assertEqual(1, count($rows));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doTestTranslationEdit() {
|
||||
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
|
||||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
// We only want to test the title for non-english translations.
|
||||
if ($langcode != 'en') {
|
||||
$options = array('language' => $languages[$langcode]);
|
||||
$url = $entity->urlInfo('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
|
||||
$title = t('<em>Edit @type</em> @title [%language translation]', array(
|
||||
'@type' => $entity->bundle(),
|
||||
'@title' => $entity->getTranslation($langcode)->label(),
|
||||
'%language' => $languages[$langcode]->getName(),
|
||||
));
|
||||
$this->assertRaw($title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\system\Tests\Menu\AssertBreadcrumbTrait;
|
||||
|
||||
/**
|
||||
* Ensures that custom block type functions work correctly.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentTypeTest extends BlockContentTestBase {
|
||||
|
||||
use AssertBreadcrumbTrait;
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field_ui'];
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
'administer block_content fields'
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether or not to create an initial block type.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $autoCreateBasicBlockType = FALSE;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating a block type programmatically and via a form.
|
||||
*/
|
||||
public function testBlockContentTypeCreation() {
|
||||
// Log in a test user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Test the page with no block-types.
|
||||
$this->drupalGet('block/add');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('You have not created any block types yet');
|
||||
$this->clickLink('block type creation page');
|
||||
|
||||
// Create a block type via the user interface.
|
||||
$edit = [
|
||||
'id' => 'foo',
|
||||
'label' => 'title for foo',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$block_type = BlockContentType::load('foo');
|
||||
$this->assertTrue($block_type, 'The new block type has been created.');
|
||||
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'foo');
|
||||
$this->assertTrue(isset($field_definitions['body']), 'Body field created when using the UI to create block content types.');
|
||||
|
||||
// Check that the block type was created in site default language.
|
||||
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
||||
$this->assertEqual($block_type->language()->getId(), $default_langcode);
|
||||
|
||||
// Create block types programmatically.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'basic');
|
||||
$this->assertTrue(isset($field_definitions['body']), "Body field for 'basic' block type created when using the testing API to create block content types.");
|
||||
|
||||
$this->createBlockContentType('other');
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
|
||||
$this->assertFalse(isset($field_definitions['body']), "Body field for 'other' block type not created when using the testing API to create block content types.");
|
||||
|
||||
$block_type = BlockContentType::load('other');
|
||||
$this->assertTrue($block_type, 'The new block type has been created.');
|
||||
|
||||
$this->drupalGet('block/add/' . $block_type->id());
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests editing a block type using the UI.
|
||||
*/
|
||||
public function testBlockContentTypeEditing() {
|
||||
$this->drupalPlaceBlock('system_breadcrumb_block');
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// We need two block types to prevent /block/add redirecting.
|
||||
$this->createBlockContentType('other');
|
||||
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
|
||||
$this->assertFalse(isset($field_definitions['body']), 'Body field was not created when using the API to create block content types.');
|
||||
|
||||
// Verify that title and body fields are displayed.
|
||||
$this->drupalGet('block/add/basic');
|
||||
$this->assertRaw('Block description', 'Block info field was found.');
|
||||
$this->assertRaw('Body', 'Body field was found.');
|
||||
|
||||
// Change the block type name.
|
||||
$edit = [
|
||||
'label' => 'Bar',
|
||||
];
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/basic');
|
||||
$this->assertTitle(format_string('Edit @type custom block type | Drupal', ['@type' => 'basic']));
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$front_page_path = Url::fromRoute('<front>')->toString();
|
||||
$this->assertBreadcrumb('admin/structure/block/block-content/manage/basic/fields', [
|
||||
$front_page_path => 'Home',
|
||||
'admin/structure/block' => 'Block layout',
|
||||
'admin/structure/block/block-content' => 'Custom block library',
|
||||
'admin/structure/block/block-content/manage/basic' => 'Bar',
|
||||
]);
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
||||
$this->drupalGet('block/add');
|
||||
$this->assertRaw('Bar', 'New name was displayed.');
|
||||
$this->clickLink('Bar');
|
||||
$this->assertUrl(\Drupal::url('block_content.add_form', ['block_content_type' => 'basic'], ['absolute' => TRUE]), [], 'Original machine name was used in URL.');
|
||||
|
||||
// Remove the body field.
|
||||
$this->drupalPostForm('admin/structure/block/block-content/manage/basic/fields/block_content.basic.body/delete', [], t('Delete'));
|
||||
// Resave the settings for this type.
|
||||
$this->drupalPostForm('admin/structure/block/block-content/manage/basic', [], t('Save'));
|
||||
// Check that the body field doesn't exist.
|
||||
$this->drupalGet('block/add/basic');
|
||||
$this->assertNoRaw('Body', 'Body field was not found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deleting a block type that still has content.
|
||||
*/
|
||||
public function testBlockContentTypeDeletion() {
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
// Create a block type programmatically.
|
||||
$type = $this->createBlockContentType('foo');
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Add a new block of this type.
|
||||
$block = $this->createBlockContent(FALSE, 'foo');
|
||||
// Attempt to delete the block type, which should not be allowed.
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
|
||||
$this->assertRaw(
|
||||
t('%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', ['%label' => $type->label()]),
|
||||
'The block type will not be deleted until all blocks of that type are removed.'
|
||||
);
|
||||
$this->assertNoText(t('This action cannot be undone.'), 'The block type deletion confirmation form is not available.');
|
||||
|
||||
// Delete the block.
|
||||
$block->delete();
|
||||
// Attempt to delete the block type, which should now be allowed.
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
|
||||
$this->assertRaw(
|
||||
t('Are you sure you want to delete the custom block type %type?', ['%type' => $type->id()]),
|
||||
'The block type is available for deletion.'
|
||||
);
|
||||
$this->assertText(t('This action cannot be undone.'), 'The custom block type deletion confirmation form is available.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that redirects work as expected when multiple block types exist.
|
||||
*/
|
||||
public function testsBlockContentAddTypes() {
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Create two block types programmatically.
|
||||
$type = $this->createBlockContentType('foo');
|
||||
$type = $this->createBlockContentType('bar');
|
||||
|
||||
// Get the custom block storage.
|
||||
$storage = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content');
|
||||
|
||||
// Install all themes.
|
||||
\Drupal::service('theme_handler')->install(['bartik', 'seven', 'stark']);
|
||||
$theme_settings = $this->config('system.theme');
|
||||
foreach (['bartik', 'seven', 'stark'] as $default_theme) {
|
||||
// Change the default theme.
|
||||
$theme_settings->set('default', $default_theme)->save();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// For each installed theme, go to its block page and test the redirects.
|
||||
foreach (['bartik', 'seven', 'stark'] as $theme) {
|
||||
// Test that adding a block from the 'place blocks' form sends you to the
|
||||
// block configure form.
|
||||
$path = $theme == $default_theme ? 'admin/structure/block' : "admin/structure/block/list/$theme";
|
||||
$this->drupalGet($path);
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$this->clickLink(t('Add custom block'));
|
||||
// The seven theme has markup inside the link, we cannot use clickLink().
|
||||
if ($default_theme == 'seven') {
|
||||
$options = $theme != $default_theme ? ['query' => ['theme' => $theme]] : [];
|
||||
$this->assertLinkByHref(\Drupal::url('block_content.add_form', ['block_content_type' => 'foo'], $options));
|
||||
$this->drupalGet('block/add/foo', $options);
|
||||
}
|
||||
else {
|
||||
$this->clickLink('foo');
|
||||
}
|
||||
// Create a new block.
|
||||
$edit = ['info[0][value]' => $this->randomMachineName(8)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
if (!empty($blocks)) {
|
||||
$block = reset($blocks);
|
||||
$this->assertUrl(\Drupal::url('block.admin_add', ['plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme], ['absolute' => TRUE]));
|
||||
$this->drupalPostForm(NULL, ['region' => 'content'], t('Save block'));
|
||||
$this->assertUrl(\Drupal::url('block.admin_display_theme', ['theme' => $theme], ['absolute' => TRUE, 'query' => ['block-placement' => Html::getClass($edit['info[0][value]'])]]));
|
||||
}
|
||||
else {
|
||||
$this->fail('Could not load created block.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test that adding a block from the 'custom blocks list' doesn't send you
|
||||
// to the block configure form.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->clickLink(t('Add custom block'));
|
||||
$this->clickLink('foo');
|
||||
$edit = ['info[0][value]' => $this->randomMachineName(8)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
if (!empty($blocks)) {
|
||||
$this->assertUrl(\Drupal::url('entity.block_content.collection', [], ['absolute' => TRUE]));
|
||||
}
|
||||
else {
|
||||
$this->fail('Could not load created block.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests update functions for the Block Content module.
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class BlockContentUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the revision metadata fields and revision data table additions.
|
||||
*/
|
||||
public function testSimpleUpdates() {
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
|
||||
$this->assertNull($entity_type->getRevisionDataTable());
|
||||
|
||||
$this->runUpdates();
|
||||
|
||||
$post_revision_created = $entity_definition_update_manager->getFieldStorageDefinition('revision_created', 'block_content');
|
||||
$post_revision_user = $entity_definition_update_manager->getFieldStorageDefinition('revision_user', 'block_content');
|
||||
$this->assertTrue($post_revision_created instanceof BaseFieldDefinition, "Revision created field found");
|
||||
$this->assertTrue($post_revision_user instanceof BaseFieldDefinition, "Revision user field found");
|
||||
|
||||
$this->assertEqual('created', $post_revision_created->getType(), "Field is type created");
|
||||
$this->assertEqual('entity_reference', $post_revision_user->getType(), "Field is type entity_reference");
|
||||
|
||||
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
|
||||
$this->assertEqual('block_content_field_revision', $entity_type->getRevisionDataTable());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
/**
|
||||
* Tests block content validation constraints.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentValidationTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Tests the block content validation constraints.
|
||||
*/
|
||||
public function testValidation() {
|
||||
// Add a block.
|
||||
$description = $this->randomMachineName();
|
||||
$block = $this->createBlockContent($description, 'basic');
|
||||
// Validate the block.
|
||||
$violations = $block->validate();
|
||||
// Make sure we have no violations.
|
||||
$this->assertEqual(count($violations), 0);
|
||||
// Save the block.
|
||||
$block->save();
|
||||
|
||||
// Add another block with the same description.
|
||||
$block = $this->createBlockContent($description, 'basic');
|
||||
// Validate this block.
|
||||
$violations = $block->validate();
|
||||
// Make sure we have 1 violation.
|
||||
$this->assertEqual(count($violations), 1);
|
||||
// Make sure the violation is on the info property
|
||||
$this->assertEqual($violations[0]->getPropertyPath(), 'info');
|
||||
// Make sure the message is correct.
|
||||
$this->assertEqual($violations[0]->getMessage(), format_string('A custom block with block description %value already exists.', [
|
||||
'%value' => $block->label(),
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Create a block and test block edit functionality.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class PageEditTest extends BlockContentTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks block edit functionality.
|
||||
*/
|
||||
public function testPageEdit() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$title_key = 'info[0][value]';
|
||||
$body_key = 'body[0][value]';
|
||||
// Create block to edit.
|
||||
$edit = array();
|
||||
$edit['info[0][value]'] = Unicode::strtolower($this->randomMachineName(8));
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = \Drupal::entityQuery('block_content')->condition('info', $edit['info[0][value]'])->execute();
|
||||
$block = BlockContent::load(reset($blocks));
|
||||
$this->assertTrue($block, 'Custom block found in database.');
|
||||
|
||||
// Load the edit page.
|
||||
$this->drupalGet('block/' . $block->id());
|
||||
$this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
|
||||
$this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
|
||||
|
||||
// Edit the content of the block.
|
||||
$edit = array();
|
||||
$edit[$title_key] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
// Stay on the current page, without reloading.
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Edit the same block, creating a new revision.
|
||||
$this->drupalGet("block/" . $block->id());
|
||||
$edit = array();
|
||||
$edit['info[0][value]'] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$edit['revision'] = TRUE;
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Ensure that the block revision has been created.
|
||||
\Drupal::entityManager()->getStorage('block_content')->resetCache(array($block->id()));
|
||||
$revised_block = BlockContent::load($block->id());
|
||||
$this->assertNotIdentical($block->getRevisionId(), $revised_block->getRevisionId(), 'A new revision has been created.');
|
||||
|
||||
// Test deleting the block.
|
||||
$this->drupalGet("block/" . $revised_block->id());
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertText(format_string('Are you sure you want to delete the custom block @label?', array('@label' => $revised_block->label())));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests block_content field filters with translations.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentFieldFilterTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_field_filters');
|
||||
|
||||
/**
|
||||
* List of block_content infos by language.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $blockContentInfos = [];
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Add two new languages.
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
ConfigurableLanguage::createFromLangcode('es')->save();
|
||||
|
||||
// Make the body field translatable. The info is already translatable by
|
||||
// definition.
|
||||
$field_storage = FieldStorageConfig::loadByName('block_content', 'body');
|
||||
$field_storage->setTranslatable(TRUE);
|
||||
$field_storage->save();
|
||||
|
||||
// Set up block_content infos.
|
||||
$this->blockContentInfos = array(
|
||||
'en' => 'Food in Paris',
|
||||
'es' => 'Comida en Paris',
|
||||
'fr' => 'Nouriture en Paris',
|
||||
);
|
||||
|
||||
// Create block_content with translations.
|
||||
$block_content = $this->createBlockContent(['info' => $this->blockContentInfos['en'], 'langcode' => 'en', 'type' => 'basic', 'body' => [['value' => $this->blockContentInfos['en']]]]);
|
||||
foreach (array('es', 'fr') as $langcode) {
|
||||
$translation = $block_content->addTranslation($langcode, ['info' => $this->blockContentInfos[$langcode]]);
|
||||
$translation->body->value = $this->blockContentInfos[$langcode];
|
||||
}
|
||||
$block_content->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests body and info filters.
|
||||
*/
|
||||
public function testFilters() {
|
||||
// Test the info filter page, which filters for info contains 'Comida'.
|
||||
// Should show just the Spanish translation, once.
|
||||
$this->assertPageCounts('test-info-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida info filter');
|
||||
|
||||
// Test the body filter page, which filters for body contains 'Comida'.
|
||||
// Should show just the Spanish translation, once.
|
||||
$this->assertPageCounts('test-body-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida body filter');
|
||||
|
||||
// Test the info Paris filter page, which filters for info contains
|
||||
// 'Paris'. Should show each translation once.
|
||||
$this->assertPageCounts('test-info-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris info filter');
|
||||
|
||||
// Test the body Paris filter page, which filters for body contains
|
||||
// 'Paris'. Should show each translation once.
|
||||
$this->assertPageCounts('test-body-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris body filter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given block_content translation counts are correct.
|
||||
*
|
||||
* @param string $path
|
||||
* Path of the page to test.
|
||||
* @param array $counts
|
||||
* Array whose keys are languages, and values are the number of times
|
||||
* that translation should be shown on the given page.
|
||||
* @param string $message
|
||||
* Message suffix to display.
|
||||
*/
|
||||
protected function assertPageCounts($path, $counts, $message) {
|
||||
// Get the text of the page.
|
||||
$this->drupalGet($path);
|
||||
$text = $this->getTextContent();
|
||||
|
||||
foreach ($counts as $langcode => $count) {
|
||||
$this->assertEqual(substr_count($text, $this->blockContentInfos[$langcode]), $count, 'Translation ' . $langcode . ' has count ' . $count . ' with ' . $message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests\Views;
|
||||
|
||||
/**
|
||||
* Tests the block_content integration into views.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentIntegrationTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_block_content_view');
|
||||
|
||||
/**
|
||||
* Tests basic block_content view with a block_content_type argument.
|
||||
*/
|
||||
public function testBlockContentViewTypeArgument() {
|
||||
// Create two content types with three block_contents each.
|
||||
$types = array();
|
||||
$all_ids = array();
|
||||
$block_contents = array();
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$type = $this->createBlockContentType();
|
||||
$types[] = $type;
|
||||
|
||||
for ($j = 0; $j < 5; $j++) {
|
||||
// Ensure the right order of the block_contents.
|
||||
$block_content = $this->createBlockContent(array('type' => $type->id()));
|
||||
$block_contents[$type->id()][$block_content->id()] = $block_content;
|
||||
$all_ids[] = $block_content->id();
|
||||
}
|
||||
}
|
||||
|
||||
$this->drupalGet('test-block_content-view');
|
||||
$this->assertResponse(404);
|
||||
|
||||
$this->drupalGet('test-block_content-view/all');
|
||||
$this->assertResponse(200);
|
||||
$this->assertIds($all_ids);
|
||||
/* @var \Drupal\block_content\Entity\BlockContentType[] $types*/
|
||||
foreach ($types as $type) {
|
||||
$this->drupalGet("test-block_content-view/{$type->id()}");
|
||||
$this->assertIds(array_keys($block_contents[$type->id()]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that a list of block_contents appear on the page.
|
||||
*
|
||||
* @param array $expected_ids
|
||||
* An array of block_content IDs.
|
||||
*/
|
||||
protected function assertIds(array $expected_ids = array()) {
|
||||
$result = $this->xpath('//span[@class="field-content"]');
|
||||
$ids = array();
|
||||
foreach ($result as $element) {
|
||||
$ids[] = (int) $element;
|
||||
}
|
||||
$this->assertEqual($ids, $expected_ids);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the Drupal\block_content\Plugin\views\field\Type handler.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class FieldTypeTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_field_type');
|
||||
|
||||
public function testFieldType() {
|
||||
$block_content = $this->createBlockContent();
|
||||
$expected_result[] = array(
|
||||
'id' => $block_content->id(),
|
||||
'type' => $block_content->bundle(),
|
||||
);
|
||||
$column_map = array(
|
||||
'id' => 'id',
|
||||
'type:target_id' => 'type',
|
||||
);
|
||||
|
||||
$view = Views::getView('test_field_type');
|
||||
$this->executeView($view);
|
||||
$this->assertIdenticalResultset($view, $expected_result, $column_map, 'The correct block_content type was displayed.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests\Views;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
* Tests the integration of block_content_revision table of block_content module.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class RevisionRelationshipsTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block_content' , 'block_content_test_views');
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_block_content_revision_id', 'test_block_content_revision_revision_id');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
BlockContentType::create(array(
|
||||
'id' => 'basic',
|
||||
'label' => 'basic',
|
||||
'revision' => TRUE,
|
||||
));
|
||||
ViewTestData::createTestViews(get_class($this), array('block_content_test_views'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a block_content with revision and rest result count for both views.
|
||||
*/
|
||||
public function testBlockContentRevisionRelationship() {
|
||||
$block_content = BlockContent::create(array(
|
||||
'info' => $this->randomMachineName(),
|
||||
'type' => 'basic',
|
||||
'langcode' => 'en',
|
||||
));
|
||||
$block_content->save();
|
||||
// Create revision of the block_content.
|
||||
$block_content_revision = clone $block_content;
|
||||
$block_content_revision->setNewRevision();
|
||||
$block_content_revision->save();
|
||||
$column_map = array(
|
||||
'revision_id' => 'revision_id',
|
||||
'id_1' => 'id_1',
|
||||
'block_content_field_data_block_content_field_revision_id' => 'block_content_field_data_block_content_field_revision_id',
|
||||
);
|
||||
|
||||
// Here should be two rows.
|
||||
$view_id = Views::getView('test_block_content_revision_id');
|
||||
$this->executeView($view_id, array($block_content->id()));
|
||||
$resultset_id = array(
|
||||
array(
|
||||
'revision_id' => '1',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
),
|
||||
array(
|
||||
'revision_id' => '2',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view_id, $resultset_id, $column_map);
|
||||
|
||||
// There should be only one row with active revision 2.
|
||||
$view_revision_id = Views::getView('test_block_content_revision_revision_id');
|
||||
$this->executeView($view_revision_id, array($block_content->id()));
|
||||
$resultset_revision_id = array(
|
||||
array(
|
||||
'revision_id' => '2',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view_revision_id, $resultset_revision_id, $column_map);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- block_content
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
+3
-3
@@ -8,8 +8,8 @@ dependencies:
|
||||
- block_content
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -31,7 +31,7 @@ class BlockContentRevisionsTest extends BlockContentTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
/** @var UserInterface $user */
|
||||
/** @var \Drupal\user\Entity\UserInterface $user */
|
||||
$user = User::load(1);
|
||||
|
||||
// Create initial block.
|
||||
|
||||
@@ -13,6 +13,8 @@ abstract class BlockContentTestBase extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Profile to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $profile = 'testing';
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class MigrateBlockContentTest extends MigrateDrupal6TestBase {
|
||||
* Tests the Drupal 6 custom block to Drupal 8 migration.
|
||||
*/
|
||||
public function testBlockMigration() {
|
||||
/** @var BlockContent $block */
|
||||
/** @var \Drupal\block_content\Entity\BlockContent $block */
|
||||
$block = BlockContent::load(1);
|
||||
$this->assertIdentical('My block 1', $block->label());
|
||||
$this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time());
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Unit\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D6 block boxes source plugin.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BoxTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\block_content\Plugin\migrate\source\d6\Box';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'd6_boxes',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'bid' => 1,
|
||||
'body' => '<p>I made some custom content.</p>',
|
||||
'info' => 'Static Block',
|
||||
'format' => 1,
|
||||
),
|
||||
array(
|
||||
'bid' => 2,
|
||||
'body' => '<p>I made some more custom content.</p>',
|
||||
'info' => 'Test Content',
|
||||
'format' => 1,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Prepopulate contents with results.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['boxes'] = $this->expectedResults;
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Unit\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\block_content\Plugin\migrate\source\d7\BlockCustom;
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\block_content\Plugin\migrate\source\d7\BlockCustom
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockCustomTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = BlockCustom::class;
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'd7_block_custom',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'bid' => '1',
|
||||
'body' => "I don't feel creative enough to write anything clever here.",
|
||||
'info' => 'Meh',
|
||||
'format' => 'filtered_html',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['block_custom'] = $this->expectedResults;
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user