Skip to content
Snippets Groups Projects
Commit 41ae6b5e authored by JohnCullen's avatar JohnCullen
Browse files

#3384913 Moved old tests ready for review.

parent 766a47a3
Branches
No related tags found
No related merge requests found
Pipeline #21399 failed
Showing
with 0 additions and 142 deletions
name: 'Support ticket tests'
type: module
description: 'Support module for support_ticket related testing.'
package: Testing
core_version_requirement: ^9 || ^10
<?php
/**
* @file
* A dummy module for testing support_ticket related hooks.
*
* This is a dummy module that implements support_ticket related hooks to
* test API interaction with the Support ticket module.
*/
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\support_ticket\SupportTicketInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_ENTITY_TYPE_view() for support_ticket entities.
*/
function support_ticket_test_support_ticket_view(array &$build, SupportTicketInterface $support_ticket, EntityViewDisplayInterface $display, $view_mode) {
if ($view_mode == 'rss') {
// Add RSS elements and namespaces when building the RSS feed.
$support_ticket->rss_elements[] = [
'key' => 'testElement',
'value' => t('Value of testElement RSS element for support_ticket @id.', ['@id' => $support_ticket->id()]),
];
// Add content that should be displayed only in the RSS feed.
$build['extra_feed_content'] = [
'#markup' => '<p>' . t('Extra data that should appear only in the RSS feed for support_ticket @id.', ['@id' => $support_ticket->id()]) . '</p>',
'#weight' => 10,
];
}
if ($view_mode != 'rss') {
// Add content that should NOT be displayed in the RSS feed.
$build['extra_non_feed_content'] = [
'#markup' => '<p>' . t('Extra data that should appear everywhere except the RSS feed for support_ticket @id.', ['@id' => $support_ticket->id()]) . '</p>',
];
}
}
/**
* Implements hook_ENTITY_TYPE_build_defaults_alter() for support_ticket entities.
*/
function support_ticket_test_support_ticket_build_defaults_alter(array &$build, SupportTicketInterface &$support_ticket, $view_mode = 'full', $langcode = NULL) {
if ($view_mode == 'rss') {
$support_ticket->rss_namespaces['xmlns:drupaltest'] = 'http://example.com/test-namespace';
}
}
/**
* Implements hook_ENTITY_TYPE_presave() for support_ticket entities.
*/
function support_ticket_test_support_ticket_presave(SupportTicketInterface $support_ticket) {
if ($support_ticket->getTitle() == 'testing_support_ticket_presave') {
// Sun, 19 Nov 1978 05:00:00 GMT.
$support_ticket->setCreatedTime(280299600);
// Drupal 1.0 release.
$support_ticket->changed = 979534800;
}
// Determine changes.
if (!empty($support_ticket->original) && $support_ticket->original->getTitle() == 'test_changes') {
if ($support_ticket->original->getTitle() != $support_ticket->getTitle()) {
$support_ticket->title->value .= '_presave';
}
}
}
/**
* Implements hook_ENTITY_TYPE_update() for support_ticket entities.
*/
function support_ticket_test_support_ticket_update(SupportTicketInterface $support_ticket) {
// Determine changes on update.
if (!empty($support_ticket->original) && $support_ticket->original->getTitle() == 'test_changes') {
if ($support_ticket->original->getTitle() != $support_ticket->getTitle()) {
$support_ticket->title->value .= '_update';
}
}
}
/**
* Implements hook_entity_view_mode_alter().
*/
function support_ticket_test_entity_view_mode_alter(&$view_mode, EntityInterface $entity, $context) {
// Only alter the view mode if we are on the test callback.
$change_view_mode = \Drupal::state()->get('support_ticket_test_change_view_mode') ?: '';
if ($change_view_mode) {
$view_mode = $change_view_mode;
}
}
/**
* Implements hook_ENTITY_TYPE_insert() for support_ticket entities.
*
* This tests saving a support_ticket on support_ticket insert.
*
* @see \Drupal\support_ticket\Tests\SupportTicketSaveTest::testSupportTicketSaveOnInsert()
*/
function support_ticket_test_support_ticket_insert(SupportTicketInterface $support_ticket) {
// Set the support_ticket title to the support_ticket ID and save.
if ($support_ticket->getTitle() == "new") {
$support_ticket->setTitle("Support ticket " . $support_ticket->id());
$support_ticket->setNewRevision(FALSE);
$support_ticket->save();
}
}
/**
* Compensate for missing Classy classes when testing.
*/
function support_ticket_test_preprocess_field(&$variables) {
// Add additional targeting for tests.
if ($variables['entity_type'] == 'support_ticket' && $variables['field_name'] == 'title') {
$variables['attributes']['class'][] = 'field--name-title';
}
}
name: 'Support ticket exception tests'
type: module
description: 'Support module for support ticket related exception testing.'
package: Testing
core_version_requirement: ^9 || ^10
<?php
/**
* @file
* A module implementing support ticket related hooks to test API interaction.
*/
use Drupal\support_ticket\SupportTicketInterface;
/**
* Implements hook_ENTITY_TYPE_insert() for support_ticket entities.
*/
function support_ticket_test_exception_support_ticket_insert(SupportTicketInterface $support_ticket) {
if ($support_ticket->getTitle() == 'testing_transaction_exception') {
throw new Exception('Test exception for rollback.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment