2015-08-18 00:00:26 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-06 22:16:20 +00:00
|
|
|
namespace Drupal\FunctionalTests;
|
2015-08-18 00:00:26 +00:00
|
|
|
|
2016-10-06 22:16:20 +00:00
|
|
|
use Drupal\Component\Utility\Html;
|
2016-06-02 22:56:09 +00:00
|
|
|
use Drupal\Core\Url;
|
2016-04-20 16:56:34 +00:00
|
|
|
use Drupal\Tests\BrowserTestBase;
|
2015-08-18 00:00:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests BrowserTestBase functionality.
|
|
|
|
*
|
2016-10-06 22:16:20 +00:00
|
|
|
* @group browsertestbase
|
2015-08-18 00:00:26 +00:00
|
|
|
*/
|
|
|
|
class BrowserTestBaseTest extends BrowserTestBase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modules to enable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-10-06 22:16:20 +00:00
|
|
|
public static $modules = array('test_page_test', 'form_test', 'system_test');
|
2015-08-18 00:00:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests basic page test.
|
|
|
|
*/
|
|
|
|
public function testGoTo() {
|
|
|
|
$account = $this->drupalCreateUser();
|
|
|
|
$this->drupalLogin($account);
|
|
|
|
|
|
|
|
// Visit a Drupal page that requires login.
|
2015-10-08 18:40:12 +00:00
|
|
|
$this->drupalGet('test-page');
|
2015-08-18 00:00:26 +00:00
|
|
|
$this->assertSession()->statusCodeEquals(200);
|
|
|
|
|
|
|
|
// Test page contains some text.
|
|
|
|
$this->assertSession()->pageTextContains('Test page text.');
|
2016-06-02 22:56:09 +00:00
|
|
|
|
2016-09-07 20:26:21 +00:00
|
|
|
// Check that returned plain text is correct.
|
|
|
|
$text = $this->getTextContent();
|
|
|
|
$this->assertContains('Test page text.', $text);
|
|
|
|
$this->assertNotContains('</html>', $text);
|
|
|
|
|
2016-07-07 16:44:38 +00:00
|
|
|
// Response includes cache tags that we can assert.
|
|
|
|
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'rendered');
|
|
|
|
|
2016-08-03 20:22:33 +00:00
|
|
|
// Test that we can read the JS settings.
|
|
|
|
$js_settings = $this->getDrupalSettings();
|
|
|
|
$this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
|
|
|
|
|
2016-06-02 22:56:09 +00:00
|
|
|
// Test drupalGet with a url object.
|
|
|
|
$url = Url::fromRoute('test_page_test.render_title');
|
|
|
|
$this->drupalGet($url);
|
|
|
|
$this->assertSession()->statusCodeEquals(200);
|
|
|
|
|
|
|
|
// Test page contains some text.
|
|
|
|
$this->assertSession()->pageTextContains('Hello Drupal');
|
2016-10-06 22:16:20 +00:00
|
|
|
|
|
|
|
// Test that setting headers with drupalGet() works.
|
|
|
|
$this->drupalGet('system-test/header', array(), array(
|
|
|
|
'Test-Header' => 'header value',
|
|
|
|
));
|
|
|
|
$returned_header = $this->getSession()->getResponseHeader('Test-Header');
|
|
|
|
$this->assertSame('header value', $returned_header);
|
2015-08-18 00:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests basic form functionality.
|
|
|
|
*/
|
|
|
|
public function testForm() {
|
|
|
|
// Ensure the proper response code for a _form route.
|
2015-10-08 18:40:12 +00:00
|
|
|
$this->drupalGet('form-test/object-builder');
|
2015-08-18 00:00:26 +00:00
|
|
|
$this->assertSession()->statusCodeEquals(200);
|
|
|
|
|
|
|
|
// Ensure the form and text field exist.
|
|
|
|
$this->assertSession()->elementExists('css', 'form#form-test-form-test-object');
|
|
|
|
$this->assertSession()->fieldExists('bananas');
|
|
|
|
|
|
|
|
$edit = ['bananas' => 'green'];
|
|
|
|
$this->submitForm($edit, 'Save', 'form-test-form-test-object');
|
|
|
|
|
|
|
|
$config_factory = $this->container->get('config.factory');
|
|
|
|
$value = $config_factory->get('form_test.object')->get('bananas');
|
|
|
|
$this->assertSame('green', $value);
|
|
|
|
}
|
|
|
|
|
2016-10-06 22:16:20 +00:00
|
|
|
/**
|
|
|
|
* Tests clickLink() functionality.
|
|
|
|
*/
|
|
|
|
public function testClickLink() {
|
|
|
|
$this->drupalGet('test-page');
|
|
|
|
$this->clickLink('Visually identical test links');
|
|
|
|
$this->assertContains('user/login', $this->getSession()->getCurrentUrl());
|
|
|
|
$this->drupalGet('test-page');
|
|
|
|
$this->clickLink('Visually identical test links', 0);
|
|
|
|
$this->assertContains('user/login', $this->getSession()->getCurrentUrl());
|
|
|
|
$this->drupalGet('test-page');
|
|
|
|
$this->clickLink('Visually identical test links', 1);
|
|
|
|
$this->assertContains('user/register', $this->getSession()->getCurrentUrl());
|
|
|
|
}
|
|
|
|
|
2016-04-07 18:19:57 +00:00
|
|
|
public function testError() {
|
|
|
|
$this->setExpectedException('\Exception', 'User notice: foo');
|
|
|
|
$this->drupalGet('test-error');
|
|
|
|
}
|
|
|
|
|
2016-10-06 22:16:20 +00:00
|
|
|
/**
|
|
|
|
* Tests legacy asserts.
|
|
|
|
*/
|
|
|
|
public function testLegacyAsserts() {
|
|
|
|
$this->drupalGet('test-encoded');
|
|
|
|
$dangerous = 'Bad html <script>alert(123);</script>';
|
|
|
|
$sanitized = Html::escape($dangerous);
|
|
|
|
$this->assertNoText($dangerous);
|
|
|
|
$this->assertText($sanitized);
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:28:38 +00:00
|
|
|
/**
|
|
|
|
* Tests the Drupal install done in \Drupal\Tests\BrowserTestBase::setUp().
|
|
|
|
*/
|
|
|
|
public function testInstall() {
|
|
|
|
$htaccess_filename = $this->tempFilesDirectory . '/.htaccess';
|
|
|
|
$this->assertTrue(file_exists($htaccess_filename), "$htaccess_filename exists");
|
|
|
|
}
|
|
|
|
|
2015-08-18 00:00:26 +00:00
|
|
|
}
|