Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -3,6 +3,7 @@
namespace Drupal\FunctionalTests;
use Behat\Mink\Exception\ExpectationException;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
@ -22,7 +23,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['test_page_test', 'form_test', 'system_test'];
public static $modules = ['test_page_test', 'form_test', 'system_test', 'node'];
/**
* Tests basic page test.
@ -66,6 +67,21 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertSame('header value', $returned_header);
}
/**
* Tests drupalGet().
*/
public function testDrupalGet() {
$this->drupalGet('test-page');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->addressEquals('test-page');
$this->drupalGet('/test-page');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->addressEquals('test-page');
$this->drupalGet('/test-page/');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->addressEquals('/test-page/');
}
/**
* Tests basic form functionality.
*/
@ -98,13 +114,27 @@ class BrowserTestBaseTest extends BrowserTestBase {
// Test drupalPostForm().
$edit = ['bananas' => 'red'];
$this->drupalPostForm('form-test/object-builder', $edit, 'Save');
$result = $this->drupalPostForm('form-test/object-builder', $edit, 'Save');
$this->assertSame($this->getSession()->getPage()->getContent(), $result);
$value = $config_factory->get('form_test.object')->get('bananas');
$this->assertSame('red', $value);
$this->drupalPostForm('form-test/object-builder', NULL, 'Save');
$value = $config_factory->get('form_test.object')->get('bananas');
$this->assertSame('', $value);
// Test drupalPostForm() with no-html response.
$values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit')));
$this->assertTrue(1000, $values['beer']);
// Test drupalPostForm() with form by HTML id.
$this->drupalCreateContentType(['type' => 'page']);
$this->drupalLogin($this->drupalCreateUser(['create page content']));
$this->drupalGet('form-test/two-instances-of-same-form');
$this->getSession()->getPage()->fillField('edit-title-0-value', 'form1');
$this->getSession()->getPage()->fillField('edit-title-0-value--2', 'form2');
$this->drupalPostForm(NULL, [], 'Save', [], 'node-page-form--2');
$this->assertSession()->pageTextContains('Page form2 has been created.');
}
/**
@ -137,10 +167,52 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertSession()->linkExists('foo|bar|baz');
}
/**
* Tests linkExistsExact() functionality.
*
* @see \Drupal\Tests\WebAssert::linkExistsExact()
*/
public function testLinkExistsExact() {
$this->drupalGet('test-pipe-char');
$this->assertSession()->linkExistsExact('foo|bar|baz');
}
/**
* Tests linkExistsExact() functionality fail.
*
* @see \Drupal\Tests\WebAssert::linkExistsExact()
*/
public function testInvalidLinkExistsExact() {
$this->drupalGet('test-pipe-char');
$this->setExpectedException(ExpectationException::class, 'Link with label foo|bar found');
$this->assertSession()->linkExistsExact('foo|bar');
}
/**
* Tests linkNotExistsExact() functionality.
*
* @see \Drupal\Tests\WebAssert::linkNotExistsExact()
*/
public function testLinkNotExistsExact() {
$this->drupalGet('test-pipe-char');
$this->assertSession()->linkNotExistsExact('foo|bar');
}
/**
* Tests linkNotExistsExact() functionality fail.
*
* @see \Drupal\Tests\WebAssert::linkNotExistsExact()
*/
public function testInvalidLinkNotExistsExact() {
$this->drupalGet('test-pipe-char');
$this->setExpectedException(ExpectationException::class, 'Link with label foo|bar|baz not found');
$this->assertSession()->linkNotExistsExact('foo|bar|baz');
}
/**
* Tests legacy text asserts.
*/
public function testLegacyTextAsserts() {
public function testTextAsserts() {
$this->drupalGet('test-encoded');
$dangerous = 'Bad html <script>alert(123);</script>';
$sanitized = Html::escape($dangerous);
@ -148,13 +220,13 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertText($sanitized);
// Test getRawContent().
$this->assertSame($this->getSession()->getPage()->getContent(), $this->getRawContent());
$this->assertSame($this->getSession()->getPage()->getContent(), $this->getSession()->getPage()->getContent());
}
/**
* Tests legacy field asserts which use xpath directly.
*/
public function testLegacyXpathAsserts() {
public function testXpathAsserts() {
$this->drupalGet('test-field-xpath');
$this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL);
$this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one');
@ -181,7 +253,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertNoFieldByXPath("//input[@id = 'edit-name']");
$this->fail('The "edit-name" field was not found.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationException $e) {
$this->pass('assertNoFieldByXPath correctly failed. The "edit-name" field was found.');
}
@ -197,7 +269,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
/**
* Tests legacy field asserts using textfields.
*/
public function testLegacyFieldAssertsWithTextfields() {
public function testFieldAssertsForTextfields() {
$this->drupalGet('test-field-xpath');
// *** 1. assertNoField().
@ -230,7 +302,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertField('invalid_name_and_id');
$this->fail('The "invalid_name_and_id" field was found.');
}
catch (ExpectationException $e) {
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.');
}
@ -319,7 +391,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldByName('non-existing-name');
$this->fail('The "non-existing-name" field was found.');
}
catch (ExpectationException $e) {
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->pass('The "non-existing-name" field was not found');
}
@ -328,15 +400,18 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldByName('name', 'not the value');
$this->fail('The "name" field with incorrect value was found.');
}
catch (ExpectationException $e) {
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.');
}
// Test that text areas can contain new lines.
$this->assertFieldsByValue($this->xpath("//textarea[@id = 'edit-test-textarea-with-newline']"), "Test text with\nnewline");
}
/**
* Tests legacy field asserts on other types of field.
* Tests legacy field asserts for options field type.
*/
public function testLegacyFieldAssertsWithNonTextfields() {
public function testFieldAssertsForOptions() {
$this->drupalGet('test-field-xpath');
// Option field type.
@ -384,7 +459,17 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->pass($e->getMessage());
}
// Button field type.
// Test \Drupal\FunctionalTests\AssertLegacyTrait::getAllOptions.
$this->drupalGet('/form-test/select');
$this->assertCount(6, $this->getAllOptions($this->cssSelect('select[name="opt_groups"]')[0]));
}
/**
* Tests legacy field asserts for button field type.
*/
public function testFieldAssertsForButton() {
$this->drupalGet('test-field-xpath');
$this->assertFieldById('edit-save', NULL);
// Test that the assertion fails correctly if the field value is passed in
// rather than the id.
@ -392,7 +477,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldById('Save', NULL);
$this->fail('The field with id of "Save" was found.');
}
catch (ExpectationException $e) {
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->pass($e->getMessage());
}
@ -407,7 +492,27 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->pass($e->getMessage());
}
// Checkbox field type.
// Test that multiple fields with the same name are validated correctly.
$this->assertFieldByName('duplicate_button', 'Duplicate button 1');
$this->assertFieldByName('duplicate_button', 'Duplicate button 2');
$this->assertNoFieldByName('duplicate_button', 'Rabbit');
try {
$this->assertNoFieldByName('duplicate_button', 'Duplicate button 2');
$this->fail('The "duplicate_button" field with the value Duplicate button 2 was not found.');
}
catch (ExpectationException $e) {
$this->pass('assertNoFieldByName correctly failed. The "duplicate_button" field with the value Duplicate button 2 was found.');
}
}
/**
* Tests legacy field asserts for checkbox field type.
*/
public function testFieldAssertsForCheckbox() {
$this->drupalGet('test-field-xpath');
// Part 1 - Test by name.
// Test that checkboxes are found/not found correctly by name, when using
// TRUE or FALSE to match their 'checked' state.
$this->assertFieldByName('checkbox_enabled', TRUE);
@ -420,17 +525,13 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldByName('checkbox_enabled', NULL);
$this->assertFieldByName('checkbox_disabled', NULL);
// Test that checkboxes are found/not found correctly by ID, when using
// TRUE or FALSE to match their 'checked' state.
$this->assertFieldById('edit-checkbox-enabled', TRUE);
$this->assertFieldById('edit-checkbox-disabled', FALSE);
$this->assertNoFieldById('edit-checkbox-enabled', FALSE);
$this->assertNoFieldById('edit-checkbox-disabled', TRUE);
// Test that checkboxes are found by name when passing no second parameter.
$this->assertFieldByName('checkbox_enabled');
$this->assertFieldByName('checkbox_disabled');
// Test that checkboxes are found by by ID, when using NULL to ignore the
// 'checked' state.
$this->assertFieldById('edit-checkbox-enabled', NULL);
$this->assertFieldById('edit-checkbox-disabled', NULL);
// Test that we have legacy support.
$this->assertFieldByName('checkbox_enabled', '1');
$this->assertFieldByName('checkbox_disabled', '');
// Test that the assertion fails correctly when using NULL to ignore state.
try {
@ -441,6 +542,27 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->pass('assertNoFieldByName failed correctly. The "checkbox_enabled" field was found using NULL value.');
}
// Part 2 - Test by ID.
// Test that checkboxes are found/not found correctly by ID, when using
// TRUE or FALSE to match their 'checked' state.
$this->assertFieldById('edit-checkbox-enabled', TRUE);
$this->assertFieldById('edit-checkbox-disabled', FALSE);
$this->assertNoFieldById('edit-checkbox-enabled', FALSE);
$this->assertNoFieldById('edit-checkbox-disabled', TRUE);
// Test that checkboxes are found by ID, when using NULL to ignore the
// 'checked' state.
$this->assertFieldById('edit-checkbox-enabled', NULL);
$this->assertFieldById('edit-checkbox-disabled', NULL);
// Test that checkboxes are found by ID when passing no second parameter.
$this->assertFieldById('edit-checkbox-enabled');
$this->assertFieldById('edit-checkbox-disabled');
// Test that we have legacy support.
$this->assertFieldById('edit-checkbox-enabled', '1');
$this->assertFieldById('edit-checkbox-disabled', '');
// Test that the assertion fails correctly when using NULL to ignore state.
try {
$this->assertNoFieldById('edit-checkbox-disabled', NULL);
@ -450,11 +572,11 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->pass('assertNoFieldById failed correctly. The "edit-checkbox-disabled" field was found by ID using NULL value.');
}
// Test the specific 'checked' assertions.
// Part 3 - Test the specific 'checked' assertions.
$this->assertFieldChecked('edit-checkbox-enabled');
$this->assertNoFieldChecked('edit-checkbox-disabled');
// Test that the assertion fails correctly with non-existant field id.
// Test that the assertion fails correctly with non-existent field id.
try {
$this->assertNoFieldChecked('incorrect_checkbox_id');
$this->fail('The "incorrect_checkbox_id" field was found');
@ -503,4 +625,51 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertTrue(file_exists($htaccess_filename), "$htaccess_filename exists");
}
/**
* Tests the assumption that local time is in 'Australia/Sydney'.
*/
public function testLocalTimeZone() {
// The 'Australia/Sydney' time zone is set in core/tests/bootstrap.php
$this->assertEquals('Australia/Sydney', date_default_timezone_get());
// The 'Australia/Sydney' time zone is also set in
// FunctionalTestSetupTrait::initConfig().
$config_factory = $this->container->get('config.factory');
$value = $config_factory->get('system.date')->get('timezone.default');
$this->assertEquals('Australia/Sydney', $value);
}
/**
* Tests the ::checkForMetaRefresh() method.
*/
public function testCheckForMetaRefresh() {
// Disable following redirects in the client.
$this->getSession()->getDriver()->getClient()->followRedirects(FALSE);
// Set the maximumMetaRefreshCount to zero to make sure the redirect doesn't
// happen when doing a drupalGet.
$this->maximumMetaRefreshCount = 0;
$this->drupalGet('test-meta-refresh');
$this->assertNotEmpty($this->cssSelect('meta[http-equiv="refresh"]'));
// Allow one redirect to happen.
$this->maximumMetaRefreshCount = 1;
$this->checkForMetaRefresh();
// Check that we are now on the test page.
$this->assertSession()->pageTextContains('Test page text.');
}
public function testGetDefaultDriveInstance() {
putenv('MINK_DRIVER_ARGS=' . json_encode([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]]));
$this->getDefaultDriverInstance();
$this->assertEquals([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]], $this->minkDefaultDriverArgs);
}
/**
* Ensures we can't access modules we shouldn't be able to after install.
*/
public function testProfileModules() {
$this->setExpectedException(\InvalidArgumentException::class, 'The module demo_umami_content does not exist.');
$this->assertFileExists('core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.info.yml');
\Drupal::service('extension.list.module')->getPathname('demo_umami_content');
}
}