class VueFormTest in Decoupled Blocks: Vue.js 8
@coversDefaultClass \Drupal\pdb_vue\Form\VueForm @group pdb_vue
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\pdb_vue\Unit\Form\VueFormTest
Expanded class hierarchy of VueFormTest
File
- tests/
src/ Unit/ Form/ VueFormTest.php, line 13
Namespace
Drupal\Tests\pdb_vue\Unit\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
VueFormTest:: |
protected | property | The mocked config factory. | |
VueFormTest:: |
protected | property | Form instance. | |
VueFormTest:: |
protected | property | Form State stub. | |
VueFormTest:: |
protected | function |
Create the setup for constants and configFactory stub. Overrides UnitTestCase:: |
|
VueFormTest:: |
public | function | Tests the buildForm() method. | |
VueFormTest:: |
public | function | Tests the getFormId() method. |