You are here

class VueFormTest in Decoupled Blocks: Vue.js 8

@coversDefaultClass \Drupal\pdb_vue\Form\VueForm @group pdb_vue

Hierarchy

Expanded class hierarchy of VueFormTest

File

tests/src/Unit/Form/VueFormTest.php, line 13

Namespace

Drupal\Tests\pdb_vue\Unit\Form
View source
class VueFormTest extends UnitTestCase {

  /**
   * The mocked config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $configFactory;

  /**
   * Form State stub.
   *
   * @var \Drupal\Core\Form\FormStateInterface
   */
  protected $formState;

  /**
   * Form instance.
   *
   * @var \Drupal\pdb_vue\Form\VueForm
   */
  protected $form;

  /**
   * Create the setup for constants and configFactory stub.
   */
  protected function setUp() {
    parent::setUp();

    // Stub the Config Factory.
    $this->configFactory = $this
      ->getConfigFactoryStub([
      'pdb_vue.settings' => [
        'version' => 'vue2',
        'development_mode' => 0,
        'use_spa' => 0,
        'spa_element' => '#element',
      ],
    ]);

    // Mock the formState.
    $this->formState = $this
      ->createMock(FormStateInterface::CLASS);
    $this->form = new VueForm($this->configFactory);

    // Create a translation stub for the t() method.
    $translator = $this
      ->getStringTranslationStub();
    $this->form
      ->setStringTranslation($translator);
  }

  /**
   * Tests the getFormId() method.
   */
  public function testGetFormId() {
    $expected = 'pdb_vue_form';
    $return = $this->form
      ->getFormId();
    $this
      ->assertEquals($expected, $return);
  }

  /**
   * Tests the buildForm() method.
   */
  public function testBuildForm() {
    $form = [];
    $result = $this->form
      ->buildForm($form, $this->formState);
    $this
      ->assertEquals('system_config_form', $result['#theme']);
    $this
      ->assertEquals('vue2', $result['version']['#default_value']);
    $this
      ->assertEquals('0', $result['development_mode']['#default_value']);
    $this
      ->assertEquals('0', $result['use_spa']['#default_value']);
    $this
      ->assertEquals('#element', $result['spa_element']['#default_value']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
VueFormTest::$configFactory protected property The mocked config factory.
VueFormTest::$form protected property Form instance.
VueFormTest::$formState protected property Form State stub.
VueFormTest::setUp protected function Create the setup for constants and configFactory stub. Overrides UnitTestCase::setUp
VueFormTest::testBuildForm public function Tests the buildForm() method.
VueFormTest::testGetFormId public function Tests the getFormId() method.