Skip to content
GitLab
Explore
Sign in
project
drupal
Compare revisions
540a5f41541a3109995104e90720580e350ed433 to 8.1.x
Hide whitespace changes
Inline
Side-by-side
core/modules/comment/tests/src/Functional/CommentStatusFieldAccessTest.php
0 → 100644
View file @
614ba415
<?php
namespace
Drupal\Tests\comment\Functional
;
use
Drupal\comment\Tests\CommentTestTrait
;
use
Drupal\node\Entity\NodeType
;
use
Drupal\Tests\BrowserTestBase
;
/**
* Tests comment status field access.
*
* @group comment
*/
class
CommentStatusFieldAccessTest
extends
BrowserTestBase
{
use
CommentTestTrait
;
/**
* {@inheritdoc}
*/
public
$profile
=
'testing'
;
/**
* Comment admin.
*
* @var \Drupal\user\UserInterface
*/
protected
$commentAdmin
;
/**
* Node author.
*
* @var \Drupal\user\UserInterface
*/
protected
$nodeAuthor
;
/**
* {@inheritdoc}
*/
public
static
$modules
=
[
'node'
,
'comment'
,
'user'
,
'system'
,
'text'
,
];
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$node_type
=
NodeType
::
create
([
'type'
=>
'article'
,
'name'
=>
t
(
'Article'
),
]);
$node_type
->
save
();
$this
->
nodeAuthor
=
$this
->
drupalCreateUser
([
'create article content'
,
'skip comment approval'
,
'post comments'
,
'edit own comments'
,
'access comments'
,
'administer nodes'
,
]);
$this
->
commentAdmin
=
$this
->
drupalCreateUser
([
'administer comments'
,
'create article content'
,
'edit own comments'
,
'skip comment approval'
,
'post comments'
,
'access comments'
,
'administer nodes'
,
]);
$this
->
addDefaultCommentField
(
'node'
,
'article'
);
}
/**
* Tests comment status field access.
*/
public
function
testCommentStatusFieldAccessStatus
()
{
$this
->
drupalLogin
(
$this
->
nodeAuthor
);
$this
->
drupalGet
(
'node/add/article'
);
$assert
=
$this
->
assertSession
();
$assert
->
fieldNotExists
(
'comment[0][status]'
);
$this
->
submitForm
([
'title[0][value]'
=>
'Node 1'
,
],
t
(
'Save and publish'
));
$assert
->
fieldExists
(
'subject[0][value]'
);
$this
->
drupalLogin
(
$this
->
commentAdmin
);
$this
->
drupalGet
(
'node/add/article'
);
$assert
->
fieldExists
(
'comment[0][status]'
);
$this
->
submitForm
([
'title[0][value]'
=>
'Node 2'
,
],
t
(
'Save and publish'
));
$assert
->
fieldExists
(
'subject[0][value]'
);
}
}
core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php
View file @
614ba415
...
...
@@ -40,7 +40,7 @@ protected function setUp() {
),
));
$this
->
executeMigrations
([
'd7_node
:test_content_type
'
,
'd7_node'
,
'd7_comment_type'
,
'd7_comment'
,
]);
...
...
core/modules/config/config.module
View file @
614ba415
...
...
@@ -65,14 +65,17 @@ function config_file_download($uri) {
$scheme
=
file_uri_scheme
(
$uri
);
$target
=
file_uri_target
(
$uri
);
if
(
$scheme
==
'temporary'
&&
$target
==
'config.tar.gz'
)
{
$request
=
\Drupal
::
request
();
$date
=
DateTime
::
createFromFormat
(
'U'
,
$request
->
server
->
get
(
'REQUEST_TIME'
));
$date_string
=
$date
->
format
(
'Y-m-d-H-i'
);
$hostname
=
str_replace
(
'.'
,
'-'
,
$request
->
getHttpHost
());
$filename
=
'config'
.
'-'
.
$hostname
.
'-'
.
$date_string
.
'.tar.gz'
;
$disposition
=
'attachment; filename="'
.
$filename
.
'"'
;
return
array
(
'Content-disposition'
=>
$disposition
,
);
if
(
\Drupal
::
currentUser
()
->
hasPermission
(
'export configuration'
))
{
$request
=
\Drupal
::
request
();
$date
=
DateTime
::
createFromFormat
(
'U'
,
$request
->
server
->
get
(
'REQUEST_TIME'
));
$date_string
=
$date
->
format
(
'Y-m-d-H-i'
);
$hostname
=
str_replace
(
'.'
,
'-'
,
$request
->
getHttpHost
());
$filename
=
'config'
.
'-'
.
$hostname
.
'-'
.
$date_string
.
'.tar.gz'
;
$disposition
=
'attachment; filename="'
.
$filename
.
'"'
;
return
array
(
'Content-disposition'
=>
$disposition
,
);
}
return
-
1
;
}
}
core/modules/config/src/StorageReplaceDataWrapper.php
View file @
614ba415
...
...
@@ -44,6 +44,7 @@ class StorageReplaceDataWrapper implements StorageInterface {
public
function
__construct
(
StorageInterface
$storage
,
$collection
=
StorageInterface
::
DEFAULT_COLLECTION
)
{
$this
->
storage
=
$storage
;
$this
->
collection
=
$collection
;
$this
->
replacementData
[
$collection
]
=
[];
}
/**
...
...
@@ -104,7 +105,7 @@ public function rename($name, $new_name) {
$this
->
replacementData
[
$this
->
collection
][
$new_name
]
=
$this
->
replacementData
[
$this
->
collection
][
$name
];
unset
(
$this
->
replacementData
[
$this
->
collection
][
$name
]);
}
return
$this
->
rename
(
$name
,
$new_name
);
return
$this
->
storage
->
rename
(
$name
,
$new_name
);
}
/**
...
...
@@ -164,8 +165,10 @@ public function deleteAll($prefix = '') {
* {@inheritdoc}
*/
public
function
createCollection
(
$collection
)
{
$this
->
collection
=
$collection
;
return
$this
->
storage
->
createCollection
(
$collection
);
return
new
static
(
$this
->
storage
->
createCollection
(
$collection
),
$collection
);
}
/**
...
...
core/modules/config/src/Tests/ConfigExportUITest.php
View file @
614ba415
...
...
@@ -88,6 +88,12 @@ function testExport() {
// Check the single export form doesn't have "form-required" elements.
$this
->
drupalGet
(
'admin/config/development/configuration/single/export'
);
$this
->
assertNoRaw
(
'js-form-required form-required'
,
'No form required fields are found.'
);
// Ensure the temporary file is not available to users without the
// permission.
$this
->
drupalLogout
();
$this
->
drupalGet
(
'system/temporary'
,
[
'query'
=>
[
'file'
=>
'config.tar.gz'
]]);
$this
->
assertResponse
(
403
);
}
}
core/modules/config/src/Tests/ConfigSingleImportExportTest.php
View file @
614ba415
...
...
@@ -20,7 +20,10 @@ class ConfigSingleImportExportTest extends WebTestBase {
public
static
$modules
=
[
'block'
,
'config'
,
'config_test'
'config_test'
,
// Adding language module makes it possible to involve non-default
// (language.xx) collections in import/export operations.
'language'
,
];
protected
function
setUp
()
{
...
...
core/modules/field/src/Plugin/migrate/process/FieldType.php
View file @
614ba415
...
...
@@ -3,12 +3,12 @@
namespace
Drupal\field\Plugin\migrate\process
;
use
Drupal\Component\Plugin\Exception\PluginNotFoundException
;
use
Drupal\Component\Plugin\PluginManagerInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\Plugin\migrate\process\StaticMap
;
use
Drupal\migrate\Row
;
use
Drupal\migrate_drupal
\Plugin\MigrateCckFieldPluginManagerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
...
...
@@ -21,7 +21,7 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
/**
* The cckfield plugin manager.
*
* @var \Drupal\
Component\Plugin\
PluginManagerInterface
* @var \Drupal\
migrate_drupal\Plugin\MigrateCckField
PluginManagerInterface
*/
protected
$cckPluginManager
;
...
...
@@ -41,12 +41,12 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\
Component\Plugin\
PluginManagerInterface $cck_plugin_manager
* @param \Drupal\
migrate_drupal\Plugin\MigrateCckField
PluginManagerInterface $cck_plugin_manager
* The cckfield plugin manager.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration being run.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
PluginManagerInterface
$cck_plugin_manager
,
MigrationInterface
$migration
=
NULL
)
{
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
MigrateCckField
PluginManagerInterface
$cck_plugin_manager
,
MigrationInterface
$migration
=
NULL
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
cckPluginManager
=
$cck_plugin_manager
;
$this
->
migration
=
$migration
;
...
...
@@ -72,7 +72,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$field_type
=
is_array
(
$value
)
?
$value
[
0
]
:
$value
;
try
{
return
$this
->
cckPluginManager
->
createInstance
(
$field_type
,
[],
$this
->
migration
)
->
getFieldType
(
$row
);
$plugin_id
=
$this
->
cckPluginManager
->
getPluginIdFromFieldType
(
$field_type
,
[],
$this
->
migration
);
return
$this
->
cckPluginManager
->
createInstance
(
$plugin_id
,
[],
$this
->
migration
)
->
getFieldType
(
$row
);
}
catch
(
PluginNotFoundException
$e
)
{
return
parent
::
transform
(
$value
,
$migrate_executable
,
$row
,
$destination_property
);
...
...
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'
,
],
];
}
}
Prev
1
2
3
4
5
6
Next