You are here

class MachineNameTest in Drupal 10

Same name in this branch
  1. 10 core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php \Drupal\FunctionalJavascriptTests\Core\MachineNameTest
  2. 10 core/tests/Drupal/Tests/Core/Render/Element/MachineNameTest.php \Drupal\Tests\Core\Render\Element\MachineNameTest
  3. 10 core/tests/Drupal/KernelTests/Core/Render/Element/MachineNameTest.php \Drupal\KernelTests\Core\Render\Element\MachineNameTest
  4. 10 core/modules/migrate/tests/src/Unit/process/MachineNameTest.php \Drupal\Tests\migrate\Unit\process\MachineNameTest

@coversDefaultClass \Drupal\Core\Render\Element\MachineName @group Render

Hierarchy

  • class \Drupal\KernelTests\Core\Render\Element\MachineNameTest extends \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\Form\FormInterface

Expanded class hierarchy of MachineNameTest

File

core/tests/Drupal/KernelTests/Core/Render/Element/MachineNameTest.php, line 13

Namespace

Drupal\KernelTests\Core\Render\Element
View source
class MachineNameTest extends KernelTestBase implements FormInterface {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
  ];

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return __CLASS__;
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $element = [
      '#id' => 'test',
      '#type' => 'machine_name',
      '#machine_name' => [
        'source' => [
          'test_source',
        ],
      ],
      '#name' => 'test_machine_name',
      '#default_value' => NULL,
    ];
    $complete_form = [
      'test_machine_name' => $element,
      'test_source' => [
        '#type' => 'textfield',
      ],
    ];
    return $complete_form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * Tests the order of the machine name field and the source.
   */
  public function testMachineNameOrderException() {
    $this
      ->expectException(\LogicException::class);
    $this
      ->expectErrorMessage('The machine name element "test_machine_name" is defined before the source element "test_source", it must be defined after or the source element must specify an id.');
    $form = \Drupal::formBuilder()
      ->getForm($this);
    $this
      ->render($form);
  }

}

Members