Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\contact\Plugin\rest\resource\ContactMessageResource;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
|
@ -235,3 +236,10 @@ function contact_form_user_admin_settings_submit($form, FormStateInterface $form
|
|||
->set('user_default_enabled', $form_state->getValue('contact_default_status'))
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_rest_resource_alter().
|
||||
*/
|
||||
function contact_rest_resource_alter(&$definitions) {
|
||||
$definitions['entity:contact_message']['class'] = ContactMessageResource::class;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
use Drupal\contact\Entity\ContactForm;
|
||||
|
||||
|
||||
/**
|
||||
* Initialize 'message' and 'redirect' field values to 'contact_form' entities.
|
||||
*/
|
||||
|
|
|
@ -3,6 +3,7 @@ label: Contact category configuration
|
|||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: contact_category
|
||||
process:
|
|
@ -2,6 +2,7 @@ id: d6_contact_settings
|
|||
label: Contact configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: contact_settings
|
||||
variables:
|
|
@ -2,6 +2,7 @@ id: d7_contact_settings
|
|||
label: Contact configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: contact_settings
|
||||
variables:
|
|
@ -24,7 +24,7 @@ class ContactPageAccess implements AccessInterface {
|
|||
/**
|
||||
* The user data service.
|
||||
*
|
||||
* @var \Drupal\user\UserDataInterface;
|
||||
* @var \Drupal\user\UserDataInterface
|
||||
*/
|
||||
protected $userData;
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@ class ContactFormAccessControlHandler extends EntityAccessControlHandler {
|
|||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
if ($operation == 'view') {
|
||||
// Do not allow access personal form via site-wide route.
|
||||
return AccessResult::allowedIf($account->hasPermission('access site-wide contact form') && $entity->id() !== 'personal')->cachePerPermissions();
|
||||
return AccessResult::allowedIfHasPermission($account, 'access site-wide contact form')->andIf(AccessResult::allowedIf($entity->id() !== 'personal'));
|
||||
}
|
||||
elseif ($operation == 'delete' || $operation == 'update') {
|
||||
// Do not allow the 'personal' form to be deleted, as it's used for
|
||||
// the personal contact form.
|
||||
return AccessResult::allowedIf($account->hasPermission('administer contact forms') && $entity->id() !== 'personal')->cachePerPermissions();
|
||||
return AccessResult::allowedIfHasPermission($account, 'administer contact forms')->andIf(AccessResult::allowedIf($entity->id() !== 'personal'));
|
||||
}
|
||||
|
||||
return parent::checkAccess($entity, $operation, $account);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\contact;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
|
@ -15,6 +14,8 @@ use Drupal\Core\Render\Element\PathElement;
|
|||
|
||||
/**
|
||||
* Base form for contact form edit forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ContactFormEditForm extends EntityForm implements ContainerInjectionInterface {
|
||||
use ConfigFormBaseTrait;
|
||||
|
@ -148,7 +149,7 @@ class ContactFormEditForm extends EntityForm implements ContainerInjectionInterf
|
|||
$form_state->setValue('recipients', $recipients);
|
||||
$redirect_url = $form_state->getValue('redirect');
|
||||
if ($redirect_url && $this->pathValidator->isValid($redirect_url)) {
|
||||
if (Unicode::substr($redirect_url, 0, 1) !== '/') {
|
||||
if (mb_substr($redirect_url, 0, 1) !== '/') {
|
||||
$form_state->setErrorByName('redirect', $this->t('The path should start with /.'));
|
||||
}
|
||||
}
|
||||
|
@ -165,11 +166,11 @@ class ContactFormEditForm extends EntityForm implements ContainerInjectionInterf
|
|||
$edit_link = $this->entity->link($this->t('Edit'));
|
||||
$view_link = $contact_form->link($contact_form->label(), 'canonical');
|
||||
if ($status == SAVED_UPDATED) {
|
||||
drupal_set_message($this->t('Contact form %label has been updated.', ['%label' => $view_link]));
|
||||
$this->messenger()->addStatus($this->t('Contact form %label has been updated.', ['%label' => $view_link]));
|
||||
$this->logger('contact')->notice('Contact form %label has been updated.', ['%label' => $contact_form->label(), 'link' => $edit_link]);
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('Contact form %label has been added.', ['%label' => $view_link]));
|
||||
$this->messenger()->addStatus($this->t('Contact form %label has been added.', ['%label' => $view_link]));
|
||||
$this->logger('contact')->notice('Contact form %label has been added.', ['%label' => $contact_form->label(), 'link' => $edit_link]);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,8 @@ class ContactController extends ControllerBase {
|
|||
* The contact form to use.
|
||||
*
|
||||
* @return array
|
||||
* The form as render array as expected by drupal_render().
|
||||
* The form as render array as expected by
|
||||
* \Drupal\Core\Render\RendererInterface::render().
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
* Exception is thrown when user tries to access non existing default
|
||||
|
@ -64,8 +65,9 @@ class ContactController extends ControllerBase {
|
|||
// If there are no forms, do not display the form.
|
||||
if (empty($contact_form)) {
|
||||
if ($this->currentUser()->hasPermission('administer contact forms')) {
|
||||
drupal_set_message($this->t('The contact form has not been configured. <a href=":add">Add one or more forms</a> .', [
|
||||
':add' => $this->url('contact.form_add')]), 'error');
|
||||
$this->messenger()->addError($this->t('The contact form has not been configured. <a href=":add">Add one or more forms</a> .', [
|
||||
':add' => $this->url('contact.form_add'),
|
||||
]));
|
||||
return [];
|
||||
}
|
||||
else {
|
||||
|
@ -94,7 +96,8 @@ class ContactController extends ControllerBase {
|
|||
* The account for which a personal contact form should be generated.
|
||||
*
|
||||
* @return array
|
||||
* The personal contact form as render array as expected by drupal_render().
|
||||
* The personal contact form as render array as expected by
|
||||
* \Drupal\Core\Render\RendererInterface::render().
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
* Exception is thrown when user tries to access a contact form for a
|
||||
|
|
|
@ -12,6 +12,13 @@ use Drupal\Core\Url;
|
|||
* @ConfigEntityType(
|
||||
* id = "contact_form",
|
||||
* label = @Translation("Contact form"),
|
||||
* label_collection = @Translation("Contact forms"),
|
||||
* label_singular = @Translation("contact form"),
|
||||
* label_plural = @Translation("contact forms"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count contact form",
|
||||
* plural = "@count contact forms",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "access" = "Drupal\contact\ContactFormAccessControlHandler",
|
||||
* "list_builder" = "Drupal\contact\ContactFormListBuilder",
|
||||
|
|
|
@ -13,6 +13,14 @@ use Drupal\Core\Field\BaseFieldDefinition;
|
|||
* @ContentEntityType(
|
||||
* id = "contact_message",
|
||||
* label = @Translation("Contact message"),
|
||||
* label_collection = @Translation("Contact messages"),
|
||||
* label_singular = @Translation("contact message"),
|
||||
* label_plural = @Translation("contact messages"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count contact message",
|
||||
* plural = "@count contact messages",
|
||||
* ),
|
||||
* bundle_label = @Translation("Contact form"),
|
||||
* handlers = {
|
||||
* "access" = "Drupal\contact\ContactMessageAccessControlHandler",
|
||||
* "storage" = "Drupal\Core\Entity\ContentEntityNullStorage",
|
||||
|
@ -107,7 +115,7 @@ class Message extends ContentEntityBase implements MessageInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function copySender() {
|
||||
return (bool)$this->get('copy')->value;
|
||||
return (bool) $this->get('copy')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -134,16 +134,16 @@ class MailHandler implements MailHandlerInterface {
|
|||
|
||||
if (!$message->isPersonal()) {
|
||||
$this->logger->notice('%sender-name (@sender-from) sent an email regarding %contact_form.', [
|
||||
'%sender-name' => $sender_cloned->getUsername(),
|
||||
'%sender-name' => $sender_cloned->getAccountName(),
|
||||
'@sender-from' => $sender_cloned->getEmail(),
|
||||
'%contact_form' => $contact_form->label(),
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$this->logger->notice('%sender-name (@sender-from) sent %recipient-name an email.', [
|
||||
'%sender-name' => $sender_cloned->getUsername(),
|
||||
'%sender-name' => $sender_cloned->getAccountName(),
|
||||
'@sender-from' => $sender_cloned->getEmail(),
|
||||
'%recipient-name' => $message->getPersonalRecipient()->getUsername(),
|
||||
'%recipient-name' => $message->getPersonalRecipient()->getAccountName(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Drupal\contact;
|
|||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityRepositoryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Flood\FloodInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
@ -14,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Form controller for contact message forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class MessageForm extends ContentEntityForm {
|
||||
|
||||
|
@ -55,8 +57,8 @@ class MessageForm extends ContentEntityForm {
|
|||
/**
|
||||
* Constructs a MessageForm object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
|
||||
* The entity repository.
|
||||
* @param \Drupal\Core\Flood\FloodInterface $flood
|
||||
* The flood control mechanism.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
|
@ -70,8 +72,8 @@ class MessageForm extends ContentEntityForm {
|
|||
* @param \Drupal\Component\Datetime\TimeInterface $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, FloodInterface $flood, LanguageManagerInterface $language_manager, MailHandlerInterface $mail_handler, DateFormatterInterface $date_formatter, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
|
||||
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
|
||||
public function __construct(EntityRepositoryInterface $entity_repository, FloodInterface $flood, LanguageManagerInterface $language_manager, MailHandlerInterface $mail_handler, DateFormatterInterface $date_formatter, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
|
||||
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
|
||||
$this->flood = $flood;
|
||||
$this->languageManager = $language_manager;
|
||||
$this->mailHandler = $mail_handler;
|
||||
|
@ -83,7 +85,7 @@ class MessageForm extends ContentEntityForm {
|
|||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('entity.repository'),
|
||||
$container->get('flood'),
|
||||
$container->get('language_manager'),
|
||||
$container->get('contact.mail_handler'),
|
||||
|
@ -107,7 +109,7 @@ class MessageForm extends ContentEntityForm {
|
|||
'#theme_wrappers' => ['container__preview'],
|
||||
'#attributes' => ['class' => ['preview']],
|
||||
];
|
||||
$form['preview']['message'] = $this->entityManager->getViewBuilder('contact_message')->view($message, 'full');
|
||||
$form['preview']['message'] = $this->entityTypeManager->getViewBuilder('contact_message')->view($message, 'full');
|
||||
}
|
||||
|
||||
$form['name'] = [
|
||||
|
@ -222,7 +224,7 @@ class MessageForm extends ContentEntityForm {
|
|||
|
||||
$this->flood->register('contact', $this->config('contact.settings')->get('flood.interval'));
|
||||
if ($submission_message = $contact_form->getMessage()) {
|
||||
drupal_set_message($submission_message);
|
||||
$this->messenger()->addStatus($submission_message);
|
||||
}
|
||||
|
||||
// To avoid false error messages caused by flood control, redirect away from
|
||||
|
|
|
@ -10,7 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
|||
*
|
||||
* @MigrateSource(
|
||||
* id = "contact_category",
|
||||
* source_provider = "contact"
|
||||
* source_module = "contact"
|
||||
* )
|
||||
*/
|
||||
class ContactCategory extends DrupalSqlBase {
|
||||
|
|
|
@ -7,7 +7,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\Variable;
|
|||
/**
|
||||
* @MigrateSource(
|
||||
* id = "contact_settings",
|
||||
* source_provider = "contact"
|
||||
* source_module = "contact"
|
||||
* )
|
||||
*/
|
||||
class ContactSettings extends Variable {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\contact\Plugin\rest\resource;
|
||||
|
||||
use Drupal\rest\Plugin\rest\resource\EntityResource;
|
||||
|
||||
/**
|
||||
* Customizes the entity REST Resource plugin for Contact's Message entities.
|
||||
*
|
||||
* Message entities are not stored, so they cannot be:
|
||||
* - retrieved (GET)
|
||||
* - modified (PATCH)
|
||||
* - deleted (DELETE)
|
||||
* Messages can only be sent/created (POST).
|
||||
*/
|
||||
class ContactMessageResource extends EntityResource {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function availableMethods() {
|
||||
return ['POST'];
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ db_insert('contact')->fields([
|
|||
'recipients',
|
||||
'reply',
|
||||
'weight',
|
||||
'selected'
|
||||
'selected',
|
||||
])
|
||||
->values([
|
||||
'category' => 'Upgrade test',
|
||||
|
|
|
@ -5,5 +5,5 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- contact
|
||||
- user
|
||||
- drupal:contact
|
||||
- drupal:user
|
||||
|
|
|
@ -27,7 +27,6 @@ function contact_storage_test_entity_base_field_info(EntityTypeInterface $entity
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_entity_type_alter().
|
||||
*/
|
||||
|
@ -56,6 +55,7 @@ function contact_storage_test_form_contact_form_form_alter(&$form, FormStateInte
|
|||
];
|
||||
$form['#entity_builders'][] = 'contact_storage_test_contact_form_form_builder';
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity builder for the contact form edit form with third party options.
|
||||
*
|
||||
|
|
|
@ -5,4 +5,4 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- contact
|
||||
- drupal:contact
|
||||
|
|
|
@ -5,6 +5,6 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- contact
|
||||
- views
|
||||
- user
|
||||
- drupal:contact
|
||||
- drupal:views
|
||||
- drupal:user
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests contact form textfields are present if authenticated.
|
||||
*
|
||||
* @group contact
|
||||
*/
|
||||
class ContactAuthenticatedUserTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['contact'];
|
||||
|
||||
/**
|
||||
* Tests that name and email fields are not present for authenticated users.
|
||||
*/
|
||||
public function testContactSiteWideTextfieldsLoggedInTestCase() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['access site-wide contact form']));
|
||||
$this->drupalGet('contact');
|
||||
|
||||
// Ensure that there is no textfield for name.
|
||||
$this->assertFalse($this->xpath('//input[@name=:name]', [':name' => 'name']));
|
||||
|
||||
// Ensure that there is no textfield for email.
|
||||
$this->assertFalse($this->xpath('//input[@name=:name]', [':name' => 'mail']));
|
||||
}
|
||||
|
||||
}
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Drupal\Tests\contact\Functional;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Render\PlainTextOutput;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Test\AssertMailTrait;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
|
@ -98,9 +98,9 @@ class ContactPersonalTest extends BrowserTestBase {
|
|||
$placeholders = [
|
||||
'@sender_name' => $this->webUser->username,
|
||||
'@sender_email' => $this->webUser->getEmail(),
|
||||
'@recipient_name' => $this->contactUser->getUsername()
|
||||
'@recipient_name' => $this->contactUser->getUsername(),
|
||||
];
|
||||
$this->assertRaw(SafeMarkup::format('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders));
|
||||
$this->assertRaw(new FormattableMarkup('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders));
|
||||
// Ensure an unescaped version of the email does not exist anywhere.
|
||||
$this->assertNoRaw($this->webUser->getEmail());
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class ContactPersonalTest extends BrowserTestBase {
|
|||
$this->drupalGet('user/' . $this->contactUser->id());
|
||||
$contact_link = '/user/' . $this->contactUser->id() . '/contact';
|
||||
$this->assertResponse(200);
|
||||
$this->assertNoLinkByHref ($contact_link, 'The "contact" tab is hidden on profiles for users with no email address');
|
||||
$this->assertNoLinkByHref($contact_link, 'The "contact" tab is hidden on profiles for users with no email address');
|
||||
|
||||
// Restore original email address.
|
||||
$this->contactUser->setEmail($original_email)->save();
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
namespace Drupal\Tests\contact\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\contact\Entity\ContactForm;
|
||||
use Drupal\Core\Mail\MailFormatHelper;
|
||||
use Drupal\Core\Test\AssertMailTrait;
|
||||
use Drupal\field_ui\Tests\FieldUiTestTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
|
@ -44,6 +43,27 @@ class ContactSitewideTest extends BrowserTestBase {
|
|||
* Tests configuration options and the site-wide contact form.
|
||||
*/
|
||||
public function testSiteWideContact() {
|
||||
// Tests name and email fields for authenticated and anonymous users.
|
||||
$this->drupalLogin($this->drupalCreateUser(['access site-wide contact form']));
|
||||
$this->drupalGet('contact');
|
||||
|
||||
// Ensure that there is no textfield for name.
|
||||
$this->assertFalse($this->xpath('//input[@name=:name]', [':name' => 'name']));
|
||||
|
||||
// Ensure that there is no textfield for email.
|
||||
$this->assertFalse($this->xpath('//input[@name=:name]', [':name' => 'mail']));
|
||||
|
||||
// Logout and retrieve the page as an anonymous user
|
||||
$this->drupalLogout();
|
||||
user_role_grant_permissions('anonymous', ['access site-wide contact form']);
|
||||
$this->drupalGet('contact');
|
||||
|
||||
// Ensure that there is textfield for name.
|
||||
$this->assertTrue($this->xpath('//input[@name=:name]', [':name' => 'name']));
|
||||
|
||||
// Ensure that there is textfield for email.
|
||||
$this->assertTrue($this->xpath('//input[@name=:name]', [':name' => 'mail']));
|
||||
|
||||
// Create and log in administrative user.
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'access site-wide contact form',
|
||||
|
@ -80,7 +100,7 @@ class ContactSitewideTest extends BrowserTestBase {
|
|||
// field_ui enabled admin/structure/contact/manage/personal/fields exists.
|
||||
// @todo: See https://www.drupal.org/node/2031223 for the above.
|
||||
$edit_link = $this->xpath('//a[@href=:href]', [
|
||||
':href' => \Drupal::url('entity.contact_form.edit_form', ['contact_form' => 'personal'])
|
||||
':href' => \Drupal::url('entity.contact_form.edit_form', ['contact_form' => 'personal']),
|
||||
]);
|
||||
$this->assertTrue(empty($edit_link), format_string('No link containing href %href found.',
|
||||
['%href' => 'admin/structure/contact/manage/personal']
|
||||
|
@ -128,9 +148,9 @@ class ContactSitewideTest extends BrowserTestBase {
|
|||
$recipients = ['simpletest&@example.com', 'simpletest2@example.com', 'simpletest3@example.com'];
|
||||
$max_length = EntityTypeInterface::BUNDLE_MAX_LENGTH;
|
||||
$max_length_exceeded = $max_length + 1;
|
||||
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName($max_length_exceeded)), $label = $this->randomMachineName($max_length_exceeded), implode(',', [$recipients[0]]), '', TRUE);
|
||||
$this->addContactForm($id = mb_strtolower($this->randomMachineName($max_length_exceeded)), $label = $this->randomMachineName($max_length_exceeded), implode(',', [$recipients[0]]), '', TRUE);
|
||||
$this->assertText(format_string('Machine-readable name cannot be longer than @max characters but is currently @exceeded characters long.', ['@max' => $max_length, '@exceeded' => $max_length_exceeded]));
|
||||
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName($max_length)), $label = $this->randomMachineName($max_length), implode(',', [$recipients[0]]), '', TRUE);
|
||||
$this->addContactForm($id = mb_strtolower($this->randomMachineName($max_length)), $label = $this->randomMachineName($max_length), implode(',', [$recipients[0]]), '', TRUE);
|
||||
$this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
|
||||
|
||||
// Verify that the creation message contains a link to a contact form.
|
||||
|
@ -138,7 +158,7 @@ class ContactSitewideTest extends BrowserTestBase {
|
|||
$this->assert(isset($view_link), 'The message area contains a link to a contact form.');
|
||||
|
||||
// Create first valid form.
|
||||
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0]]), '', TRUE);
|
||||
$this->addContactForm($id = mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0]]), '', TRUE);
|
||||
$this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
|
||||
|
||||
// Verify that the creation message contains a link to a contact form.
|
||||
|
@ -181,10 +201,10 @@ class ContactSitewideTest extends BrowserTestBase {
|
|||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Add more forms.
|
||||
$this->addContactForm(Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0], $recipients[1]]), '', FALSE);
|
||||
$this->addContactForm(mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0], $recipients[1]]), '', FALSE);
|
||||
$this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
|
||||
|
||||
$this->addContactForm($name = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0], $recipients[1], $recipients[2]]), '', FALSE);
|
||||
$this->addContactForm($name = mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0], $recipients[1], $recipients[2]]), '', FALSE);
|
||||
$this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
|
||||
|
||||
// Try adding a form that already exists.
|
||||
|
@ -249,7 +269,7 @@ class ContactSitewideTest extends BrowserTestBase {
|
|||
|
||||
$label = $this->randomMachineName(16);
|
||||
$recipients = implode(',', [$recipients[0], $recipients[1], $recipients[2]]);
|
||||
$contact_form = Unicode::strtolower($this->randomMachineName(16));
|
||||
$contact_form = mb_strtolower($this->randomMachineName(16));
|
||||
$this->addContactForm($contact_form, $label, $recipients, '', FALSE);
|
||||
$this->drupalGet('admin/structure/contact');
|
||||
$this->clickLink(t('Edit'));
|
||||
|
@ -279,7 +299,7 @@ class ContactSitewideTest extends BrowserTestBase {
|
|||
$this->assertResponse(200);
|
||||
|
||||
// Create a simple textfield.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_label = $this->randomMachineName();
|
||||
$this->fieldUIAddNewField(NULL, $field_name, $field_label, 'text');
|
||||
$field_name = 'field_' . $field_name;
|
||||
|
@ -385,7 +405,7 @@ class ContactSitewideTest extends BrowserTestBase {
|
|||
'administer contact forms',
|
||||
'administer permissions',
|
||||
'administer users',
|
||||
'access site reports'
|
||||
'access site reports',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\contact\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\contact\Entity\Message;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
|
@ -47,7 +46,7 @@ class ContactStorageTest extends ContactSitewideTest {
|
|||
$this->drupalLogin($admin_user);
|
||||
// Create first valid contact form.
|
||||
$mail = 'simpletest@example.com';
|
||||
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$mail]), '', TRUE, 'Your message has been sent.', [
|
||||
$this->addContactForm($id = mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$mail]), '', TRUE, 'Your message has been sent.', [
|
||||
'send_a_pony' => 1,
|
||||
]);
|
||||
$this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\contact\Functional\Rest\ContactFormResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ContactFormHalJsonAnonTest extends ContactFormResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\contact\Functional\Rest\ContactFormResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ContactFormHalJsonBasicAuthTest extends ContactFormResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\contact\Functional\Rest\ContactFormResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ContactFormHalJsonCookieTest extends ContactFormResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\contact\Functional\Rest\MessageResourceTestBase;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MessageHalJsonAnonTest extends MessageResourceTestBase {
|
||||
|
||||
use HalEntityNormalizationTrait;
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return parent::getNormalizedPostEntity() + [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/contact_message/camelids',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MessageHalJsonBasicAuthTest extends MessageHalJsonAnonTest {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MessageHalJsonCookieTest extends MessageHalJsonAnonTest {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ContactFormJsonAnonTest extends ContactFormResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ContactFormJsonBasicAuthTest extends ContactFormResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ContactFormJsonCookieTest extends ContactFormResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\contact\Entity\ContactForm;
|
||||
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
|
||||
abstract class ContactFormResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
use BcTimestampNormalizerUnixTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['contact'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'contact_form';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [];
|
||||
|
||||
/**
|
||||
* @var \Drupal\contact\Entity\ContactForm
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
$this->grantPermissionsToTestedRole(['access site-wide contact form']);
|
||||
default:
|
||||
$this->grantPermissionsToTestedRole(['administer contact forms']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$contact_form = ContactForm::create([
|
||||
'id' => 'llama',
|
||||
'label' => 'Llama',
|
||||
'message' => 'Let us know what you think about llamas',
|
||||
'reply' => 'Llamas are indeed awesome!',
|
||||
'recipients' => [
|
||||
'llama@example.com',
|
||||
'contact@example.com',
|
||||
],
|
||||
]);
|
||||
$contact_form->save();
|
||||
|
||||
return $contact_form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'dependencies' => [],
|
||||
'id' => 'llama',
|
||||
'label' => 'Llama',
|
||||
'langcode' => 'en',
|
||||
'message' => 'Let us know what you think about llamas',
|
||||
'recipients' => [
|
||||
'llama@example.com',
|
||||
'contact@example.com',
|
||||
],
|
||||
'redirect' => NULL,
|
||||
'reply' => 'Llamas are indeed awesome!',
|
||||
'status' => TRUE,
|
||||
'uuid' => $this->entity->uuid(),
|
||||
'weight' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
// @todo Update in https://www.drupal.org/node/2300677.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
return "The 'access site-wide contact form' permission is required.";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ContactFormXmlAnonTest extends ContactFormResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ContactFormXmlBasicAuthTest extends ContactFormResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ContactFormXmlCookieTest extends ContactFormResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class MessageJsonAnonTest extends MessageResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class MessageJsonBasicAuthTest extends MessageResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class MessageJsonCookieTest extends MessageResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\contact\Entity\ContactForm;
|
||||
use Drupal\contact\Entity\Message;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
|
||||
abstract class MessageResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['contact'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'contact_message';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $labelFieldName = 'subject';
|
||||
|
||||
/**
|
||||
* The Message entity.
|
||||
*
|
||||
* @var \Drupal\contact\MessageInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['access site-wide contact form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
if (!ContactForm::load('camelids')) {
|
||||
// Create a "Camelids" contact form.
|
||||
ContactForm::create([
|
||||
'id' => 'camelids',
|
||||
'label' => 'Llama',
|
||||
'message' => 'Let us know what you think about llamas',
|
||||
'reply' => 'Llamas are indeed awesome!',
|
||||
'recipients' => [
|
||||
'llama@example.com',
|
||||
'contact@example.com',
|
||||
],
|
||||
])->save();
|
||||
}
|
||||
|
||||
$message = Message::create([
|
||||
'contact_form' => 'camelids',
|
||||
'subject' => 'Llama Gabilondo',
|
||||
'message' => 'Llamas are awesome!',
|
||||
]);
|
||||
$message->save();
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return [
|
||||
'subject' => [
|
||||
[
|
||||
'value' => 'Dramallama',
|
||||
],
|
||||
],
|
||||
'contact_form' => [
|
||||
[
|
||||
'target_id' => 'camelids',
|
||||
],
|
||||
],
|
||||
'message' => [
|
||||
[
|
||||
'value' => 'http://www.urbandictionary.com/define.php?term=drama%20llama',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
throw new \Exception('Not yet supported.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
if ($method === 'POST') {
|
||||
return "The 'access site-wide contact form' permission is required.";
|
||||
}
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testGet() {
|
||||
// Contact Message entities are not stored, so they cannot be retrieved.
|
||||
$this->setExpectedException(RouteNotFoundException::class, 'Route "rest.entity.contact_message.GET" does not exist.');
|
||||
|
||||
$this->provisionEntityResource();
|
||||
Url::fromRoute('rest.entity.contact_message.GET')->toString(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testPatch() {
|
||||
// Contact Message entities are not stored, so they cannot be modified.
|
||||
$this->setExpectedException(RouteNotFoundException::class, 'Route "rest.entity.contact_message.PATCH" does not exist.');
|
||||
|
||||
$this->provisionEntityResource();
|
||||
Url::fromRoute('rest.entity.contact_message.PATCH')->toString(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testDelete() {
|
||||
// Contact Message entities are not stored, so they cannot be deleted.
|
||||
$this->setExpectedException(RouteNotFoundException::class, 'Route "rest.entity.contact_message.DELETE" does not exist.');
|
||||
|
||||
$this->provisionEntityResource();
|
||||
Url::fromRoute('rest.entity.contact_message.DELETE')->toString(TRUE);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class MessageXmlAnonTest extends MessageResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class MessageXmlBasicAuthTest extends MessageResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\contact\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class MessageXmlCookieTest extends MessageResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\contact\Tests\Update;
|
||||
namespace Drupal\Tests\contact\Functional\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests contact update path.
|
||||
*
|
||||
* @group contact
|
||||
* @group legacy
|
||||
*/
|
||||
class ContactUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
|
@ -16,7 +17,7 @@ class ContactUpdateTest extends UpdatePathTestBase {
|
|||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\contact\Tests\Views;
|
||||
namespace Drupal\Tests\contact\Functional\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\contact\Entity\ContactForm;
|
||||
|
||||
|
@ -28,13 +28,13 @@ class ContactFieldsTest extends ViewTestBase {
|
|||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => strtolower($this->randomMachineName()),
|
||||
'entity_type' => 'contact_message',
|
||||
'type' => 'text'
|
||||
'type' => 'text',
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\contact\Tests\Views;
|
||||
namespace Drupal\Tests\contact\Functional\Views;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
|
@ -39,8 +39,8 @@ class ContactLinkTest extends ViewTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), ['contact_test_views']);
|
||||
|
|
@ -37,7 +37,7 @@ class ContactSettingsTest extends MigrateSqlSourceTestBase {
|
|||
'reply' => '',
|
||||
'weight' => '0',
|
||||
'selected' => '1',
|
||||
]
|
||||
],
|
||||
];
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
|
|
|
@ -136,7 +136,7 @@ class MailHandlerTest extends UnitTestCase {
|
|||
$this->mailManager->expects($this->any())
|
||||
->method('mail')
|
||||
->willReturnCallback(
|
||||
function($module, $key, $to, $langcode, $params, $from) use (&$results) {
|
||||
function ($module, $key, $to, $langcode, $params, $from) use (&$results) {
|
||||
$result = array_shift($results);
|
||||
$this->assertEquals($module, $result['module']);
|
||||
$this->assertEquals($key, $result['key']);
|
||||
|
@ -234,7 +234,7 @@ class MailHandlerTest extends UnitTestCase {
|
|||
$results[] = $result + $default_result;
|
||||
$data[] = [$message, $sender, $results];
|
||||
|
||||
//For authenticated user.
|
||||
// For authenticated user.
|
||||
$results = [];
|
||||
$message = $this->getAuthenticatedMockMessage();
|
||||
$sender = $this->getMockSender(FALSE, 'user@drupal.org');
|
||||
|
@ -367,7 +367,7 @@ class MailHandlerTest extends UnitTestCase {
|
|||
$recipient->expects($this->once())
|
||||
->method('getEmail')
|
||||
->willReturn('user2@drupal.org');
|
||||
$recipient->expects($this->once())
|
||||
$recipient->expects($this->any())
|
||||
->method('getDisplayName')
|
||||
->willReturn('user2');
|
||||
$recipient->expects($this->once())
|
||||
|
|
Reference in a new issue