diff --git a/modules/core/quick/tests/modules/farm_quick_test/config/install/log.type.test.yml b/modules/core/quick/tests/modules/farm_quick_test/config/install/log.type.test.yml new file mode 100644 index 00000000..d88475de --- /dev/null +++ b/modules/core/quick/tests/modules/farm_quick_test/config/install/log.type.test.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +id: test +label: Test +description: '' +name_pattern: 'Test log [log:id]' +workflow: log_default +new_revision: true diff --git a/modules/core/quick/tests/modules/farm_quick_test/farm_quick_test.info.yml b/modules/core/quick/tests/modules/farm_quick_test/farm_quick_test.info.yml new file mode 100644 index 00000000..86a66e90 --- /dev/null +++ b/modules/core/quick/tests/modules/farm_quick_test/farm_quick_test.info.yml @@ -0,0 +1,8 @@ +name: farmOS quick form tests +type: module +description: Support module for farmOS quick form testing. +package: Testing +core_version_requirement: ^8.8 || ^9 +dependencies: + - farm:farm_quick + - log:log diff --git a/modules/core/quick/tests/modules/farm_quick_test/src/QuickForm/Test.php b/modules/core/quick/tests/modules/farm_quick_test/src/QuickForm/Test.php new file mode 100644 index 00000000..bf3d50ee --- /dev/null +++ b/modules/core/quick/tests/modules/farm_quick_test/src/QuickForm/Test.php @@ -0,0 +1,44 @@ + 'number', + '#title' => $this->t('Test field'), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + + } + +} diff --git a/modules/core/quick/tests/src/Functional/QuickFormTest.php b/modules/core/quick/tests/src/Functional/QuickFormTest.php new file mode 100644 index 00000000..a913d14b --- /dev/null +++ b/modules/core/quick/tests/src/Functional/QuickFormTest.php @@ -0,0 +1,64 @@ +createUser(); + $this->drupalLogin($user); + + // Go to the quick form index and confirm that access is denied. + $this->drupalGet('quick'); + $this->assertSession()->statusCodeEquals(403); + + // Create and login a test user with access to the quick form index. + $user = $this->createUser(['view quick forms index']); + $this->drupalLogin($user); + + // Go to the quick form index and confirm that access is granted, but no + // quick forms are visible. + $this->drupalGet('quick'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains($this->t('You do not have any quick forms.')); + + // Create and login a test user with access to the quick form index, and + // permission to create test logs. + $user = $this->createUser(['view quick forms index', 'create test log']); + $this->drupalLogin($user); + + // Go to the quick form index and confirm that access is granted, and the + // test quick form item is visible. + $this->drupalGet('quick'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains($this->t('Test quick form')); + + // Go to the test quick form and confirm that the test field is visible. + $this->drupalGet('quick/test'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains($this->t('Test field')); + } + +} diff --git a/modules/core/quick/tests/src/Kernel/QuickFormTest.php b/modules/core/quick/tests/src/Kernel/QuickFormTest.php new file mode 100644 index 00000000..a26b5f74 --- /dev/null +++ b/modules/core/quick/tests/src/Kernel/QuickFormTest.php @@ -0,0 +1,67 @@ +quickFormManager = \Drupal::service('plugin.manager.quick_form'); + $this->installEntitySchema('log'); + $this->installEntitySchema('user'); + $this->installConfig([ + 'farm_quick_test', + ]); + } + + /** + * Test quick form discovery. + */ + public function testQuickFormDiscovery() { + + // Load quick form definitions. + $quick_forms = $this->quickFormManager->getDefinitions(); + + // Confirm that one quick form was discovered. + $this->assertEquals(1, count($quick_forms)); + + // Initialize the test quick form. + /** @var \Drupal\farm_quick\QuickFormInterface $test_quick_form */ + $test_quick_form = $this->quickFormManager->createInstance('test'); + + // Confirm the label, description, helpText, and permissions. + $this->assertEquals('Test quick form', $test_quick_form->getLabel()); + $this->assertEquals('Test quick form description.', $test_quick_form->getDescription()); + $this->assertEquals('Test quick form help text.', $test_quick_form->getHelpText()); + $this->assertEquals(['create test log'], $test_quick_form->getPermissions()); + } + +}