Verified Commit f296e346 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3196937 by quietone, ayushmishra206, paulocs, guilhermevp, alexpott:...

Issue #3196937 by quietone, ayushmishra206, paulocs, guilhermevp, alexpott: Deprecate the string code path for values parameter in BlockContentTestBase::createBlockContentType
parent 1c67d3b5
Loading
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ abstract class BlockContentTestBase extends BrowserTestBase {
  protected function setUp(): void {
    parent::setUp();
    if ($this->autoCreateBasicBlockType) {
      $this->createBlockContentType('basic', TRUE);
      $this->createBlockContentType(['id' => 'basic'], TRUE);
    }

    $this->adminUser = $this->drupalCreateUser($this->permissions);
@@ -95,9 +95,11 @@ protected function createBlockContent($title = FALSE, $bundle = 'basic', $save =
   * Creates a block type (bundle).
   *
   * @param array|string $values
   *   The value to create the block content type. If $values is an array
   *   it should be like: ['id' => 'foo', 'label' => 'Foo']. If $values
   *   is a string, it will be considered that it represents the label.
   *   (deprecated) The variable $values as string is deprecated. Provide as an
   *   array as parameter. The value to create the block content type. If
   *   $values is an array it should be like: ['id' => 'foo', 'label' => 'Foo'].
   *   If $values is a string, it will be considered that it represents the
   *   label.
   * @param bool $create_body
   *   Whether or not to create the body field
   *
@@ -105,6 +107,9 @@ protected function createBlockContent($title = FALSE, $bundle = 'basic', $save =
   *   Created block type.
   */
  protected function createBlockContentType($values, $create_body = FALSE) {
    if (is_string($values)) {
      @trigger_error('Using the variable $values as string is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. Provide an array as parameter. See https://www.drupal.org/node/3473739', E_USER_DEPRECATED);
    }
    if (is_array($values)) {
      if (!isset($values['id'])) {
        do {
+9 −9
Original line number Diff line number Diff line
@@ -102,11 +102,11 @@ public function testBlockContentTypeCreation(): void {
    $this->assertEquals($block_type->language()->getId(), $default_langcode);

    // Create block types programmatically.
    $this->createBlockContentType('basic', TRUE);
    $this->createBlockContentType(['id' => 'basic'], TRUE);
    $field_definitions = \Drupal::service('entity_field.manager')->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');
    $this->createBlockContentType(['id' => 'other']);
    $field_definitions = \Drupal::service('entity_field.manager')->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.");

@@ -123,11 +123,11 @@ public function testBlockContentTypeCreation(): void {
  public function testBlockContentTypeEditing(): void {
    $this->drupalPlaceBlock('system_breadcrumb_block');
    // Now create an initial block-type.
    $this->createBlockContentType('basic', TRUE);
    $this->createBlockContentType(['id' => 'basic'], TRUE);

    $this->drupalLogin($this->adminUser);
    // We need two block types to prevent /block/add redirecting.
    $this->createBlockContentType('other');
    $this->createBlockContentType(['id' => 'other']);

    $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('block_content', 'other');
    $this->assertFalse(isset($field_definitions['body']), 'Body field was not created when using the API to create block content types.');
@@ -174,10 +174,10 @@ public function testBlockContentTypeEditing(): void {
   */
  public function testBlockContentTypeDeletion(): void {
    // Now create an initial block-type.
    $this->createBlockContentType('basic', TRUE);
    $this->createBlockContentType(['id' => 'basic'], TRUE);

    // Create a block type programmatically.
    $type = $this->createBlockContentType('foo');
    $type = $this->createBlockContentType(['id' => 'foo']);

    $this->drupalLogin($this->adminUser);

@@ -201,12 +201,12 @@ public function testBlockContentTypeDeletion(): void {
   */
  public function testsBlockContentAddTypes(): void {
    // Now create an initial block-type.
    $this->createBlockContentType('basic', TRUE);
    $this->createBlockContentType(['id' => 'basic'], TRUE);

    $this->drupalLogin($this->adminUser);
    // Create two block types programmatically.
    $this->createBlockContentType('foo');
    $this->createBlockContentType('bar');
    $this->createBlockContentType(['id' => 'foo']);
    $this->createBlockContentType(['id' => 'bar']);

    // Get the content block storage.
    $storage = $this->container