Skip to content
Snippets Groups Projects
Unverified Commit fa32497e authored by Abhishek Lal B's avatar Abhishek Lal B Committed by GitHub
Browse files

WIDEN-222: Image style options for embed codes (#113)

* WIDEN-222: Embedcode for the image.

* WIDEN-113: fixing tests.

* WIDEN-222: Adding the docs.

* WIDEN-22: fixing the test.

* WIDEN-222: Fixing the test.
parent 114c617b
No related branches found
Tags 1.0.0
No related merge requests found
......@@ -8,6 +8,7 @@ use Drupal\Core\Link;
use Drupal\Core\Render\Markup;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Url;
use Drupal\image\Entity\ImageStyle;
use Drupal\media\MediaInterface;
/**
......@@ -29,6 +30,11 @@ final class EmbedCodeFactory implements TrustedCallbackInterface {
// https://www.drupal.org/project/drupal/issues/2984272 Core issue where
// "." in the query parameter gets replaced with "_" so the url with
// "t.download=true" will be replaced with "t_download=true".
$image_styles = [];
foreach (ImageStyle::loadMultiple() as $styles) {
$image_styles[$styles->id()] = $styles->label();
}
$image_styles = ['original' => 'Original'] + $image_styles;
$mapping = [
'pdf' => [
'inline_view_download' => 'Inline viewer with download',
......@@ -49,9 +55,7 @@ final class EmbedCodeFactory implements TrustedCallbackInterface {
'inline_view' => 'Inline viewer without download',
'link_text' => 'Text linked to viewer without download',
],
'image' => [
'original' => 'Original',
],
'image' => $image_styles,
'documents' => [
'inline_view_download' => 'Inline viewer with download',
'link_text_download' => 'Text linked to viewer with download',
......
......@@ -90,6 +90,9 @@ abstract class AcquiaDamWebDriverTestBase extends WebDriverTestBase {
],
])->save();
$this->drupalCreateContentType(['type' => 'page']);
// Suppressing itok to make the image style URLs easier to test.
$config = $this->config('image.settings');
$config->set('suppress_itok_output', TRUE)->save();
}
......
......@@ -9,6 +9,7 @@ use Drupal\acquia_dam\Entity\MediaEmbedsField;
use Drupal\acquia_dam\Entity\MediaSourceField;
use Drupal\Core\Url;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
use Drupal\media\Entity\Media;
use Drupal\media\MediaInterface;
use Drupal\Tests\ckeditor\Traits\CKEditorTestTrait;
......@@ -62,6 +63,9 @@ class MediaLibraryIntegrationTest extends AcquiaDamWebDriverTestBase {
* @dataProvider assetProvider
*/
public function testEditorMediaLibrary(string $asset_type, string $asset_id, int $asset_count, string $format): void {
if ($asset_type === 'Image') {
$this->overwriteImageSettings();
}
$this->createAndLoginContentCreator();
$this->grantSiteRegistrationToken();
$this->grantCurrentUserDamToken();
......@@ -121,6 +125,7 @@ class MediaLibraryIntegrationTest extends AcquiaDamWebDriverTestBase {
2,
'link_text_download',
],
['Image', '56ff14de-02cd-41b5-9a73-c917eab19abf', 3, 'large'],
];
}
......@@ -501,6 +506,12 @@ class MediaLibraryIntegrationTest extends AcquiaDamWebDriverTestBase {
'link_text_download',
'<a href="https://laser.widen.net/view/pdf/rfnwimkigc/Best-Practice---Content-Architecture---v2.1.pptx?t.download=true&amp;u=t3nxzh" target="_blank">Best Practice - Content Architecture - v2.1.pptx</a>',
];
yield 'Image: Large' => [
'56ff14de-02cd-41b5-9a73-c917eab19abf',
'Image',
'large',
'<img src="https://laser.widen.net/content/9e4e810c-147b-4ac2-85a9-cf64f8fa61e0/web/Wheel%20Illustration.ai?w=480&amp;h=480" width="157" height="120" alt="Wheel Illustration.ai" loading="lazy" class="image-style-large">',
];
}
/**
......@@ -1060,7 +1071,7 @@ class MediaLibraryIntegrationTest extends AcquiaDamWebDriverTestBase {
}
/**
* Tests reseting the media library filter.
* Tests resetting the media library filter.
*/
public function testEditorMediaLibraryFilterReset(): void {
$this->createAndLoginContentCreator();
......@@ -1088,6 +1099,41 @@ class MediaLibraryIntegrationTest extends AcquiaDamWebDriverTestBase {
self::assertEquals($modal->findField('Search')->getValue(), '');
}
/**
* Tests to check the image assets embed code is image style.
*/
public function testMediaLibraryImageAssetEmbedCode() {
$this->overwriteImageSettings();
$this->createAndLoginContentCreator();
$this->grantSiteRegistrationToken();
$this->grantCurrentUserDamToken();
$this->drupalGet('/node/add/page');
$this->getSession()->getPage()->fillField('Title', 'Embed test');
$this->waitForEditor();
$this->pressEditorButton('drupalmedialibrary');
$modal = $this->assertSession()->waitForElement('css', '#drupal-modal');
$modal->clickLink('Image');
$this->assertSession()->assertWaitOnAjaxRequest();
$media_select_checkbox = $this->assertSession()->elementExists('css', "[value='56ff14de-02cd-41b5-9a73-c917eab19abf']", $modal);
$media_select_checkbox->check();
$this->pressDialogButton('Next: Select Format');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->pageTextContains('Choose a format for your media');
$embedcode_fieldset = $this->assertSession()->waitForElement('css', '.embed_code_fieldset');
$embed_fieldset_count = $embedcode_fieldset->findAll('css', '.js-form-item-embed-code');
$image_styles = ImageStyle::loadMultiple();
$image_styles_count = count($image_styles);
self::assertCount($image_styles_count + 1, $embed_fieldset_count);
$session = $this->assertSession();
foreach ($image_styles as $style) {
$session->pageTextContains($style->label());
}
}
/**
* Asserts the number of media entities that exist.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment