X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fentity_browser%2Fmodules%2Fentity_form%2Ftests%2Fsrc%2FFunctionalJavascript%2FEntityFormWidgetTest.php;fp=web%2Fmodules%2Fcontrib%2Fentity_browser%2Fmodules%2Fentity_form%2Ftests%2Fsrc%2FFunctionalJavascript%2FEntityFormWidgetTest.php;h=aef8ebb349152a68f38eca7fdd651411fd957520;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/entity_browser/modules/entity_form/tests/src/FunctionalJavascript/EntityFormWidgetTest.php b/web/modules/contrib/entity_browser/modules/entity_form/tests/src/FunctionalJavascript/EntityFormWidgetTest.php new file mode 100644 index 000000000..aef8ebb34 --- /dev/null +++ b/web/modules/contrib/entity_browser/modules/entity_form/tests/src/FunctionalJavascript/EntityFormWidgetTest.php @@ -0,0 +1,153 @@ +drupalCreateContentType(['type' => 'foo', 'name' => 'Foo']); + + FieldStorageConfig::create([ + 'field_name' => 'field_reference', + 'type' => 'entity_reference', + 'entity_type' => 'node', + 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, + 'settings' => [ + 'target_type' => 'node', + ], + ])->save(); + + FieldConfig::create([ + 'field_name' => 'field_reference', + 'entity_type' => 'node', + 'bundle' => 'foo', + 'label' => 'Reference', + 'settings' => [], + ])->save(); + + /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */ + $form_display = $this->container->get('entity_type.manager') + ->getStorage('entity_form_display') + ->load('node.foo.default'); + + $form_display->setComponent('field_reference', [ + 'type' => 'entity_browser_entity_reference', + 'settings' => [ + 'entity_browser' => 'entity_browser_test_entity_form', + 'field_widget_display' => 'label', + 'open' => TRUE, + ], + ])->save(); + + $account = $this->drupalCreateUser([ + 'access entity_browser_test_entity_form entity browser pages', + 'create foo content', + 'access content', + ]); + $this->drupalLogin($account); + } + + /** + * Test if save button is appears on form. + */ + public function testEntityForm() { + /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */ + $browser = $this->container->get('entity_type.manager') + ->getStorage('entity_browser') + ->load('entity_browser_test_entity_form'); + + // Make sure that the "Save entities" button exists. + $this->drupalGet('entity-browser/iframe/entity_browser_test_entity_form'); + $this->assertSession()->buttonExists('Save entity'); + + // Change save button's text and make sure that the change was respected. + $config = $browser->getWidget('9c6ee4c0-4642-4203-b4bd-ec0bad068ad3')->getConfiguration(); + $config['settings']['submit_text'] = 'Save node'; + $browser->getWidget('9c6ee4c0-4642-4203-b4bd-ec0bad068ad3')->setConfiguration($config); + $browser->save(); + $this->drupalGet('entity-browser/iframe/entity_browser_test_entity_form'); + $this->assertSession()->buttonNotExists('Save entity'); + $this->assertSession()->buttonExists('Save node'); + + // Make sure that the widget works correctly with the field widget + $this->drupalGet('node/add/foo'); + $this->getSession()->getPage()->clickLink('Select entities'); + $this->getSession()->switchToIFrame('entity_browser_iframe_entity_browser_test_entity_form'); + $this->getSession()->getPage()->fillField('inline_entity_form[title][0][value]', 'War is peace'); + $this->getSession()->getPage()->pressButton('Save node'); + + // Switch back to the main page. + $this->getSession()->switchToIFrame(); + $this->assertSession()->assertWaitOnAjaxRequest(); + + $this->assertSession()->pageTextContains('War is peace'); + $this->getSession()->getPage()->fillField('title[0][value]', 'Freedom is slavery'); + $this->getSession()->getPage()->pressButton('Save'); + + $parent_node = $this->container->get('entity_type.manager') + ->getStorage('node') + ->loadByProperties(['title' => 'Freedom is slavery']); + $parent_node = current($parent_node); + $this->assertEquals(1, $parent_node->get('field_reference')->count(), 'There is one child node.'); + $this->assertEquals('War is peace', $parent_node->field_reference->entity->label(), 'Child node has correct title.'); + + // Now try using Multi value selection display and make sure there is only + // one node created by the Entity browser. + $browser->setSelectionDisplay('multi_step_display')->save(); + $this->drupalGet('node/add/foo'); + $this->getSession()->getPage()->clickLink('Select entities'); + $this->getSession()->switchToIFrame('entity_browser_iframe_entity_browser_test_entity_form'); + $this->getSession()->getPage()->fillField('inline_entity_form[title][0][value]', 'War is peace'); + $this->getSession()->getPage()->pressButton('Save node'); + $this->getSession()->getPage()->pressButton('Use selected'); + + // Switch back to the main page. + $this->getSession()->switchToIFrame(); + $this->assertSession()->assertWaitOnAjaxRequest(); + + $this->assertSession()->pageTextContains('War is peace'); + $this->getSession()->getPage()->fillField('title[0][value]', 'Ignorance is strength'); + $this->getSession()->getPage()->pressButton('Save'); + + $parent_node = $this->container->get('entity_type.manager') + ->getStorage('node') + ->loadByProperties(['title' => 'Ignorance is strength']); + $parent_node = current($parent_node); + $this->assertEquals(1, $parent_node->get('field_reference')->count(), 'There is one child node.'); + $this->assertEquals('War is peace', $parent_node->field_reference->entity->label(), 'Child node has correct title.'); + } + +}