Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -57,7 +57,7 @@ abstract class BlockContentTestBase extends BrowserTestBase { ...@@ -57,7 +57,7 @@ abstract class BlockContentTestBase extends BrowserTestBase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
if ($this->autoCreateBasicBlockType) { if ($this->autoCreateBasicBlockType) {
$this->createBlockContentType('basic', TRUE); $this->createBlockContentType(['id' => 'basic'], TRUE);
} }
$this->adminUser = $this->drupalCreateUser($this->permissions); $this->adminUser = $this->drupalCreateUser($this->permissions);
...@@ -95,9 +95,11 @@ protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = ...@@ -95,9 +95,11 @@ protected function createBlockContent($title = FALSE, $bundle = 'basic', $save =
* Creates a block type (bundle). * Creates a block type (bundle).
* *
* @param array|string $values * @param array|string $values
* The value to create the block content type. If $values is an array * (deprecated) The variable $values as string is deprecated. Provide as an
* it should be like: ['id' => 'foo', 'label' => 'Foo']. If $values * array as parameter. The value to create the block content type. If
* is a string, it will be considered that it represents the label. * $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 * @param bool $create_body
* Whether or not to create the body field * Whether or not to create the body field
* *
...@@ -105,6 +107,9 @@ protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = ...@@ -105,6 +107,9 @@ protected function createBlockContent($title = FALSE, $bundle = 'basic', $save =
* Created block type. * Created block type.
*/ */
protected function createBlockContentType($values, $create_body = FALSE) { 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 (is_array($values)) {
if (!isset($values['id'])) { if (!isset($values['id'])) {
do { do {
......
...@@ -102,11 +102,11 @@ public function testBlockContentTypeCreation(): void { ...@@ -102,11 +102,11 @@ public function testBlockContentTypeCreation(): void {
$this->assertEquals($block_type->language()->getId(), $default_langcode); $this->assertEquals($block_type->language()->getId(), $default_langcode);
// Create block types programmatically. // Create block types programmatically.
$this->createBlockContentType('basic', TRUE); $this->createBlockContentType(['id' => 'basic'], TRUE);
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('block_content', 'basic'); $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->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'); $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."); $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 { ...@@ -123,11 +123,11 @@ public function testBlockContentTypeCreation(): void {
public function testBlockContentTypeEditing(): void { public function testBlockContentTypeEditing(): void {
$this->drupalPlaceBlock('system_breadcrumb_block'); $this->drupalPlaceBlock('system_breadcrumb_block');
// Now create an initial block-type. // Now create an initial block-type.
$this->createBlockContentType('basic', TRUE); $this->createBlockContentType(['id' => 'basic'], TRUE);
$this->drupalLogin($this->adminUser); $this->drupalLogin($this->adminUser);
// We need two block types to prevent /block/add redirecting. // 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'); $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.'); $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 { ...@@ -174,10 +174,10 @@ public function testBlockContentTypeEditing(): void {
*/ */
public function testBlockContentTypeDeletion(): void { public function testBlockContentTypeDeletion(): void {
// Now create an initial block-type. // Now create an initial block-type.
$this->createBlockContentType('basic', TRUE); $this->createBlockContentType(['id' => 'basic'], TRUE);
// Create a block type programmatically. // Create a block type programmatically.
$type = $this->createBlockContentType('foo'); $type = $this->createBlockContentType(['id' => 'foo']);
$this->drupalLogin($this->adminUser); $this->drupalLogin($this->adminUser);
...@@ -201,12 +201,12 @@ public function testBlockContentTypeDeletion(): void { ...@@ -201,12 +201,12 @@ public function testBlockContentTypeDeletion(): void {
*/ */
public function testsBlockContentAddTypes(): void { public function testsBlockContentAddTypes(): void {
// Now create an initial block-type. // Now create an initial block-type.
$this->createBlockContentType('basic', TRUE); $this->createBlockContentType(['id' => 'basic'], TRUE);
$this->drupalLogin($this->adminUser); $this->drupalLogin($this->adminUser);
// Create two block types programmatically. // Create two block types programmatically.
$this->createBlockContentType('foo'); $this->createBlockContentType(['id' => 'foo']);
$this->createBlockContentType('bar'); $this->createBlockContentType(['id' => 'bar']);
// Get the content block storage. // Get the content block storage.
$storage = $this->container $storage = $this->container
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment