|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\Tests\paragraphs_editor\Unit\WidgetBinder\Generators; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Render\BubbleableMetadata; |
|
6
|
|
|
use Drupal\Core\Render\RenderContext; |
|
7
|
|
|
use Drupal\editor_assets\EditorAssetProcessorInterface; |
|
8
|
|
|
use Drupal\paragraphs_editor\WidgetBinder\Generators\AssetGenerator; |
|
9
|
|
|
use Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData; |
|
10
|
|
|
use Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState; |
|
11
|
|
|
use Drupal\Tests\paragraphs_editor\Traits\MockContextTrait; |
|
12
|
|
|
use Drupal\Tests\UnitTestCase; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @coversDefaultClass \Drupal\paragraphs_editor\WidgetBinder\Generators\AssetGenerator |
|
16
|
|
|
* @group paragraphs_editor |
|
17
|
|
|
*/ |
|
18
|
|
|
class AssetGeneratorUnitTest extends UnitTestCase { |
|
19
|
|
|
use MockContextTrait; |
|
20
|
|
|
|
|
21
|
1 |
|
public function testComplete() { |
|
22
|
1 |
|
$prophecy = $this->prophesize(EditorAssetProcessorInterface::CLASS); |
|
|
|
|
|
|
23
|
1 |
|
$prophecy->processAttachments(['input_attachment'])->willReturn([ |
|
24
|
1 |
|
'test_asset_id' => [ |
|
25
|
|
|
'test_model_key' => 'test_model_value', |
|
26
|
|
|
], |
|
27
|
|
|
]); |
|
28
|
|
|
|
|
29
|
1 |
|
$context = $this->createContext([ |
|
30
|
1 |
|
'context_id' => 'test_editor_context', |
|
31
|
|
|
]); |
|
32
|
1 |
|
$context->addAdditionalContext('editorContext', 'test_owner_context'); |
|
33
|
1 |
|
$item = $context->getEditBuffer()->createItem($this->createMockParagraph()); |
|
34
|
|
|
|
|
35
|
1 |
|
$render_context = new RenderContext(); |
|
36
|
1 |
|
$metadata = new BubbleableMetadata(); |
|
37
|
1 |
|
$metadata->addAttachments(['input_attachment']); |
|
38
|
1 |
|
$render_context->push($metadata); |
|
39
|
|
|
|
|
40
|
1 |
|
$data = new WidgetBinderData(); |
|
41
|
1 |
|
$state = new WidgetBinderDataCompilerState([], $data, $context, $item); |
|
42
|
1 |
|
$generator = new AssetGenerator($prophecy->reveal()); |
|
43
|
1 |
|
$generator->complete($data, $state, $render_context, ''); |
|
44
|
|
|
|
|
45
|
1 |
|
$this->assertEquals([ |
|
46
|
1 |
|
'test_asset_id' => [ |
|
47
|
|
|
'test_model_key' => 'test_model_value', |
|
48
|
|
|
'editorContextId' => 'test_owner_context', |
|
49
|
|
|
], |
|
50
|
1 |
|
], $data->getModels('asset')); |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|