Issue #3015855 by Neslee Canil Pinto, mondrake, hash6, neel24, daffie, andypost: Replace all db calls to block_content table with Entity APIs
(cherry picked from commit 219df57c0d
)
merge-requests/2419/head
parent
a96d4b3f92
commit
701a778095
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Tests $block_content->save() for saving content.
|
||||
|
@ -38,7 +37,7 @@ class BlockContentSaveTest extends BlockContentTestBase {
|
|||
*/
|
||||
public function testImport() {
|
||||
// Custom block ID must be a number that is not in the database.
|
||||
$max_id = Database::getConnection()->query('SELECT MAX(id) FROM {block_content}')->fetchField();
|
||||
$max_id = (int) \Drupal::entityQueryAggregate('block_content')->aggregate('id', 'max')->execute()[0]['id_max'];
|
||||
$test_id = $max_id + mt_rand(1000, 1000000);
|
||||
$info = $this->randomMachineName(8);
|
||||
$block_array = [
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
|
||||
|
||||
/**
|
||||
|
@ -82,31 +80,6 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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([
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en',
|
||||
]);
|
||||
$block_content->save();
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -158,28 +131,6 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
$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([
|
||||
'id' => $disabled_bundle,
|
||||
'label' => $disabled_bundle,
|
||||
'revision' => FALSE,
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
// Create a block content for each bundle.
|
||||
$enabled_block_content = $this->createBlockContent();
|
||||
$this->createBlockContent(FALSE, $bundle->id());
|
||||
|
||||
// Make sure that only a single row was inserted into the block table.
|
||||
$rows = Database::getConnection()->query('SELECT * FROM {block_content_field_data} WHERE id = :id', [':id' => $enabled_block_content->id()])->fetchAll();
|
||||
$this->assertEqual(1, count($rows));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue