public function BynderUploadWidgetTest::testUploadConfigurationForm in Bynder 8
Same name and namespace in other branches
- 8.3 tests/src/FunctionalJavascript/BynderUploadWidgetTest.php \Drupal\Tests\bynder\FunctionalJavascript\BynderUploadWidgetTest::testUploadConfigurationForm()
- 8.2 tests/src/FunctionalJavascript/BynderUploadWidgetTest.php \Drupal\Tests\bynder\FunctionalJavascript\BynderUploadWidgetTest::testUploadConfigurationForm()
- 4.0.x tests/src/FunctionalJavascript/BynderUploadWidgetTest.php \Drupal\Tests\bynder\FunctionalJavascript\BynderUploadWidgetTest::testUploadConfigurationForm()
Tests upload configuration form.
Return value
void
File
- tests/
src/ FunctionalJavascript/ BynderUploadWidgetTest.php, line 175 - Tests Bynder upload widget.
Class
- BynderUploadWidgetTest
- Test the Bynder upload widget.
Namespace
Drupal\Tests\bynder\FunctionalJavascriptCode
public function testUploadConfigurationForm() {
$metaproperties = [
'test_filter' => [
'label' => 'Test filter',
'name' => 'test_filter',
'id' => 'test_filter',
'isFilterable' => TRUE,
'isMultiselect' => FALSE,
'isRequired' => FALSE,
'zindex' => 1,
'options' => [
'optiona1' => [
'displayLabel' => 'option A1',
'id' => 'optiona1',
],
'optiona2' => [
'displayLabel' => 'option A2',
'id' => 'optiona2',
],
],
],
'test_another_filter' => [
'label' => 'Test another filter',
'name' => 'test_another_filter',
'id' => 'test_another_filter',
'isFilterable' => TRUE,
'isMultiselect' => FALSE,
'isRequired' => FALSE,
'zindex' => 1,
'options' => [
'optionb1' => [
'displayLabel' => 'option B1',
'id' => 'optionb1',
],
'optionb2' => [
'displayLabel' => 'option B2',
'id' => 'optionb2',
],
],
],
];
\Drupal::state()
->set('bynder.bynder_test_metaproperties', $metaproperties);
\Drupal::state()
->set('bynder.bynder_test_brands', [
[
'id' => 'brand_id',
'name' => 'Brand Name',
'subBrands' => [],
],
]);
$this
->drupalGet('admin/config/content/entity_browser/bynder/widgets');
// Confirm no upload widget is present, remove search widget.
$this
->assertSession()
->pageTextNotContains('Label (Bynder upload)');
$this
->assertSession()
->fieldValueEquals('Label (Bynder search)', 'Bynder');
$this
->getSession()
->getPage()
->pressButton('Delete');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextNotContains('Label (Bynder search)');
// Add upload widget and confirm default values.
$this
->getSession()
->getPage()
->selectFieldOption('widget', 'bynder_upload');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->fieldValueEquals('Label (Bynder upload)', 'bynder_upload');
$this
->assertSession()
->fieldValueEquals('Submit button text', 'Select entities');
$this
->assertSession()
->fieldValueEquals('Allowed file extensions', 'jpg jpeg png gif');
$this
->assertSession()
->fieldValueEquals('Dropzone drag-n-drop zone text', 'Drop files here to upload them.');
$this
->assertSession()
->fieldValueEquals('Tags', '');
// Set custom values, save and check if they were saved.
$this
->getSession()
->getPage()
->fillField('Label (Bynder upload)', 'Upload');
$this
->getSession()
->getPage()
->fillField('Submit button text', 'Upload assets');
$this
->getSession()
->getPage()
->fillField('Allowed file extensions', 'png jpg');
$this
->getSession()
->getPage()
->fillField('Dropzone drag-n-drop zone text', 'Drop files...');
$this
->getSession()
->getPage()
->fillField('Tags', 'foo,bar, baz');
$this
->getSession()
->getPage()
->selectFieldOption('Media bundle', 'Bynder');
$this
->getSession()
->getPage()
->selectFieldOption('Brand', 'Brand Name');
$this
->getSession()
->getPage()
->pressButton('Finish');
$entity_browser = \Drupal\entity_browser\Entity\EntityBrowser::load('bynder');
$this
->assertTrue($entity_browser
->getWidgets()
->count() == 1);
$widget_uuid = $entity_browser
->getWidgets()
->getInstanceIds();
$widget_uuid = reset($widget_uuid);
$upload_widget = $entity_browser
->getWidget($widget_uuid);
$expected_config = [
'settings' => [
'brand' => 'brand_id',
'extensions' => 'png jpg',
'dropzone_description' => 'Drop files...',
'tags' => [
'foo',
'bar',
'baz',
],
'media_bundle' => 'bynder',
'submit_text' => 'Upload assets',
'metaproperty_options' => [],
],
'uuid' => $widget_uuid,
'weight' => 1,
'label' => 'Upload',
'id' => 'bynder_upload',
];
$this
->assertEquals($expected_config, $upload_widget
->getConfiguration());
$this
->drupalGet('admin/config/content/entity_browser/bynder/widgets');
$this
->assertSession()
->fieldValueEquals('Label (Bynder upload)', 'Upload');
$this
->assertSession()
->fieldValueEquals('Submit button text', 'Upload assets');
$this
->assertTrue($this
->xpath('//select[@name="table[' . $widget_uuid . '][form][media_bundle]"]//option[@selected="selected" and @value="bynder"]'));
$this
->assertTrue($this
->xpath('//select[@name="table[' . $widget_uuid . '][form][brand]"]//option[@selected="selected" and @value="brand_id"]'));
$this
->assertSession()
->fieldValueEquals('Allowed file extensions', 'png jpg');
$this
->assertSession()
->fieldValueEquals('Dropzone drag-n-drop zone text', 'Drop files...');
$this
->assertSession()
->fieldValueEquals('Tags', 'foo, bar, baz');
// Play with metaproperties AJAX form and confirm it saves correctly.
$this
->getSession()
->getPage()
->checkField('table[' . $widget_uuid . '][form][metaproperties][test_filter]');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->getPage()
->selectFieldOption('table[' . $widget_uuid . '][form][metaproperty_options][test_filter][]', 'optiona2');
$this
->getSession()
->getPage()
->pressButton('Finish');
$entity_browser = \Drupal\entity_browser\Entity\EntityBrowser::load('bynder');
$this
->assertTrue($entity_browser
->getWidgets()
->count() == 1);
$widget_uuid = $entity_browser
->getWidgets()
->getInstanceIds();
$widget_uuid = reset($widget_uuid);
$upload_widget = $entity_browser
->getWidget($widget_uuid);
$expected_config = [
'settings' => [
'brand' => 'brand_id',
'extensions' => 'png jpg',
'dropzone_description' => 'Drop files...',
'tags' => [
'foo',
'bar',
'baz',
],
'media_bundle' => 'bynder',
'submit_text' => 'Upload assets',
'metaproperty_options' => [
'test_filter' => [
'optiona2',
],
],
],
'uuid' => $widget_uuid,
'weight' => 1,
'label' => 'Upload',
'id' => 'bynder_upload',
];
$this
->assertEquals($expected_config, $upload_widget
->getConfiguration());
}