ExecuteCodeTest.php in Devel PHP 8
File
tests/src/Functional/ExecuteCodeTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\devel_php\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class ExecuteCodeTest extends BrowserTestBase {
use StringTranslationTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'devel',
'devel_php',
];
public function testHandleErrors() {
$edit = [];
$url = Url::fromRoute('devel_php.execute_php');
$user = $this
->drupalCreateUser([
'execute php code',
]);
$this
->drupalLogin($user);
$this
->drupalGet($url);
$edit['code'] = 'devel_help()';
$this
->submitForm($edit, $this
->t('Execute'));
$this
->assertSession()
->pageTextContains('syntax error, unexpected end of file');
$edit['code'] = 'devel_help2();';
$this
->submitForm($edit, $this
->t('Execute'));
$this
->assertSession()
->pageTextContains('Call to undefined function devel_help2()');
$edit['code'] = 'devel_help();';
$this
->submitForm($edit, $this
->t('Execute'));
$this
->assertSession()
->pageTextContains('Too few arguments to function devel_help(), 0 passed');
}
public function testOutputBuffer() {
$edit = [];
$url = Url::fromRoute('devel_php.execute_php');
$user = $this
->drupalCreateUser([
'access devel information',
'execute php code',
]);
$this
->drupalLogin($user);
$this
->drupalGet($url);
$edit['code'] = 'echo \\Drupal::VERSION;';
$this
->submitForm($edit, $this
->t('Execute'));
$this
->assertSession()
->pageTextContains(\Drupal::VERSION);
}
}