Skip to content
GitLab
Explore
Sign in
project
drupal
Compare revisions
c5ce86234f84acab47b7dc892b55504536875ccd to 8.1.x
Hide whitespace changes
Inline
Side-by-side
core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php
View file @
614ba415
...
...
@@ -208,6 +208,7 @@ public function testFieldAdminHandler() {
'id'
=>
'node_test_view'
,
'label'
=>
'Node Test View'
,
'show[wizard_key]'
=>
'node'
,
'show[sort]'
=>
'none'
,
'page[create]'
=>
1
,
'page[title]'
=>
'Test Node View'
,
'page[path]'
=>
'test/node/view'
,
...
...
@@ -221,6 +222,14 @@ public function testFieldAdminHandler() {
'style_options[search_fields][title]'
=>
'title'
,
);
$this
->
drupalPostForm
(
NULL
,
$edit
,
t
(
'Apply'
));
// Set sort to NID ascending.
$edit
=
[
'name[node_field_data.nid]'
=>
1
,
];
$this
->
drupalPostForm
(
'admin/structure/views/nojs/add-handler/node_test_view/entity_reference_1/sort'
,
$edit
,
t
(
'Add and configure sort criteria'
));
$this
->
drupalPostForm
(
NULL
,
NULL
,
t
(
'Apply'
));
$this
->
drupalPostForm
(
'admin/structure/views/view/node_test_view/edit/entity_reference_1'
,
array
(),
t
(
'Save'
));
$this
->
clickLink
(
t
(
'Settings'
));
...
...
@@ -301,6 +310,7 @@ public function testFieldAdminHandler() {
$this
->
assertText
(
t
(
'Multiple entities match this reference;'
));
$this
->
assertText
(
t
(
"@node1"
,
[
'@node1'
=>
$node1
->
getTitle
()
.
' ('
.
$node1
->
id
()
.
')'
]));
$this
->
assertText
(
t
(
"@node2"
,
[
'@node2'
=>
$node2
->
getTitle
()
.
' ('
.
$node2
->
id
()
.
')'
]));
$this
->
assertText
(
t
(
'Specify the one you want by appending the id in parentheses, like "@example".'
,
[
'@example'
=>
$node2
->
getTitle
()
.
' ('
.
$node2
->
id
()
.
')'
]));
$edit
=
array
(
'title[0][value]'
=>
'Test'
,
...
...
core/modules/field/tests/src/Kernel/BulkDeleteTest.php
View file @
614ba415
...
...
@@ -210,6 +210,98 @@ function testDeleteField() {
$this
->
assertFalse
(
array_diff
(
$found
,
array_keys
(
$this
->
entities
)));
}
/**
* Tests that recreating a field with the name as a deleted field works.
*/
public
function
testPurgeWithDeletedAndActiveField
()
{
$bundle
=
reset
(
$this
->
bundles
);
// Create another field storage.
$field_name
=
'bf_3'
;
$deleted_field_storage
=
FieldStorageConfig
::
create
(
array
(
'field_name'
=>
$field_name
,
'entity_type'
=>
$this
->
entityTypeId
,
'type'
=>
'test_field'
,
'cardinality'
=>
1
));
$deleted_field_storage
->
save
();
// Create the field.
FieldConfig
::
create
([
'field_storage'
=>
$deleted_field_storage
,
'bundle'
=>
$bundle
,
])
->
save
();
for
(
$i
=
0
;
$i
<
20
;
$i
++
)
{
$entity
=
$this
->
container
->
get
(
'entity_type.manager'
)
->
getStorage
(
$this
->
entityTypeId
)
->
create
(
array
(
'type'
=>
$bundle
));
$entity
->
{
$field_name
}
->
setValue
(
$this
->
_generateTestFieldValues
(
1
));
$entity
->
save
();
}
// Delete the field.
$deleted_field
=
FieldConfig
::
loadByName
(
$this
->
entityTypeId
,
$bundle
,
$field_name
);
$deleted_field
->
delete
();
$deleted_field_uuid
=
$deleted_field
->
uuid
();
// Reload the field storage.
$field_storages
=
entity_load_multiple_by_properties
(
'field_storage_config'
,
array
(
'uuid'
=>
$deleted_field_storage
->
uuid
(),
'include_deleted'
=>
TRUE
));
$deleted_field_storage
=
reset
(
$field_storages
);
// Create the field again.
$field_storage
=
FieldStorageConfig
::
create
(
array
(
'field_name'
=>
$field_name
,
'entity_type'
=>
$this
->
entityTypeId
,
'type'
=>
'test_field'
,
'cardinality'
=>
1
));
$field_storage
->
save
();
FieldConfig
::
create
([
'field_storage'
=>
$field_storage
,
'bundle'
=>
$bundle
,
])
->
save
();
// The field still exists, deleted, with the same field name.
$fields
=
entity_load_multiple_by_properties
(
'field_config'
,
array
(
'uuid'
=>
$deleted_field_uuid
,
'include_deleted'
=>
TRUE
));
$this
->
assertTrue
(
isset
(
$fields
[
$deleted_field_uuid
])
&&
$fields
[
$deleted_field_uuid
]
->
isDeleted
(),
'The field exists and is deleted'
);
$this
->
assertTrue
(
isset
(
$fields
[
$deleted_field_uuid
])
&&
$fields
[
$deleted_field_uuid
]
->
getName
()
==
$field_name
);
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$entity
=
$this
->
container
->
get
(
'entity_type.manager'
)
->
getStorage
(
$this
->
entityTypeId
)
->
create
(
array
(
'type'
=>
$bundle
));
$entity
->
{
$field_name
}
->
setValue
(
$this
->
_generateTestFieldValues
(
1
));
$entity
->
save
();
}
// Check that the two field storages have different tables.
$storage
=
\Drupal
::
entityManager
()
->
getStorage
(
$this
->
entityTypeId
);
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping
=
$storage
->
getTableMapping
();
$deleted_table_name
=
$table_mapping
->
getDedicatedDataTableName
(
$deleted_field_storage
,
TRUE
);
$active_table_name
=
$table_mapping
->
getDedicatedDataTableName
(
$field_storage
);
field_purge_batch
(
50
);
// Ensure the new field still has its table and the deleted one has been
// removed.
$this
->
assertTrue
(
\Drupal
::
database
()
->
schema
()
->
tableExists
(
$active_table_name
));
$this
->
assertFalse
(
\Drupal
::
database
()
->
schema
()
->
tableExists
(
$deleted_table_name
));
// The field has been removed from the system.
$fields
=
entity_load_multiple_by_properties
(
'field_config'
,
array
(
'field_storage_uuid'
=>
$deleted_field_storage
->
uuid
(),
'deleted'
=>
TRUE
,
'include_deleted'
=>
TRUE
));
$this
->
assertEqual
(
count
(
$fields
),
0
,
'The field is gone'
);
// Verify there are still 10 entries in the main table.
$count
=
\Drupal
::
database
()
->
select
(
'entity_test__'
.
$field_name
,
'f'
)
->
fields
(
'f'
,
array
(
'entity_id'
))
->
condition
(
'bundle'
,
$bundle
)
->
countQuery
()
->
execute
()
->
fetchField
();
$this
->
assertEqual
(
$count
,
10
);
}
/**
* Verify that field data items and fields are purged when a field storage is
* deleted.
...
...
core/modules/field/tests/src/Kernel/Migrate/d7/RollbackFieldInstanceTest.php
0 → 100644
View file @
614ba415
<?php
namespace
Drupal\Tests\field\Kernel\Migrate\d7
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\migrate\MigrateExecutable
;
/**
* Migrates and rolls back Drupal 7 fields.
*
* @group field
*/
class
RollbackFieldInstanceTest
extends
MigrateFieldInstanceTest
{
/**
* Tests migrating D7 fields to field_storage_config entities, then rolling back.
*/
public
function
testFieldInstances
()
{
// Test that the field instances have migrated (prior to rollback).
parent
::
testFieldInstances
();
$this
->
executeRollback
(
'd7_field_instance'
);
$this
->
executeRollback
(
'd7_field'
);
// Check that field instances have been rolled back.
$field_instance_ids
=
[
'comment.comment_node_page.comment_body'
,
'node.page.body'
,
'comment.comment_node_article.comment_body'
,
'node.article.body'
,
'node.article.field_tags'
,
'node.article.field_image'
,
'comment.comment_node_blog.comment_body'
,
'node.blog.body'
,
'comment.comment_node_book.comment_body'
,
'node.book.body'
,
'node.forum.taxonomy_forums'
,
'comment.comment_node_forum.comment_body'
,
'node.forum.body'
,
'comment.comment_node_test_content_type.comment_body'
,
'node.test_content_type.field_boolean'
,
'node.test_content_type.field_email'
,
'node.test_content_type.field_phone'
,
'node.test_content_type.field_date'
,
'node.test_content_type.field_date_with_end_time'
,
'node.test_content_type.field_file'
,
'node.test_content_type.field_float'
,
'node.test_content_type.field_images'
,
'node.test_content_type.field_integer'
,
'node.test_content_type.field_link'
,
'node.test_content_type.field_text_list'
,
'node.test_content_type.field_integer_list'
,
'node.test_content_type.field_long_text'
,
'node.test_content_type.field_term_reference'
,
'node.test_content_type.field_text'
,
'comment.comment_node_test_content_type.field_integer'
,
'user.user.field_file'
,
];
foreach
(
$field_instance_ids
as
$field_instance_id
)
{
$this
->
assertNull
(
FieldConfig
::
load
(
$field_instance_id
));
}
}
/**
* Executes a single rollback.
*
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
* The migration to rollback, or its ID.
*/
protected
function
executeRollback
(
$migration
)
{
if
(
is_string
(
$migration
))
{
$this
->
migration
=
$this
->
getMigration
(
$migration
);
}
else
{
$this
->
migration
=
$migration
;
}
(
new
MigrateExecutable
(
$this
->
migration
,
$this
))
->
rollback
();
}
}
core/modules/field/tests/src/Kernel/Migrate/d7/RollbackFieldTest.php
0 → 100644
View file @
614ba415
<?php
namespace
Drupal\Tests\field\Kernel\Migrate\d7
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\migrate\MigrateExecutable
;
/**
* Migrates and rolls back Drupal 7 fields.
*
* @group field
*/
class
RollbackFieldTest
extends
MigrateFieldTest
{
/**
* Tests migrating D7 fields to field_storage_config entities, then rolling back.
*/
public
function
testFields
()
{
// Test that the fields have migrated (prior to rollback).
parent
::
testFields
();
$this
->
executeRollback
(
'd7_field'
);
// Check that fields have been rolled back.
$rolled_back_field_ids
=
[
'comment.field_integer'
,
'node.taxonomy_forums'
,
'node.field_integer'
,
'node.field_tags'
,
'node.field_term_reference'
,
'node.field_text_list'
,
'node.field_text'
,
'node.field_phone'
,
'node.field_file'
,
'node.field_images'
,
'node.field_image'
,
'node.field_long_text'
,
'node.field_date_with_end_time'
,
'node.field_integer_list'
,
'node.field_date'
,
'node.field_link'
,
'node.field_float'
,
'node.field_boolean'
,
'node.field_email'
,
'user.field_file'
,
];
foreach
(
$rolled_back_field_ids
as
$field_id
)
{
$this
->
assertNull
(
FieldStorageConfig
::
load
(
$field_id
));
}
// Check that fields that should persist have not been rolled back.
$non_rolled_back_field_ids
=
[
'node.body'
,
'comment.comment_body'
,
];
foreach
(
$non_rolled_back_field_ids
as
$field_id
)
{
$this
->
assertNotNull
(
FieldStorageConfig
::
load
(
$field_id
));
}
}
/**
* Executes a single rollback.
*
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
* The migration to rollback, or its ID.
*/
protected
function
executeRollback
(
$migration
)
{
if
(
is_string
(
$migration
))
{
$this
->
migration
=
$this
->
getMigration
(
$migration
);
}
else
{
$this
->
migration
=
$migration
;
}
(
new
MigrateExecutable
(
$this
->
migration
,
$this
))
->
rollback
();
}
}
core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php
0 → 100644
View file @
614ba415
<?php
namespace
Drupal\Tests\field\Kernel\Migrate\d7
;
use
Drupal\Core\Entity\Entity\EntityViewMode
;
use
Drupal\migrate\MigrateExecutable
;
/**
* Migrates and rolls back Drupal 7 view modes.
*
* @group field
*/
class
RollbackViewModesTest
extends
MigrateViewModesTest
{
/**
* Tests migrating D7 view modes, then rolling back.
*/
public
function
testMigration
()
{
// Test that the view modes have migrated (prior to rollback).
parent
::
testMigration
();
$this
->
executeRollback
(
'd7_view_modes'
);
// Check that view modes have been rolled back.
$view_mode_ids
=
[
'comment.full'
,
'node.teaser'
,
'node.full'
,
'user.full'
,
];
foreach
(
$view_mode_ids
as
$view_mode_id
)
{
$this
->
assertNull
(
EntityViewMode
::
load
(
$view_mode_id
));
}
}
/**
* Executes a single rollback.
*
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
* The migration to rollback, or its ID.
*/
protected
function
executeRollback
(
$migration
)
{
if
(
is_string
(
$migration
))
{
$this
->
migration
=
$this
->
getMigration
(
$migration
);
}
else
{
$this
->
migration
=
$migration
;
}
(
new
MigrateExecutable
(
$this
->
migration
,
$this
))
->
rollback
();
}
}
core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php
View file @
614ba415
...
...
@@ -81,9 +81,11 @@ public function delete() {
parent
::
delete
();
$entity
=
$this
->
getEntity
();
// Delete all file usages within this entity.
// If a translation is deleted only decrement the file usage by one. If the
// default translation is deleted remove all file usages within this entity.
$count
=
$entity
->
isDefaultTranslation
()
?
0
:
1
;
foreach
(
$this
->
referencedEntities
()
as
$file
)
{
\Drupal
::
service
(
'file.usage'
)
->
delete
(
$file
,
'file'
,
$entity
->
getEntityTypeId
(),
$entity
->
id
(),
0
);
\Drupal
::
service
(
'file.usage'
)
->
delete
(
$file
,
'file'
,
$entity
->
getEntityTypeId
(),
$entity
->
id
(),
$count
);
}
}
...
...
core/modules/file/tests/src/Kernel/UsageTest.php
View file @
614ba415
...
...
@@ -2,6 +2,13 @@
namespace
Drupal\Tests\file\Kernel
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\language\Entity\ConfigurableLanguage
;
use
Drupal\language\Entity\ContentLanguageSettings
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\Entity\NodeType
;
/**
* Tests file usage functions.
*
...
...
@@ -203,4 +210,57 @@ function testTempFileCustomCleanup() {
$this
->
assertTrue
(
file_exists
(
$perm_new
->
getFileUri
()),
'New permanent file was correctly ignored.'
);
}
/**
* Tests file usage with translated entities.
*/
public
function
testFileUsageWithEntityTranslation
()
{
/** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
$file_usage
=
$this
->
container
->
get
(
'file.usage'
);
$this
->
enableModules
([
'node'
,
'language'
]);
$this
->
installEntitySchema
(
'node'
);
$this
->
installSchema
(
'node'
,
[
'node_access'
]);
// Activate English and Romanian languages.
ConfigurableLanguage
::
create
([
'id'
=>
'en'
])
->
save
();
ConfigurableLanguage
::
create
([
'id'
=>
'ro'
])
->
save
();
NodeType
::
create
([
'type'
=>
'page'
])
->
save
();
ContentLanguageSettings
::
loadByEntityTypeBundle
(
'node'
,
'page'
)
->
setLanguageAlterable
(
FALSE
)
->
setDefaultLangcode
(
'en'
)
->
save
();
// Create a file field attached to 'page' node-type.
FieldStorageConfig
::
create
([
'type'
=>
'file'
,
'entity_type'
=>
'node'
,
'field_name'
=>
'file'
,
])
->
save
();
FieldConfig
::
create
([
'entity_type'
=>
'node'
,
'bundle'
=>
'page'
,
'field_name'
=>
'file'
,
'label'
=>
'File'
,
])
->
save
();
// Create a node, attach a file and add a Romanian translation.
$node
=
Node
::
create
([
'type'
=>
'page'
,
'title'
=>
'Page'
]);
$node
->
set
(
'file'
,
$file
=
$this
->
createFile
())
->
addTranslation
(
'ro'
,
$node
->
getTranslation
(
'en'
)
->
toArray
())
->
save
();
// Check that the file is used twice.
$usage
=
$file_usage
->
listUsage
(
$file
);
$this
->
assertEquals
(
2
,
$usage
[
'file'
][
'node'
][
$node
->
id
()]);
// Remove the Romanian translation.
$node
->
removeTranslation
(
'ro'
);
$node
->
save
();
// Check that one usage has been removed and is used only once now.
$usage
=
$file_usage
->
listUsage
(
$file
);
$this
->
assertEquals
(
1
,
$usage
[
'file'
][
'node'
][
$node
->
id
()]);
}
}
core/modules/filter/migration_templates/d6_filter_format.yml
View file @
614ba415
...
...
@@ -16,11 +16,16 @@ process:
key
:
'
@id'
process
:
id
:
plugin
:
static_map
default_value
:
filter_null
# If the filter ID cannot be mapped, it will be passed through
# unchanged because the bypass flag is set. The filter_id plugin
# will flatten the input value and default it to filter_null (the
# fallback filter plugin ID) if the flattened input value is not
# a valid plugin ID.
plugin
:
filter_id
source
:
-
module
-
delta
bypass
:
true
map
:
filter
:
-
filter_html
...
...
core/modules/filter/migration_templates/d7_filter_format.yml
View file @
614ba415
...
...
@@ -15,11 +15,16 @@ process:
key
:
'
@id'
process
:
id
:
plugin
:
static_map
# If the filter ID cannot be mapped, it will pass through unmodified
# because the bypass flag is set. When the user actually tries to
# view text through an invalid filter plugin, the filter system will
# fall back to filter_null and display a helpful error message.
plugin
:
filter_id
bypass
:
true
source
:
name
map
:
php_code
:
filter_null
# No need to map anything -- filter plugin IDs haven't changed since
# Drupal 7.
map
:
{
}
settings
:
plugin
:
filter_settings
source
:
settings
...
...
core/modules/filter/src/Plugin/migrate/process/FilterID.php
0 → 100644
View file @
614ba415
<?php
namespace
Drupal\filter\Plugin\migrate\process
;
use
Drupal\Component\Plugin\PluginManagerInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\StringTranslation\TranslationInterface
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\Plugin\migrate\process\StaticMap
;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\Row
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* @MigrateProcessPlugin(
* id = "filter_id"
* )
*/
class
FilterID
extends
StaticMap
implements
ContainerFactoryPluginInterface
{
/**
* The filter plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface|\Drupal\Component\Plugin\FallbackPluginManagerInterface
*/
protected
$filterManager
;
/**
* FilterID constructor.
*
* @param array $configuration
* Plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\Component\Plugin\PluginManagerInterface $filter_manager
* The filter plugin manager.
* @param TranslationInterface $translator
* (optional) The string translation service.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
PluginManagerInterface
$filter_manager
,
TranslationInterface
$translator
=
NULL
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
filterManager
=
$filter_manager
;
$this
->
stringTranslation
=
$translator
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'plugin.manager.filter'
),
$container
->
get
(
'string_translation'
)
);
}
/**
* {@inheritdoc}
*/
public
function
transform
(
$value
,
MigrateExecutableInterface
$migrate_executable
,
Row
$row
,
$destination_property
)
{
$plugin_id
=
parent
::
transform
(
$value
,
$migrate_executable
,
$row
,
$destination_property
);
// If the static map is bypassed on failure, the returned plugin ID will be
// an array if $value was. Plugin IDs cannot be arrays, so flatten it before
// passing it into the filter manager.
if
(
is_array
(
$plugin_id
))
{
$plugin_id
=
implode
(
':'
,
$plugin_id
);
}
if
(
$this
->
filterManager
->
hasDefinition
(
$plugin_id
))
{
return
$plugin_id
;
}
else
{
$fallback
=
$this
->
filterManager
->
getFallbackPluginId
(
$plugin_id
);
$message
=
$this
->
t
(
'Filter @plugin_id could not be mapped to an existing filter plugin; defaulting to @fallback.'
,
[
'@plugin_id'
=>
$plugin_id
,
'@fallback'
=>
$fallback
,
]);
$migrate_executable
->
saveMessage
((
string
)
$message
,
MigrationInterface
::
MESSAGE_WARNING
);
return
$fallback
;
}
}
}
core/modules/filter/tests/src/Kernel/Migrate/d6/MigrateFilterFormatTest.php
View file @
614ba415
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\Tests\filter\Kernel\Migrate\d6
;
use
Drupal\filter\Entity\FilterFormat
;
use
Drupal\filter\FilterFormatInterface
;
use
Drupal\Tests\migrate_drupal
\Kernel\d6\MigrateDrupal6TestBase
;
/**
...
...
@@ -39,14 +40,18 @@ public function testFilterFormat() {
$this
->
assertFalse
(
isset
(
$filters
[
'filter_html_image_secure'
]));
// Check variables migrated into filter.
$this
->
assertIdentical
(
'<a href hreflang> <em> <strong> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>'
,
$filters
[
'filter_html'
][
'settings'
][
'allowed_html'
]);
$this
->
assertIdentical
(
TRUE
,
$filters
[
'filter_html'
][
'settings'
][
'filter_html_help'
]);
$this
->
assertIdentical
(
FALSE
,
$filters
[
'filter_html'
][
'settings'
][
'filter_html_nofollow'
]);
$this
->
assertIdentical
(
72
,
$filters
[
'filter_url'
][
'settings'
][
'filter_url_length'
]);
// Check that the PHP code filter is converted to filter_null.
$filters
=
FilterFormat
::
load
(
'php_code'
)
->
get
(
'filters'
);
$this
->
assertTrue
(
isset
(
$filters
[
'filter_null'
]));
$this
->
assertSame
(
'<a href hreflang> <em> <strong> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>'
,
$filters
[
'filter_html'
][
'settings'
][
'allowed_html'
]);
$this
->
assertSame
(
TRUE
,
$filters
[
'filter_html'
][
'settings'
][
'filter_html_help'
]);
$this
->
assertSame
(
FALSE
,
$filters
[
'filter_html'
][
'settings'
][
'filter_html_nofollow'
]);
$this
->
assertSame
(
72
,
$filters
[
'filter_url'
][
'settings'
][
'filter_url_length'
]);
// Assert that the php_code format was migrated with filter_null in the
// php_code filter's place.
$filter_format
=
FilterFormat
::
load
(
'php_code'
);
$this
->
assertInstanceOf
(
FilterFormatInterface
::
class
,
$filter_format
);
$filters
=
$filter_format
->
get
(
'filters'
);
$this
->
assertArrayHasKey
(
'filter_null'
,
$filters
);
$this
->
assertArrayNotHasKey
(
'php_code'
,
$filters
);
}
}
core/modules/filter/tests/src/Kernel/Migrate/d7/MigrateFilterFormatTest.php
View file @
614ba415
...
...
@@ -42,13 +42,13 @@ protected function setUp() {
protected
function
assertEntity
(
$id
,
$label
,
array
$enabled_filters
,
$weight
)
{
/** @var \Drupal\filter\FilterFormatInterface $entity */
$entity
=
FilterFormat
::
load
(
$id
);
$this
->
assert
True
(
$entity
i
nstance
of
FilterFormatInterface
);
$this
->
assert
Identical
(
$label
,
$entity
->
label
());
$this
->
assert
I
nstance
Of
(
FilterFormatInterface
::
class
,
$entity
);
$this
->
assert
Same
(
$label
,
$entity
->
label
());
// get('filters') will return enabled filters only, not all of them.
$this
->
assert
Identical
(
array_keys
(
$enabled_filters
),
array_keys
(
$entity
->
get
(
'filters'
)));
$this
->
assert
Identical
(
$weight
,
$entity
->
get
(
'weight'
));
$this
->
assert
Same
(
array_keys
(
$enabled_filters
),
array_keys
(
$entity
->
get
(
'filters'
)));
$this
->
assert
Same
(
$weight
,
$entity
->
get
(
'weight'
));
foreach
(
$entity
->
get
(
'filters'
)
as
$filter_id
=>
$filter
)
{
$this
->
assert
Identical
(
$filter
[
'weight'
],
$enabled_filters
[
$filter_id
]);
$this
->
assert
Same
(
$filter
[
'weight'
],
$enabled_filters
[
$filter_id
]);
}
}
...
...
@@ -68,15 +68,17 @@ public function testFilterFormat() {
// Ensure that filter-specific settings were migrated.
/** @var \Drupal\filter\FilterFormatInterface $format */
$format
=
FilterFormat
::
load
(
'filtered_html'
);
$this
->
assertInstanceOf
(
FilterFormatInterface
::
class
,
$format
);
$config
=
$format
->
filters
(
'filter_html'
)
->
getConfiguration
();
$this
->
assert
Identical
(
'<div> <span> <ul type> <li> <ol start type> <a href hreflang> <img src alt height width>'
,
$config
[
'settings'
][
'allowed_html'
]);
$this
->
assert
Same
(
'<div> <span> <ul type> <li> <ol start type> <a href hreflang> <img src alt height width>'
,
$config
[
'settings'
][
'allowed_html'
]);
$config
=
$format
->
filters
(
'filter_url'
)
->
getConfiguration
();
$this
->
assert
Identical
(
128
,
$config
[
'settings'
][
'filter_url_length'
]);
$this
->
assert
Same
(
128
,
$config
[
'settings'
][
'filter_url_length'
]);
// The php_code format gets migrated, but the php_code filter is changed to
// filter_null.
$filters
=
FilterFormat
::
load
(
'php_code'
)
->
get
(
'filters'
);
$this
->
assertTrue
(
isset
(
$filters
[
'filter_null'
]));
$format
=
FilterFormat
::
load
(
'php_code'
);
$this
->
assertInstanceOf
(
FilterFormatInterface
::
class
,
$format
);
$this
->
assertArrayHasKey
(
'filter_null'
,
$format
->
get
(
'filters'
));
}
}
core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterIdTest.php
0 → 100644
View file @
614ba415
<?php
namespace
Drupal\Tests\filter\Kernel\Plugin\migrate\process
;
use
Drupal\filter\Plugin\migrate\process\FilterID
;
use
Drupal\KernelTests\KernelTestBase
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\Row
;
/**
* Unit tests of the filter_id plugin.
*
* @coversDefaultClass \Drupal\filter\Plugin\migrate\process\FilterID
* @group filter
*/
class
FilterIdTest
extends
KernelTestBase
{
/**
* {@inheritdoc}
*/
public
static
$modules
=
[
'filter'
];
/**
* The mocked MigrateExecutable.
*
* @var MigrateExecutableInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected
$executable
;
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
executable
=
$this
->
getMock
(
MigrateExecutableInterface
::
class
);
}
/**
* Tests the filter_id plugin.
*
* @param mixed $value
* The input value to the plugin.
* @param string $expected_value
* The output value expected from the plugin.
* @param string $invalid_id
* (optional) The invalid plugin ID which is expected to be logged by the
* MigrateExecutable object.
*
* @dataProvider testProvider
*
* @covers ::transform
*/
public
function
test
(
$value
,
$expected_value
,
$invalid_id
=
NULL
)
{
$configuration
=
[
'bypass'
=>
TRUE
,
'map'
=>
[
'foo'
=>
'filter_html'
,
'baz'
=>
'php_code'
,
],
];
$plugin
=
FilterID
::
create
(
$this
->
container
,
$configuration
,
'filter_id'
,
[]);
if
(
isset
(
$invalid_id
))
{
$this
->
executable
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'saveMessage'
)
->
with
(
'Filter '
.
$invalid_id
.
' could not be mapped to an existing filter plugin; defaulting to filter_null.'
,
MigrationInterface
::
MESSAGE_WARNING
);
}
$row
=
new
Row
([],
[]);
$output_value
=
$plugin
->
transform
(
$value
,
$this
->
executable
,
$row
,
'foo'
);
$this
->
assertSame
(
$expected_value
,
$output_value
);
}
/**
* The test data provider.
*
* @return array
*/
public
function
testProvider
()
{
return
[
// The filter ID is mapped, and the plugin exists.
[
'foo'
,
'filter_html'
,
],
// The filter ID isn't mapped, but it's unchanged from the source (i.e.,
// it bypasses the static map) and the plugin exists.
[
'filter_html'
,
'filter_html'
,
],
// The filter ID is mapped, but the plugin does not exist.
[
'baz'
,
'filter_null'
,
'php_code'
,
],
// The filter ID isn't mapped, but it's unchanged from the source (i.e.,
// it bypasses the static map) but the plugin does not exist.
[
'php_code'
,
'filter_null'
,
'php_code'
,
],
[
[
'filter'
,
1
],
'filter_null'
,
'filter:1'
,
],
];
}
}
core/modules/image/src/ImageStyleListBuilder.php
View file @
614ba415
...
...
@@ -4,10 +4,7 @@
use
Drupal\Core\Config\Entity\ConfigEntityListBuilder
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Routing\UrlGeneratorInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\Url
;
/**
* Defines a class to build a listing of image style entities.
...
...
@@ -16,40 +13,6 @@
*/
class
ImageStyleListBuilder
extends
ConfigEntityListBuilder
{
/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected
$urlGenerator
;
/**
* Constructs a new ImageStyleListBuilder object.
*
* @param EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage
* The image style entity storage class.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The URL generator.
*/
public
function
__construct
(
EntityTypeInterface
$entity_type
,
EntityStorageInterface
$image_style_storage
,
UrlGeneratorInterface
$url_generator
)
{
parent
::
__construct
(
$entity_type
,
$image_style_storage
);
$this
->
urlGenerator
=
$url_generator
;
}
/**
* {@inheritdoc}
*/
public
static
function
createInstance
(
ContainerInterface
$container
,
EntityTypeInterface
$entity_type
)
{
return
new
static
(
$entity_type
,
$container
->
get
(
'entity.manager'
)
->
getStorage
(
$entity_type
->
id
()),
$container
->
get
(
'url_generator'
),
$container
->
get
(
'string_translation'
)
);
}
/**
* {@inheritdoc}
*/
...
...
@@ -87,7 +50,7 @@ public function getDefaultOperations(EntityInterface $entity) {
public
function
render
()
{
$build
=
parent
::
render
();
$build
[
'table'
][
'#empty'
]
=
$this
->
t
(
'There are currently no styles. <a href=":url">Add a new one</a>.'
,
[
':url'
=>
$this
->
urlGenerator
->
generateF
romRoute
(
'image.style_add'
),
':url'
=>
Url
::
f
romRoute
(
'image.style_add'
)
->
toString
()
,
]);
return
$build
;
}
...
...
core/modules/migrate/src/Plugin/MigratePluginManager.php
View file @
614ba415
...
...
@@ -21,7 +21,7 @@
*
* @ingroup migration
*/
class
MigratePluginManager
extends
DefaultPluginManager
{
class
MigratePluginManager
extends
DefaultPluginManager
implements
MigratePluginManagerInterface
{
/**
* Constructs a MigratePluginManager object.
...
...
@@ -49,8 +49,6 @@ public function __construct($type, \Traversable $namespaces, CacheBackendInterfa
/**
* {@inheritdoc}
*
* A specific createInstance method is necessary to pass the migration on.
*/
public
function
createInstance
(
$plugin_id
,
array
$configuration
=
array
(),
MigrationInterface
$migration
=
NULL
)
{
$plugin_definition
=
$this
->
getDefinition
(
$plugin_id
);
...
...
core/modules/migrate/src/Plugin/MigratePluginManagerInterface.php
0 → 100644
View file @
614ba415
<?php
namespace
Drupal\migrate\Plugin
;
use
Drupal\Component\Plugin\PluginManagerInterface
;
interface
MigratePluginManagerInterface
extends
PluginManagerInterface
{
/**
* Creates a pre-configured instance of a migration plugin.
*
* A specific createInstance method is necessary to pass the migration on.
*
* @param string $plugin_id
* The ID of the plugin being instantiated.
* @param array $configuration
* An array of configuration relevant to the plugin instance.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration context in which the plugin will run.
*
* @return object
* A fully configured plugin instance.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
* If the instance cannot be created, such as if the ID is invalid.
*/
public
function
createInstance
(
$plugin_id
,
array
$configuration
=
[],
MigrationInterface
$migration
=
NULL
);
}
core/modules/migrate/src/Plugin/Migration.php
View file @
614ba415
...
...
@@ -268,16 +268,16 @@ class Migration extends PluginBase implements MigrationInterface, RequirementsIn
* The plugin definition.
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
* The migration plugin manager.
* @param \Drupal\migrate\Plugin\MigratePluginManager $source_plugin_manager
* @param \Drupal\migrate\Plugin\MigratePluginManager
Interface
$source_plugin_manager
* The source migration plugin manager.
* @param \Drupal\migrate\Plugin\MigratePluginManager $process_plugin_manager
* @param \Drupal\migrate\Plugin\MigratePluginManager
Interface
$process_plugin_manager
* The process migration plugin manager.
* @param \Drupal\migrate\Plugin\MigrateDestinationPluginManager $destination_plugin_manager
* The destination migration plugin manager.
* @param \Drupal\migrate\Plugin\MigratePluginManager $idmap_plugin_manager
* @param \Drupal\migrate\Plugin\MigratePluginManager
Interface
$idmap_plugin_manager
* The ID map migration plugin manager.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
MigrationPluginManagerInterface
$migration_plugin_manager
,
MigratePluginManager
$source_plugin_manager
,
MigratePluginManager
$process_plugin_manager
,
MigrateDestinationPluginManager
$destination_plugin_manager
,
MigratePluginManager
$idmap_plugin_manager
)
{
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
MigrationPluginManagerInterface
$migration_plugin_manager
,
MigratePluginManager
Interface
$source_plugin_manager
,
MigratePluginManager
Interface
$process_plugin_manager
,
MigrateDestinationPluginManager
$destination_plugin_manager
,
MigratePluginManager
Interface
$idmap_plugin_manager
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
migrationPluginManager
=
$migration_plugin_manager
;
$this
->
sourcePluginManager
=
$source_plugin_manager
;
...
...
core/modules/migrate/src/Plugin/migrate/destination/EntityFieldInstance.php
View file @
614ba415
...
...
@@ -21,4 +21,12 @@ public function getIds() {
return
$ids
;
}
/**
* {@inheritdoc}
*/
public
function
rollback
(
array
$destination_identifier
)
{
$destination_identifier
=
implode
(
'.'
,
$destination_identifier
);
parent
::
rollback
(
array
(
$destination_identifier
));
}
}
core/modules/migrate/src/Plugin/migrate/destination/EntityFieldStorageConfig.php
View file @
614ba415
...
...
@@ -20,4 +20,12 @@ public function getIds() {
return
$ids
;
}
/**
* {@inheritdoc}
*/
public
function
rollback
(
array
$destination_identifier
)
{
$destination_identifier
=
implode
(
'.'
,
$destination_identifier
);
parent
::
rollback
(
array
(
$destination_identifier
));
}
}
core/modules/migrate/src/Plugin/migrate/destination/EntityViewMode.php
View file @
614ba415
...
...
@@ -20,4 +20,12 @@ public function getIds() {
return
$ids
;
}
/**
* {@inheritdoc}
*/
public
function
rollback
(
array
$destination_identifier
)
{
$destination_identifier
=
implode
(
'.'
,
$destination_identifier
);
parent
::
rollback
(
array
(
$destination_identifier
));
}
}
Prev
1
2
3
4
Next