ExternalFormUrlTest.php in Zircon Profile 8
File
core/modules/system/src/Tests/Form/ExternalFormUrlTest.php
View source
<?php
namespace Drupal\system\Tests\Form;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\simpletest\KernelTestBase;
use Drupal\user\Entity\User;
use Symfony\Component\HttpFoundation\Request;
class ExternalFormUrlTest extends KernelTestBase implements FormInterface {
public static $modules = [
'user',
'system',
];
public function getFormId() {
return 'external_form_url_test';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['something'] = [
'#type' => 'textfield',
'#title' => 'What do you think?',
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
protected function setUp() {
parent::setUp();
$this
->installSchema('system', [
'key_value_expire',
'sequences',
]);
$this
->installEntitySchema('user');
$test_user = User::create([
'name' => 'foobar',
'mail' => 'foobar@example.com',
]);
$test_user
->save();
\Drupal::service('current_user')
->setAccount($test_user);
}
public function testActionUrlBehavior() {
$request_stack = \Drupal::service('request_stack');
$original_request = $request_stack
->pop();
$request = Request::create($original_request
->getSchemeAndHttpHost() . '//example.org');
$request_stack
->push($request);
$form = \Drupal::formBuilder()
->getForm($this);
$markup = \Drupal::service('renderer')
->renderRoot($form);
$this
->setRawContent($markup);
$elements = $this
->xpath('//form/@action');
$action = (string) $elements[0];
$this
->assertEqual($original_request
->getSchemeAndHttpHost() . '//example.org', $action);
$request_stack = \Drupal::service('request_stack');
$original_request = $request_stack
->pop();
$request = Request::create($original_request
->getSchemeAndHttpHost() . '/example.org');
$request_stack
->push($request);
$form = \Drupal::formBuilder()
->getForm($this);
$markup = \Drupal::service('renderer')
->renderRoot($form);
$this
->setRawContent($markup);
$elements = $this
->xpath('//form/@action');
$action = (string) $elements[0];
$this
->assertEqual('/example.org', $action);
}
}