Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
0904d377
Commit
0904d377
authored
4 months ago
by
Víctor Dorado
Browse files
Options
Downloads
Patches
Plain Diff
Add a test
parent
e238ec6b
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!8223
Issue #3450772: Media items created via the media library widget should have...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
+85
-0
85 additions, 0 deletions
...brary/tests/src/FunctionalJavascript/WidgetUploadTest.php
with
85 additions
and
0 deletions
core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
+
85
−
0
View file @
0904d377
...
...
@@ -5,6 +5,7 @@
namespace
Drupal\Tests\media_library\FunctionalJavascript
;
use
Drupal\media\Entity\Media
;
use
Drupal\Tests\content_translation
\Traits\ContentTranslationTestTrait
;
use
Drupal\Tests\TestFileCreationTrait
;
/**
...
...
@@ -18,6 +19,12 @@
class
WidgetUploadTest
extends
MediaLibraryTestBase
{
use
TestFileCreationTrait
;
use
ContentTranslationTestTrait
;
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'language'
,
'content_translation'
];
/**
* {@inheritdoc}
...
...
@@ -365,6 +372,84 @@ public function testWidgetUpload(): void {
$assert_session
->
fieldValueEquals
(
'Alternative text'
,
''
,
$media_item_three
);
}
/**
* Tests created medias have the same language as the edited translation.
*/
public
function
testWidgetUploadMediaLanguage
():
void
{
// Retrieve a test image file.
foreach
(
$this
->
getTestFiles
(
'image'
)
as
$image
)
{
$extension
=
pathinfo
(
$image
->
filename
,
PATHINFO_EXTENSION
);
if
(
$extension
===
'png'
)
{
$png_image
=
$image
;
}
}
if
(
!
isset
(
$png_image
))
{
$this
->
fail
(
'Expected test file not present.'
);
}
// Setup languages.
static
::
createLanguageFromLangcode
(
'es'
);
$this
->
container
->
get
(
'config.factory'
)
->
getEditable
(
'language.negotiation'
)
->
set
(
'url.source'
,
'path_prefix'
)
->
set
(
'url.prefixes.es'
,
'es'
)
->
save
();
$this
->
enableContentTranslation
(
'node'
,
'basic_page'
);
// Create a user that can create medias and translate entities.
$user
=
$this
->
drupalCreateUser
([
'access administration pages'
,
'access content'
,
'create basic_page content'
,
'edit any basic_page content'
,
'create media'
,
'view media'
,
'translate any entity'
,
]);
$this
->
drupalLogin
(
$user
);
// Create a basic page.
$node
=
$this
->
drupalCreateNode
([
'type'
=>
'basic_page'
,
'title'
=>
'Test node'
,
'langcode'
=>
'en'
,
]);
// Check translation add form.
$this
->
drupalGet
(
'node/'
.
$node
->
id
()
.
'/translations/add/en/es'
);
// Open the media library and upload a file.
$this
->
openMediaLibraryForField
(
'field_unlimited_media'
);
$this
->
switchToMediaType
(
'Three'
);
$this
->
addMediaFileToField
(
'Add files'
,
$this
->
container
->
get
(
'file_system'
)
->
realpath
(
$png_image
->
uri
));
$this
->
assertMediaAdded
();
$this
->
waitForFieldExists
(
'Alternative text'
)
->
setValue
(
$this
->
randomString
());
$this
->
pressSaveButton
();
// Check that the created media item has the same language
// as the translation being created.
$media_items
=
Media
::
loadMultiple
();
$added_media
=
array_pop
(
$media_items
);
$this
->
assertEquals
(
'es'
,
$added_media
->
language
()
->
getId
());
$this
->
pressInsertSelected
();
// Press save button on node edit form page
$this
->
submitForm
([],
'Save (this translation)'
);
$this
->
waitForText
(
'has been updated'
);
// Check translation edit form.
$this
->
drupalGet
(
'es/node/'
.
$node
->
id
()
.
'/edit'
);
// Open the media library and upload a file.
$this
->
openMediaLibraryForField
(
'field_unlimited_media'
);
$this
->
switchToMediaType
(
'Three'
);
$this
->
addMediaFileToField
(
'Add files'
,
$this
->
container
->
get
(
'file_system'
)
->
realpath
(
$png_image
->
uri
));
$this
->
assertMediaAdded
();
$this
->
waitForFieldExists
(
'Alternative text'
)
->
setValue
(
$this
->
randomString
());
$this
->
pressSaveButton
();
// Check that the created media item has the same language
// as the translation being edited.
$media_items
=
Media
::
loadMultiple
();
$added_media
=
array_pop
(
$media_items
);
$this
->
assertEquals
(
'es'
,
$added_media
->
language
()
->
getId
());
}
/**
* Tests that uploads in the widget's advanced UI works as expected.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment