Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -21,7 +21,7 @@ db_insert('contact')->fields([
'recipients',
'reply',
'weight',
'selected'
'selected',
])
->values([
'category' => 'Upgrade test',

View file

@ -5,5 +5,5 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- contact
- user
- drupal:contact
- drupal:user

View file

@ -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.
*

View file

@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- contact
- drupal:contact

View file

@ -5,6 +5,6 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- contact
- views
- user
- drupal:contact
- drupal:views
- drupal:user

View file

@ -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']));
}
}

View file

@ -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();

View file

@ -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);

View file

@ -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]));

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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',
],
],
];
}
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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.";
}
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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);
}
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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';
}

View file

@ -0,0 +1,54 @@
<?php
namespace Drupal\Tests\contact\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests contact update path.
*
* @group contact
* @group legacy
*/
class ContactUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
];
}
/**
* Tests contact_form updates.
*
* @see contact_post_update_add_message_redirect_field_to_contact_form()
*/
public function testPostUpdateContactFormFields() {
// Check that contact_form does not have fields redirect and message.
$config_factory = \Drupal::configFactory();
// Check that contact_form entities are more than zero.
$contact_forms = $config_factory->listAll('contact.form.');
$this->assertTrue(count($contact_forms), 'There are contact forms to update.');
foreach ($contact_forms as $contact_config_name) {
$contact_form_data = $config_factory->get($contact_config_name)->get();
$this->assertFalse(isset($contact_form_data['message']), 'Prior to running the update the "message" key does not exist.');
$this->assertFalse(isset($contact_form_data['redirect']), 'Prior to running the update the "redirect" key does not exist.');
}
// Run updates.
$this->runUpdates();
// Check that the contact_form entities have been updated.
foreach ($contact_forms as $contact_config_name) {
$contact_form_data = $config_factory->get($contact_config_name)->get();
$this->assertTrue(isset($contact_form_data['message']), 'After running the update the "message" key exists.');
$this->assertEqual('Your message has been sent.', $contact_form_data['message']);
$this->assertTrue(isset($contact_form_data['redirect']), 'After running the update the "redirect" key exists.');
$this->assertEqual('', $contact_form_data['redirect']);
}
}
}

View file

@ -0,0 +1,65 @@
<?php
namespace Drupal\Tests\contact\Functional\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\contact\Entity\ContactForm;
/**
* Tests which checks that no fieldapi fields are added on contact.
*
* @group contact
*/
class ContactFieldsTest extends ViewTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['field', 'text', 'contact'];
/**
* Contains the field storage definition for contact used for this test.
*
* @var \Drupal\field\Entity\FieldStorageConfig
*/
protected $fieldStorage;
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',
]);
$this->fieldStorage->save();
ContactForm::create([
'id' => 'contact_message',
'label' => 'Test contact form',
])->save();
FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'contact_message',
])->save();
$this->container->get('views.views_data')->clear();
}
/**
* Tests the views data generation.
*/
public function testViewsData() {
// Test that the field is not exposed to views, since contact_message
// entities have no storage.
$table_name = 'contact_message__' . $this->fieldStorage->getName();
$data = $this->container->get('views.views_data')->get($table_name);
$this->assertFalse($data, 'The field is not exposed to Views.');
}
}

View file

@ -0,0 +1,108 @@
<?php
namespace Drupal\Tests\contact\Functional\Views;
use Drupal\Core\Cache\Cache;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\user\Entity\User;
/**
* Tests the contact link field.
*
* @group contact
* @see \Drupal\contact\Plugin\views\field\ContactLink.
*/
class ContactLinkTest extends ViewTestBase {
/**
* Stores the user data service used by the test.
*
* @var \Drupal\user\UserDataInterface
*/
public $userData;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['contact_test_views'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_contact_link'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['contact_test_views']);
$this->userData = $this->container->get('user.data');
}
/**
* Tests contact link.
*/
public function testContactLink() {
$accounts = [];
$accounts['root'] = User::load(1);
// Create an account with access to all contact pages.
$admin_account = $this->drupalCreateUser(['administer users']);
$accounts['admin'] = $admin_account;
// Create an account with no access to contact pages.
$no_contact_account = $this->drupalCreateUser();
$accounts['no_contact'] = $no_contact_account;
// Create an account with access to contact pages.
$contact_account = $this->drupalCreateUser(['access user contact forms']);
$accounts['contact'] = $contact_account;
$this->drupalLogin($admin_account);
$this->drupalGet('test-contact-link');
// The admin user has access to all contact links beside his own.
$this->assertContactLinks($accounts, ['root', 'no_contact', 'contact']);
$this->drupalLogin($no_contact_account);
$this->drupalGet('test-contact-link');
// Ensure that the user without the permission doesn't see any link.
$this->assertContactLinks($accounts, []);
$this->drupalLogin($contact_account);
$this->drupalGet('test-contact-link');
$this->assertContactLinks($accounts, ['root', 'admin', 'no_contact']);
// Disable contact link for no_contact.
$this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE);
// @todo Remove cache invalidation in https://www.drupal.org/node/2477903.
Cache::invalidateTags($no_contact_account->getCacheTagsToInvalidate());
$this->drupalGet('test-contact-link');
$this->assertContactLinks($accounts, ['root', 'admin']);
}
/**
* Asserts whether certain users contact links appear on the page.
*
* @param array $accounts
* All user objects used by the test.
* @param array $names
* Users which should have contact links.
*/
public function assertContactLinks(array $accounts, array $names) {
$result = $this->xpath('//div[contains(@class, "views-field-contact")]//a');
$this->assertEqual(count($result), count($names));
foreach ($names as $name) {
$account = $accounts[$name];
$result = $this->xpath('//div[contains(@class, "views-field-contact")]//a[contains(@href, :url)]', [':url' => $account->url('contact-form')]);
$this->assertTrue(count($result));
}
}
}

View file

@ -37,7 +37,7 @@ class ContactSettingsTest extends MigrateSqlSourceTestBase {
'reply' => '',
'weight' => '0',
'selected' => '1',
]
],
];
$tests[0]['expected_data'] = [
[

View file

@ -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())