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
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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 @@ protected function setUp(): void {
   */
  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 = [
+0 −49
Original line number Diff line number Diff line
@@ -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 @@ 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}
   */
@@ -158,28 +131,6 @@ protected function doTestBasicTranslation() {
    $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}
   */