Update to Drupal 8.1.8. For more information, see https://www.drupal.org/project/drupal/releases/8.1.8

This commit is contained in:
Pantheon Automation 2016-08-03 13:22:33 -07:00 committed by Greg Anderson
parent e9f047ccf8
commit f9f23cdf38
312 changed files with 6751 additions and 1546 deletions

View file

@ -0,0 +1,173 @@
<?php
namespace Drupal\Tests\Core\Assert;
use Behat\Mink\Element\DocumentElement;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Session;
use Drupal\Component\Render\MarkupInterface;
use Drupal\FunctionalTests\AssertLegacyTrait;
use Drupal\Tests\UnitTestCase;
use Drupal\Tests\WebAssert;
use PHPUnit_Framework_ExpectationFailedException;
/**
* @coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait
* @group Assert
*/
class AssertLegacyTraitTest extends UnitTestCase {
use AssertLegacyTrait;
/**
* The mocked Mink session object used for testing.
*
* @var \Behat\Mink\Session|\Prophecy\Prophecy\ObjectProphecy
*/
protected $session;
/**
* The mocked page element used for testing.
*
* @var Behat\Mink\Element\DocumentElement|\Prophecy\Prophecy\ObjectProphecy
*/
protected $page;
/**
* The mocked web assert class.
*
* @var \Drupal\Tests\WebAssert|\Prophecy\Prophecy\ObjectProphecy
*/
protected $webAssert;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->page = $this->prophesize(DocumentElement::class);
$this->session = $this->prophesize(Session::class);
$this->session->getPage()->willReturn($this->page->reveal());
$this->webAssert = $this->prophesize(WebAssert::class);
}
/**
* @covers ::assertUniqueText
*/
public function testAssertUniqueText() {
$this->page->getText()->willReturn('foo bar bar');
$this->assertUniqueText('foo');
}
/**
* @covers ::assertUniqueText
*/
public function testAssertUniqueTextFail() {
$this->page->getText()->willReturn('foo bar bar');
$this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class);
$this->assertUniqueText('bar');
}
/**
* @covers ::assertUniqueText
*/
public function testAssertUniqueTextUnknown() {
$this->page->getText()->willReturn('foo bar bar');
$this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class);
$this->assertUniqueText('alice');
}
/**
* @covers ::assertUniqueText
*/
public function testAssertUniqueTextMarkup() {
$this->page->getText()->willReturn('foo bar bar');
$markupObject = $this->prophesize(MarkupInterface::class);
$markupObject->__toString()->willReturn('foo');
$this->assertUniqueText($markupObject->reveal());
}
/**
* @covers ::assertNoUniqueText
*/
public function testAssertNoUniqueText() {
$this->page->getText()->willReturn('foo bar bar');
$this->assertNoUniqueText('bar');
}
/**
* @covers ::assertNoUniqueText
*/
public function testAssertNoUniqueTextFail() {
$this->page->getText()->willReturn('foo bar bar');
$this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class);
$this->assertNoUniqueText('foo');
}
/**
* @covers ::assertNoUniqueText
*/
public function testAssertNoUniqueTextUnknown() {
$this->page->getText()->willReturn('foo bar bar');
$this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class);
$this->assertNoUniqueText('alice');
}
/**
* @covers ::assertNoUniqueText
*/
public function testAssertNoUniqueTextMarkup() {
$this->page->getText()->willReturn('foo bar bar');
$markupObject = $this->prophesize(MarkupInterface::class);
$markupObject->__toString()->willReturn('bar');
$this->assertNoUniqueText($markupObject->reveal());
}
/**
* @covers ::assertOptionSelected
*/
public function testAssertOptionSelected() {
$option_field = $this->prophesize(NodeElement::class);
$option_field->hasAttribute('selected')->willReturn(TRUE);
$this->webAssert
->optionExists('myselect', 'two')
->willReturn($option_field->reveal());
$this->assertOptionSelected('myselect', 'two');
}
/**
* @covers ::assertOptionSelected
*/
public function testAssertOptionSelectedFail() {
$option_field = $this->prophesize(NodeElement::class);
$option_field->hasAttribute('selected')->willReturn(FALSE);
$this->webAssert
->optionExists('myselect', 'two')
->willReturn($option_field->reveal());
$this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class);
$this->assertOptionSelected('myselect', 'two');
}
/**
* Returns a mocked behat session object.
*
* @return \Behat\Mink\Session
* The mocked session.
*/
protected function getSession() {
return $this->session->reveal();
}
/**
* {@inheritdoc}
*/
public function assertSession($name = NULL) {
return $this->webAssert->reveal();
}
}

View file

@ -0,0 +1,101 @@
<?php
namespace Drupal\Tests\Core\Config;
use Drupal\Core\Config\ConfigCollectionInfo;
use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigFactoryOverrideBase;
use Drupal\Core\Config\ConfigRenameEvent;
/**
* @coversDefaultClass \Drupal\Core\Config\ConfigFactoryOverrideBase
* @group config
*/
class ConfigFactoryOverrideBaseTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider providerTestFilterNestedArray
*/
public function testFilterNestedArray(array $original_data, array $override_data_before, array $override_data_after, $changed) {
$config_factory = new TestConfigFactoryOverrideBase();
$result = $config_factory->doFilterNestedArray($original_data, $override_data_before);
$this->assertEquals($changed, $result);
$this->assertEquals($override_data_after, $override_data_before);
}
public function providerTestFilterNestedArray() {
$data = [];
$data['empty'] = [
[],
[],
[],
FALSE,
];
$data['one-level-no-change'] = [
['key' => 'value'],
[],
[],
FALSE,
];
$data['one-level-override-no-change'] = [
['key' => 'value'],
['key' => 'value2'],
['key' => 'value2'],
FALSE,
];
$data['one-level-override-change'] = [
['key' => 'value'],
['key2' => 'value2'],
[],
TRUE,
];
$data['one-level-multiple-override-change'] = [
['key' => 'value', 'key2' => 'value2'],
['key2' => 'value2', 'key3' => 'value3'],
['key2' => 'value2'],
TRUE,
];
$data['multiple-level-multiple-override-change'] = [
['key' => ['key' => 'value'], 'key2' => ['key' => 'value']],
['key' => ['key2' => 'value2'], 'key2' => ['key' => 'value']],
['key2' => ['key' => 'value']],
TRUE,
];
$data['original-scalar-array-override'] = [
['key' => 'value'],
['key' => ['value1', 'value2']],
[],
TRUE,
];
return $data;
}
}
class TestConfigFactoryOverrideBase extends ConfigFactoryOverrideBase {
public function doFilterNestedArray(array $original_data, array &$override_data) {
return $this->filterNestedArray($original_data, $override_data);
}
public function addCollections(ConfigCollectionInfo $collection_info) {
}
public function onConfigSave(ConfigCrudEvent $event) {
}
public function onConfigDelete(ConfigCrudEvent $event) {
}
public function onConfigRename(ConfigRenameEvent $event) {
}
}

View file

@ -0,0 +1,154 @@
<?php
namespace Drupal\Tests\Core\Database;
use Drupal\Core\Database\Database;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\Database\Database
*
* @group Database
*/
class UrlConversionTest extends UnitTestCase {
/**
* @covers ::convertDbUrlToConnectionInfo
*
* @dataProvider providerConvertDbUrlToConnectionInfo
*/
public function testDbUrltoConnectionConversion($root, $url, $database_array) {
$result = Database::convertDbUrlToConnectionInfo($url, $root);
$this->assertEquals($database_array, $result);
}
/**
* Dataprovider for testDbUrltoConnectionConversion().
*
* @return array
* Array of arrays with the following elements:
* - root: The baseroot string, only used with sqlite drivers.
* - url: The full URL string to be tested.
* - database_array: An array containing the expected results.
*/
public function providerConvertDbUrlToConnectionInfo() {
// Some valid datasets.
$root1 = '';
$url1 = 'mysql://test_user:test_pass@test_host:3306/test_database';
$database_array1 = [
'driver' => 'mysql',
'username' => 'test_user',
'password' => 'test_pass',
'host' => 'test_host',
'database' => 'test_database',
'port' => '3306',
];
$root2 = '/var/www/d8';
$url2 = 'sqlite://test_user:test_pass@test_host:3306/test_database';
$database_array2 = [
'driver' => 'sqlite',
'username' => 'test_user',
'password' => 'test_pass',
'host' => 'test_host',
'database' => $root2 . '/test_database',
'port' => 3306,
];
return [
[$root1, $url1, $database_array1],
[$root2, $url2, $database_array2],
];
}
/**
* Test ::convertDbUrlToConnectionInfo() exception for invalid arguments.
*
* @dataProvider providerInvalidArgumentsUrlConversion
*/
public function testGetInvalidArgumentExceptionInUrlConversion($url, $root) {
$this->setExpectedException(\InvalidArgumentException::class);
Database::convertDbUrlToConnectionInfo($url, $root);
}
/**
* Dataprovider for testGetInvalidArgumentExceptionInUrlConversion().
*
* @return array
* Array of arrays with the following elements:
* - An invalid Url string.
* - Drupal root string.
*/
public function providerInvalidArgumentsUrlConversion() {
return [
['foo', ''],
['foo', 'bar'],
['foo://', 'bar'],
['foo://bar', 'baz'],
['foo://bar:port', 'baz'],
['foo/bar/baz', 'bar2'],
['foo://bar:baz@test1', 'test2'],
];
}
/**
* @covers ::convertDbUrlToConnectionInfo
*
* @dataProvider providerGetConnectionInfoAsUrl
*/
public function testGetConnectionInfoAsUrl(Array $info, $expected_url) {
Database::addConnectionInfo('default', 'default', $info);
$url = Database::getConnectionInfoAsUrl();
// Remove the connection to not pollute subsequent datasets being tested.
Database::removeConnection('default');
$this->assertEquals($expected_url, $url);
}
/**
* Dataprovider for testGetConnectionInfoAsUrl().
*
* @return array
* Array of arrays with the following elements:
* - An array mocking the database connection info. Possible keys are
* database, username, password, prefix, host, port, namespace and driver.
* - The expected URL after conversion.
*/
public function providerGetConnectionInfoAsUrl() {
$info1 = [
'database' => 'test_database',
'username' => 'test_user',
'password' => 'test_pass',
'prefix' => '',
'host' => 'test_host',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
];
$expected_url1 = 'mysql://test_user:test_pass@test_host:3306/test_database';
$info2 = [
'database' => 'test_database',
'username' => 'test_user',
'password' => 'test_pass',
'prefix' => 'pre',
'host' => 'test_host',
'port' => '3306',
'driver' => 'mysql',
];
$expected_url2 = 'mysql://test_user:test_pass@test_host:3306/test_database#pre';
$info3 = [
'database' => 'test_database',
'driver' => 'sqlite',
];
$expected_url3 = 'sqlite://localhost/test_database';
return [
[$info1, $expected_url1],
[$info2, $expected_url2],
[$info3, $expected_url3],
];
}
}

View file

@ -384,6 +384,38 @@ class EntityResolverManagerTest extends UnitTestCase {
$this->assertEquals(array('entity_test' => array('type' => 'entity:entity_test')), $parameters);
}
/**
* Tests an _entity_form route where a non-entity parameter is first.
*
* The {argument} preceding {entity_test} in route path, is upcasting with a
* custom param converter.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
* @covers ::setParametersFromEntityInformation
*/
public function testSetRouteOptionsWithEntityFormRouteAndArgument() {
$this->setupEntityTypes();
$route = new Route('/example/{argument}/{entity_test}', [
'_entity_form' => 'entity_test.edit',
]);
// Add {argument} parameter configuration. In this case {argument} is
// upcasted by a custom param converter 'argument_type'.
$route->setOption('parameters', ['argument' => ['type' => 'argument_type']]);
$defaults = $route->getDefaults();
$this->entityResolverManager->setRouteOptions($route);
$this->assertEquals($defaults, $route->getDefaults());
$parameters = $route->getOption('parameters');
$expect = [
'argument' => ['type' => 'argument_type'],
'entity_test' => ['type' => 'entity:entity_test'],
];
$this->assertEquals($expect, $parameters);
}
/**
* Creates the entity manager mock returning entity type objects.
*/

View file

@ -76,6 +76,20 @@ class EntityUrlTest extends UnitTestCase {
*/
const NON_DEFAULT_REVISION = FALSE;
/**
* Indicator that the test entity type has no bundle key.
*
* @var false
*/
const HAS_NO_BUNDLE_KEY = FALSE;
/**
* Indicator that the test entity type has a bundle key.
*
* @var true
*/
const HAS_BUNDLE_KEY = TRUE;
/**
* Tests the toUrl() method without an entity ID.
*
@ -185,20 +199,94 @@ class EntityUrlTest extends UnitTestCase {
}
/**
* Tests the toUrl() method with the 'collection' link template.
* Tests the toUrl() method with link templates without an entity ID.
*
* @param string $link_template
* The link template to test.
* @param string $expected_route_name
* The expected route name of the generated URL.
*
* @dataProvider providerTestToUrlLinkTemplateNoId
*
* @covers ::toUrl
* @covers ::linkTemplates
* @covers ::urlRouteParameters
*/
public function testToUrlLinkTemplateCollection() {
public function testToUrlLinkTemplateNoId($link_template, $expected_route_name) {
$entity = $this->getEntity(Entity::class, ['id' => $this->entityId]);
$link_template = 'collection';
$this->registerLinkTemplate($link_template);
/** @var \Drupal\Core\Url $url */
$url = $entity->toUrl($link_template);
$this->assertUrl('entity.test_entity.collection', [], $entity, FALSE, $url);
$this->assertUrl($expected_route_name, [], $entity, FALSE, $url);
}
/**
* Provides data for testToUrlLinkTemplateNoId().
*
* @return array
* An array of test cases for testToUrlLinkTemplateNoId().
*/
public function providerTestToUrlLinkTemplateNoId() {
$test_cases = [];
$test_cases['collection'] = ['collection', 'entity.test_entity.collection'];
$test_cases['add-page'] = ['add-page', 'entity.test_entity.add_page'];
return $test_cases;
}
/**
* Tests the toUrl() method with the 'revision' link template.
*
* @param bool $has_bundle_key
* Whether or not the mock entity type should have a bundle key.
* @param string|null $bundle_entity_type
* The ID of the bundle entity type of the mock entity type, or NULL if the
* mock entity type should not have a bundle entity type.
* @param string $bundle_key
* The bundle key of the mock entity type or FALSE if the entity type should
* not have a bundle key.
* @param array $expected_route_parameters
* The expected route parameters of the generated URL.
*
* @dataProvider providerTestToUrlLinkTemplateAddForm
*
* @covers ::toUrl
* @covers ::linkTemplates
* @covers ::urlRouteParameters
*/
public function testToUrlLinkTemplateAddForm($has_bundle_key, $bundle_entity_type, $bundle_key, $expected_route_parameters) {
$values = ['id' => $this->entityId, 'langcode' => $this->langcode];
$entity = $this->getEntity(Entity::class, $values);
$this->entityType->hasKey('bundle')->willReturn($has_bundle_key);
$this->entityType->getBundleEntityType()->willReturn($bundle_entity_type);
$this->entityType->getKey('bundle')->willReturn($bundle_key);
$link_template = 'add-form';
$this->registerLinkTemplate($link_template);
/** @var \Drupal\Core\Url $url */
$url = $entity->toUrl($link_template);
$this->assertUrl('entity.test_entity.add_form', $expected_route_parameters, $entity, FALSE, $url);
}
/**
* Provides data for testToUrlLinkTemplateAddForm().
*
* @return array
* An array of test cases for testToUrlLinkTemplateAddForm().
*/
public function providerTestToUrlLinkTemplateAddForm() {
$test_cases = [];
$route_parameters = [];
$test_cases['no_bundle_key'] = [static::HAS_NO_BUNDLE_KEY, NULL, FALSE, $route_parameters];
$route_parameters = ['type' => $this->entityTypeId];
$test_cases['bundle_entity_type'] = [static::HAS_BUNDLE_KEY, 'type', FALSE, $route_parameters];
$test_cases['bundle_key'] = [static::HAS_BUNDLE_KEY, NULL, 'type', $route_parameters];
return $test_cases;
}
/**

View file

@ -3,6 +3,7 @@
namespace Drupal\Tests\Core\ParamConverter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\ParamConverter\EntityRevisionParamConverter;
@ -28,7 +29,10 @@ class EntityRevisionParamConverterTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
$this->converter = new EntityRevisionParamConverter($this->prophesize(EntityTypeManagerInterface::class)->reveal());
$this->converter = new EntityRevisionParamConverter(
$this->prophesize(EntityTypeManagerInterface::class)->reveal(),
$this->prophesize(EntityRepositoryInterface::class)->reveal()
);
}
protected function getTestRoute() {
@ -67,7 +71,9 @@ class EntityRevisionParamConverterTest extends UnitTestCase {
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager->getStorage('test')->willReturn($storage->reveal());
$converter = new EntityRevisionParamConverter($entity_type_manager->reveal());
$entity_repository = $this->prophesize(EntityRepositoryInterface::class);
$entity_repository->getTranslationFromContext($entity)->willReturn($entity);
$converter = new EntityRevisionParamConverter($entity_type_manager->reveal(), $entity_repository->reveal());
$route = $this->getTestRoute();
$result = $converter->convert(1, $route->getOption('parameters')['test_revision'], 'test_revision', ['test_revision' => 1]);