Skip to content
Snippets Groups Projects
Commit 5479d723 authored by JohnCullen's avatar JohnCullen
Browse files

#3384913 created PhpUnit Functional test methods to check that all routes are...

#3384913 created PhpUnit Functional test methods to check that all routes are returning a http 200 response when logged in
parent 452c78f3
No related branches found
No related tags found
No related merge requests found
...@@ -59,22 +59,33 @@ class SupportTicketTypeForm extends EntityForm { ...@@ -59,22 +59,33 @@ class SupportTicketTypeForm extends EntityForm {
* {@inheritdoc} * {@inheritdoc}
* *
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/ */
public function form(array $form, FormStateInterface $form_state): array { public function form(array $form, FormStateInterface $form_state): array {
$form = parent::form($form, $form_state); $form = parent::form($form, $form_state);
$type = $this->entity;
if ($this->operation == 'add') { if ($this->operation == 'add') {
$form['#title'] = $this->t('Add support ticket type'); $form['#title'] = $this->t('Add support ticket type');
$fields = $this->entityFieldManager $fields = $this->entityFieldManager
->getBaseFieldDefinitions('support_ticket'); ->getBaseFieldDefinitions('support_ticket');
// Create a support ticket with a fake bundle using the type's
// UUID so that we can get the default values for workflow settings.
$support_ticket = $this->entityManager
->getStorage('support_ticket')
->create(['support_ticket_type' => $type->uuid()]);
} }
else { else {
$form['#title'] = $this->t('Edit %label support ticket type', ['%label' => $this->entity->label()]); $form['#title'] = $this->t('Edit %label support ticket type', ['%label' => $this->entity->label()]);
$fields = $this->entityFieldManager $fields = $this->entityFieldManager
->getFieldDefinitions('support_ticket', $this->entity->id()); ->getFieldDefinitions('support_ticket', $this->entity->id());
// Create a support_ticket to get the current values
// for workflow settings fields.
$support_ticket = $this->entityManager
->getStorage('support_ticket')
->create(['support_ticket_type' => $type->id()]);
} }
// @todo how to refer to this page?
$form['name'] = [ $form['name'] = [
'#title' => $this->t('Name'), '#title' => $this->t('Name'),
'#type' => 'textfield', '#type' => 'textfield',
...@@ -143,7 +154,7 @@ class SupportTicketTypeForm extends EntityForm { ...@@ -143,7 +154,7 @@ class SupportTicketTypeForm extends EntityForm {
$form['submission']['help'] = [ $form['submission']['help'] = [
'#type' => 'textarea', '#type' => 'textarea',
'#title' => $this->t('Explanation or submission guidelines'), '#title' => $this->t('Explanation or submission guidelines'),
'#default_value' => '',//$this->entity->getHelp(), '#default_value' => '', //$this->entity->getHelp(),
'#description' => $this->t('This text will be displayed at the top of the page when creating or editing support tickets of this type.'), '#description' => $this->t('This text will be displayed at the top of the page when creating or editing support tickets of this type.'),
]; ];
...@@ -154,8 +165,8 @@ class SupportTicketTypeForm extends EntityForm { ...@@ -154,8 +165,8 @@ class SupportTicketTypeForm extends EntityForm {
]; ];
$workflow_options = [ $workflow_options = [
'status' => $support_ticket->status->value, 'status' => $support_ticket->isPublished(),
'locked' => $support_ticket->locked->value, 'locked' => $support_ticket->isLocked(),
'revision' => $this->entity->isNewRevision(), 'revision' => $this->entity->isNewRevision(),
]; ];
......
<?php <?php
namespace Drupal\support_ticket\Tests; namespace Drupal\support_ticket\Tests\SupportTicket;
use Drupal\Tests\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
...@@ -12,7 +12,7 @@ use Drupal\Tests\BrowserTestBase; ...@@ -12,7 +12,7 @@ use Drupal\Tests\BrowserTestBase;
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class SupportTicketRoutesTests extends BrowserTestBase { class Http200ResponseRouteTests extends BrowserTestBase {
/** /**
* Modules to enable. * Modules to enable.
......
<?php <?php
namespace Drupal\support_ticket\Tests; namespace Drupal\support_ticket\Tests\SupportTicketType;
use Drupal\Tests\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
...@@ -12,7 +11,7 @@ use Drupal\Tests\BrowserTestBase; ...@@ -12,7 +11,7 @@ use Drupal\Tests\BrowserTestBase;
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class SupportTicketTypeRoutesTests extends BrowserTestBase { class Http200ResponseRouteTests extends BrowserTestBase {
/** /**
* Modules to enable. * Modules to enable.
...@@ -50,10 +49,10 @@ class SupportTicketTypeRoutesTests extends BrowserTestBase { ...@@ -50,10 +49,10 @@ class SupportTicketTypeRoutesTests extends BrowserTestBase {
* Testing support_ticket.type_add. * Testing support_ticket.type_add.
*/ */
public function testSupportTicketTypeAddFunctionality() { public function testSupportTicketTypeAddFunctionality() {
//$admin_user = $this->drupalCreateUser(['administer support ticket types']); $admin_user = $this->drupalCreateUser(['administer support ticket types']);
//$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
//$this->drupalGet('/admin/structure/support_ticket/ticket-types/add'); $this->drupalGet('/admin/structure/support_ticket/ticket-types/add');
//$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
} }
/** /**
......
#!/bin/bash
##
# This script does a code check on the module to
# ensure that code meets Drupal security standards.
##
echo 'Checks code'
##
# Access test code.
##
CURRENT_DIR=${PWD};
cd $CURRENT_DIR"/../"
if [ -z "$1" ]
then
CLASS_TYPE='*';
else
CLASS_TYPE=$1;
fi
phpcs \
--standard=Drupal,DrupalPractice \
--extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml $CLASS_TYPE
##
# Returns to script directory
##
cd $CURRENT_DIR;
echo "";
echo "Returned to script directory: "${PWD};
...@@ -28,8 +28,8 @@ echo ""; ...@@ -28,8 +28,8 @@ echo "";
# Run support module tests. # Run support module tests.
## ##
../../vendor/bin/phpunit ../modules/custom/support/tests/src/Functional/SupportInstallationTests.php ../../vendor/bin/phpunit ../modules/custom/support/tests/src/Functional/SupportInstallationTests.php
../../vendor/bin/phpunit ../modules/custom/support/modules/support_ticket/tests/src/Functional/SupportTicketRoutesTests.php ../../vendor/bin/phpunit ../modules/custom/support/modules/support_ticket/tests/src/Functional/SupportTicket/Http200ResponseRouteTests.php
../../vendor/bin/phpunit ../modules/custom/support/modules/support_ticket/tests/src/Functional/SupportTicketTypeRoutesTests.php ../../vendor/bin/phpunit ../modules/custom/support/modules/support_ticket/tests/src/Functional/SupportTicketType/Http200ResponseRouteTests.php
## ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment