Commit 219df57c authored by catch's avatar catch
Browse files

Issue #3015855 by Neslee Canil Pinto, mondrake, hash6, neel24, daffie,...

Issue #3015855 by Neslee Canil Pinto, mondrake, hash6, neel24, daffie, andypost: Replace all db calls to block_content table with Entity APIs
parent 134ea3f8
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Drupal\Tests\block_content\Functional; namespace Drupal\Tests\block_content\Functional;
use Drupal\block_content\Entity\BlockContent; use Drupal\block_content\Entity\BlockContent;
use Drupal\Core\Database\Database;
/** /**
* Tests $block_content->save() for saving content. * Tests $block_content->save() for saving content.
...@@ -38,7 +37,7 @@ protected function setUp(): void { ...@@ -38,7 +37,7 @@ protected function setUp(): void {
*/ */
public function testImport() { public function testImport() {
// Custom block ID must be a number that is not in the database. // 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); $test_id = $max_id + mt_rand(1000, 1000000);
$info = $this->randomMachineName(8); $info = $this->randomMachineName(8);
$block_array = [ $block_array = [
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
namespace Drupal\Tests\block_content\Functional; namespace Drupal\Tests\block_content\Functional;
use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType; use Drupal\block_content\Entity\BlockContentType;
use Drupal\Core\Database\Database;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase; use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
/** /**
...@@ -82,31 +80,6 @@ public function getTranslatorPermissions() { ...@@ -82,31 +80,6 @@ public function getTranslatorPermissions() {
]); ]);
} }
/**
* 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} * {@inheritdoc}
*/ */
...@@ -158,28 +131,6 @@ protected function doTestBasicTranslation() { ...@@ -158,28 +131,6 @@ protected function doTestBasicTranslation() {
$this->assertLinkByHref('block/' . $entity->id() . '/translations'); $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} * {@inheritdoc}
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment