og-8.x-1.x-dev/tests/src/Kernel/EntityReference/OgSelectionConfigurationFormTest.php

tests/src/Kernel/EntityReference/OgSelectionConfigurationFormTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\og\Kernel\EntityReference;

use Drupal\Core\Form\FormState;
use Drupal\entity_test\Entity\EntityTestBundle;
use Drupal\field\Entity\FieldConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\og\Og;
use Drupal\og\OgGroupAudienceHelperInterface;

/**
 * Tests the field settings configuration form for the OG audience field.
 *
 * @group og
 * @coversDefaultClass \Drupal\og\Plugin\EntityReferenceSelection\OgSelection
 */
class OgSelectionConfigurationFormTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'field',
    'field_ui',
    'entity_test',
    'og',
    'options',
    'system',
    'user',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    // Add membership and config schema.
    $this->installEntitySchema('user');
    $this->installEntitySchema('entity_test_with_bundle');
    $this->installEntitySchema('og_membership');
    $this->installSchema('system', 'sequences');

    EntityTestBundle::create([
      'id' => 'non_group',
      'label' => 'non_group',
    ])->save();

    EntityTestBundle::create([
      'id' => 'group_type1',
      'label' => 'group_type1',
    ])->save();

    EntityTestBundle::create([
      'id' => 'group_type2',
      'label' => 'group_type2',
    ])->save();

    EntityTestBundle::create([
      'id' => 'group_content',
      'label' => 'group_content',
    ])->save();

    Og::addGroup('entity_test_with_bundle', 'group_type1');
    Og::addGroup('entity_test_with_bundle', 'group_type2');

    $settings = [
      'field_storage_config' => [
        'settings' => [
          'target_type' => 'entity_test_with_bundle',
        ],
      ],
    ];
    Og::createField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'entity_test_with_bundle', 'group_content', $settings);
  }

  /**
   * Test if a group that uses a string as ID can be referenced.
   *
   * @covers ::buildConfigurationForm
   */
  public function testConfigurationForm(): void {
    $form_object = \Drupal::entityTypeManager()->getFormObject('field_config', 'edit');

    $entity = FieldConfig::loadByName('entity_test_with_bundle', 'group_content', OgGroupAudienceHelperInterface::DEFAULT_FIELD);
    $form_object->setEntity($entity);

    $form_state = new FormState();

    $form = \Drupal::formBuilder()->buildForm($form_object, $form_state);

    $options = array_keys($form['settings']['handler']['handler_settings']['target_bundles']['#options']);
    sort($options);

    $this->assertEquals(['group_type1', 'group_type2'], $options);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc