VueFormTest.php in Decoupled Blocks: Vue.js 8
File
tests/src/Unit/Form/VueFormTest.php
View source
<?php
namespace Drupal\Tests\pdb_vue\Unit\Form;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\pdb_vue\Form\VueForm;
class VueFormTest extends UnitTestCase {
protected $configFactory;
protected $formState;
protected $form;
protected function setUp() {
parent::setUp();
$this->configFactory = $this
->getConfigFactoryStub([
'pdb_vue.settings' => [
'version' => 'vue2',
'development_mode' => 0,
'use_spa' => 0,
'spa_element' => '#element',
],
]);
$this->formState = $this
->createMock(FormStateInterface::CLASS);
$this->form = new VueForm($this->configFactory);
$translator = $this
->getStringTranslationStub();
$this->form
->setStringTranslation($translator);
}
public function testGetFormId() {
$expected = 'pdb_vue_form';
$return = $this->form
->getFormId();
$this
->assertEquals($expected, $return);
}
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']);
}
}