first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace Drupal\FunctionalJavascriptTests\Tests;
use Behat\Mink\Driver\Selenium2Driver;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\file\Functional\FileFieldCreationTrait;
use Drupal\Tests\TestFileCreationTrait;
/**
* Tests the DrupalSelenium2Driver methods.
*
* @coversDefaultClass \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver
* @group javascript
*/
class DrupalSelenium2DriverTest extends WebDriverTestBase {
use TestFileCreationTrait;
use FileFieldCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = ['file', 'field_ui', 'entity_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$storage_settings = ['cardinality' => 3];
$this->createFileField('field_file', 'entity_test', 'entity_test', $storage_settings);
$this->drupalLogin($this->drupalCreateUser([
'administer entity_test content',
'access content',
]));
}
/**
* Tests uploading remote files.
*/
public function testGetRemoteFilePath(): void {
$web_driver = $this->getSession()->getDriver();
$this->assertInstanceOf(Selenium2Driver::class, $web_driver);
$this->assertFalse($web_driver->isW3C(), 'Driver is not operating in W3C mode');
$file_system = \Drupal::service('file_system');
$entity = EntityTest::create();
$entity->save();
$files = array_slice($this->getTestFiles('text'), 0, 3);
$real_paths = [];
foreach ($files as $file) {
$real_paths[] = $file_system->realpath($file->uri);
}
$remote_paths = [];
foreach ($real_paths as $path) {
$remote_paths[] = $web_driver->uploadFileAndGetRemoteFilePath($path);
}
// Tests that uploading multiple remote files works with remote path.
$this->drupalGet($entity->toUrl('edit-form'));
$multiple_field = $this->assertSession()->elementExists('xpath', '//input[@multiple]');
$multiple_field->setValue(implode("\n", $remote_paths));
$this->assertSession()->assertWaitOnAjaxRequest();
$this->getSession()->getPage()->findButton('Save')->click();
$entity = EntityTest::load($entity->id());
$this->assertCount(3, $entity->field_file);
}
}

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Drupal\FunctionalJavascriptTests\Tests;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use WebDriver\Exception;
/**
* Tests fault tolerant interactions.
*
* @group javascript
*/
class JSInteractionTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'js_interaction_test',
];
/**
* Assert an exception is thrown when the blocker element is never removed.
*/
public function testNotClickable(): void {
$this->expectException(Exception::class);
$this->drupalGet('/js_interaction_test');
$this->assertSession()->elementExists('named', ['link', 'Target link'])->click();
}
/**
* Assert an exception is thrown when the field is never enabled.
*/
public function testFieldValueNotSettable(): void {
$this->expectException(Exception::class);
$this->drupalGet('/js_interaction_test');
$this->assertSession()->fieldExists('target_field')->setValue('Test');
}
/**
* Assert no exception is thrown when elements become interactive.
*/
public function testElementsInteraction(): void {
$this->drupalGet('/js_interaction_test');
// Remove blocking element after 100 ms.
$this->clickLink('Remove Blocker Trigger');
$this->clickLink('Target link');
// Enable field after 100 ms.
$this->clickLink('Enable Field Trigger');
$this->assertSession()->fieldExists('target_field')->setValue('Test');
$this->assertSession()->fieldValueEquals('target_field', 'Test');
}
}

View File

@@ -0,0 +1,127 @@
<?php
declare(strict_types=1);
namespace Drupal\FunctionalJavascriptTests\Tests;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementHtmlException;
use Drupal\Component\Utility\Timer;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Tests for the JSWebAssert class.
*
* @group javascript
*/
class JSWebAssertTest extends WebDriverTestBase {
/**
* Required modules.
*
* @var array
*/
protected static $modules = ['js_webassert_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that JSWebAssert assertions work correctly.
*/
public function testJsWebAssert(): void {
$this->drupalGet('js_webassert_test_form');
$session = $this->getSession();
$assert_session = $this->assertSession();
$page = $session->getPage();
$assert_session->elementExists('css', '[data-drupal-selector="edit-test-assert-no-element-after-wait-pass"]');
$page->findButton('Test assertNoElementAfterWait: pass')->press();
$assert_session->assertNoElementAfterWait('css', '[data-drupal-selector="edit-test-assert-no-element-after-wait-pass"]', 1000);
$assert_session->elementExists('css', '[data-drupal-selector="edit-test-assert-no-element-after-wait-fail"]');
$page->findButton('Test assertNoElementAfterWait: fail')->press();
try {
Timer::start('JSWebAssertTest');
$assert_session->assertNoElementAfterWait('css', '[data-drupal-selector="edit-test-assert-no-element-after-wait-fail"]', 500, 'Element exists on page after too short wait.');
// This test is fragile if webdriver responses are very slow for some
// reason. If they are, do not fail the test.
// @todo https://www.drupal.org/project/drupal/issues/3316317 remove this
// workaround.
if (Timer::read('JSWebAssertTest') < 1000) {
$this->fail("Element not exists on page after too short wait.");
}
}
catch (ElementHtmlException $e) {
$this->assertSame('Element exists on page after too short wait.', $e->getMessage());
}
$assert_session->assertNoElementAfterWait('css', '[data-drupal-selector="edit-test-assert-no-element-after-wait-fail"]', 2500, 'Element remove after another wait.ss');
$test_button = $page->findButton('Add button');
$test_link = $page->findButton('Add link');
$test_field = $page->findButton('Add field');
$test_id = $page->findButton('Add ID');
$test_wait_on_ajax = $page->findButton('Test assertWaitOnAjaxRequest');
$test_wait_on_element_visible = $page->findButton('Test waitForElementVisible');
// Test the wait...() methods by first checking the fields aren't available
// and then are available after the wait method.
$result = $page->findButton('Added button');
$this->assertEmpty($result);
$test_button->click();
$result = $assert_session->waitForButton('Added button');
$this->assertNotEmpty($result);
$this->assertInstanceOf(NodeElement::class, $result);
$result = $page->findLink('Added link');
$this->assertEmpty($result);
$test_link->click();
$result = $assert_session->waitForLink('Added link');
$this->assertNotEmpty($result);
$this->assertInstanceOf(NodeElement::class, $result);
$result = $page->findField('added_field');
$this->assertEmpty($result);
$test_field->click();
$result = $assert_session->waitForField('added_field');
$this->assertNotEmpty($result);
$this->assertInstanceOf(NodeElement::class, $result);
$result = $page->findById('js_webassert_test_field_id');
$this->assertEmpty($result);
$test_id->click();
$result = $assert_session->waitForId('js_webassert_test_field_id');
$this->assertNotEmpty($result);
$this->assertInstanceOf(NodeElement::class, $result);
// Test waitOnAjaxRequest. Verify the element is available after the wait
// and the behaviors have run on completing by checking the value.
$result = $page->findField('test_assert_wait_on_ajax_input');
$this->assertEmpty($result);
$test_wait_on_ajax->click();
$assert_session->assertWaitOnAjaxRequest();
$result = $page->findField('test_assert_wait_on_ajax_input');
$this->assertNotEmpty($result);
$this->assertInstanceOf(NodeElement::class, $result);
$this->assertEquals('js_webassert_test', $result->getValue());
$result = $page->findButton('Added WaitForElementVisible');
$this->assertEmpty($result);
$test_wait_on_element_visible->click();
$result = $assert_session->waitForElementVisible('named', ['button', 'Added WaitForElementVisible']);
$this->assertNotEmpty($result);
$this->assertInstanceOf(NodeElement::class, $result);
$this->assertEquals(TRUE, $result->isVisible());
$this->drupalGet('js_webassert_test_page');
// Ensure that the javascript has replaced the element 1100 times.
$assert_session->waitForText('New Text!! 1100');
$result = $page->find('named', ['id', 'test_text']);
$this->assertSame('test_text', $result->getAttribute('id'));
}
}