a few more base modules

This commit is contained in:
Bachir Soussi Chiadmi
2016-09-06 16:05:07 +02:00
parent c6cff46234
commit 027aa99b32
455 changed files with 43606 additions and 0 deletions
@@ -0,0 +1,12 @@
name: 'Devel dumper test module'
type: module
description: 'Test pluggable dumpers.'
package: Testing
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2016-09-03
version: '8.x-1.0-alpha1+23-dev'
core: '8.x'
project: 'devel'
datestamp: 1472897643
@@ -0,0 +1,7 @@
devel_dumper_test:
version: 0
css:
theme:
css/devel_dumper_test.css: {}
js:
js/devel_dumper_test.js: {}
@@ -0,0 +1,39 @@
devel_dumper_test.dump:
path: '/devel_dumper_test/dump'
defaults:
_controller: '\Drupal\devel_dumper_test\Controller\DumperTestController::dump'
_title: 'Devel Dumper Test'
requirements:
_permission: 'access devel information'
devel_dumper_test.message:
path: '/devel_dumper_test/message'
defaults:
_controller: '\Drupal\devel_dumper_test\Controller\DumperTestController::message'
_title: 'Devel Dumper Test'
requirements:
_permission: 'access devel information'
devel_dumper_test.export:
path: '/devel_dumper_test/export'
defaults:
_controller: '\Drupal\devel_dumper_test\Controller\DumperTestController::export'
_title: 'Devel Dumper Test'
requirements:
_permission: 'access devel information'
devel_dumper_test.export_renderable:
path: '/devel_dumper_test/export_renderable'
defaults:
_controller: '\Drupal\devel_dumper_test\Controller\DumperTestController::exportRenderable'
_title: 'Devel Dumper Test'
requirements:
_permission: 'access devel information'
devel_dumper_test.debug:
path: '/devel_dumper_test/debug'
defaults:
_controller: '\Drupal\devel_dumper_test\Controller\DumperTestController::debug'
_title: 'Devel Dumper Test'
requirements:
_access: 'TRUE'
@@ -0,0 +1,89 @@
<?php
namespace Drupal\devel_dumper_test\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\devel\DevelDumperManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class DumperTestController
*/
class DumperTestController extends ControllerBase {
/**
* The dumper manager.
*
* @var \Drupal\devel\DevelDumperManagerInterface
*/
protected $dumper;
/**
* Constructs a new DumperTestController object.
*
* @param \Drupal\devel\DevelDumperManagerInterface $devel_dumper_manager
* The dumper manager.
*/
public function __construct(DevelDumperManagerInterface $devel_dumper_manager) {
$this->dumper = $devel_dumper_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('devel.dumper')
);
}
/**
* @return array
*/
public function dump() {
$this->dumper->dump('Test output');
return [
'#markup' => 'test',
];
}
/**
* @return array
*/
public function message() {
$this->dumper->message('Test output');
return [
'#markup' => 'test',
];
}
/**
* @return array
*/
public function debug() {
$this->dumper->debug('Test output');
return [
'#markup' => 'test',
];
}
/**
* @return array
*/
public function export() {
return [
'#markup' => $this->dumper->export('Test output'),
];
}
/**
* @return array
*/
public function exportRenderable() {
return $this->dumper->exportAsRenderable('Test output');
}
}
@@ -0,0 +1,60 @@
<?php
namespace Drupal\devel_dumper_test\Plugin\Devel\Dumper;
use Drupal\devel\DevelDumperBase;
/**
* Provides a AvailableTestDumper plugin.
*
* @DevelDumper(
* id = "available_test_dumper",
* label = @Translation("Available test dumper."),
* description = @Translation("Drupal dumper for testing purposes (available).")
* )
*/
class AvailableTestDumper extends DevelDumperBase {
/**
* {@inheritdoc}
*/
public function dump($input, $name = NULL) {
// Add a predetermined string to $input to check if this dumper has been
// selected successfully.
$input = '<pre>' . 'AvailableTestDumper::dump() ' . $input . '</pre>';
echo $input;
}
/**
* {@inheritdoc}
*/
public function export($input, $name = NULL) {
// Add a predetermined string to $input to check if this dumper has been
// selected successfully.
$input = '<pre>' . 'AvailableTestDumper::export() ' . $input . '</pre>';
return $this->setSafeMarkup($input);
}
/**
* {@inheritdoc}
*/
public function exportAsRenderable($input, $name = NULL) {
// Add a predetermined string to $input to check if this dumper has been
// selected successfully.
$input = '<pre>' . 'AvailableTestDumper::exportAsRenderable() ' . $input . '</pre>';
return [
'#attached' => [
'library' => ['devel_dumper_test/devel_dumper_test']
],
'#markup' => $this->setSafeMarkup($input),
];
}
/**
* {@inheritdoc}
*/
public static function checkRequirements() {
return TRUE;
}
}
@@ -0,0 +1,41 @@
<?php
namespace Drupal\devel_dumper_test\Plugin\Devel\Dumper;
use Drupal\devel\DevelDumperBase;
/**
* Provides a NotAvailableTestDumper plugin.
*
* @DevelDumper(
* id = "not_available_test_dumper",
* label = @Translation("Not available test dumper."),
* description = @Translation("Drupal dumper for testing purposes (not available).")
* )
*/
class NotAvailableTestDumper extends DevelDumperBase {
/**
* {@inheritdoc}
*/
public function dump($input, $name = NULL) {
$input = '<pre>' . $input . '</pre>';
echo $input;
}
/**
* {@inheritdoc}
*/
public function export($input, $name = NULL) {
$input = '<pre>' . $input . '</pre>';
return $this->setSafeMarkup($input);
}
/**
* {@inheritdoc}
*/
public static function checkRequirements() {
return FALSE;
}
}
@@ -0,0 +1,16 @@
name: 'Devel entity test module'
type: module
description: 'Provides entity types for Devel tests.'
package: Testing
# version: VERSION
# core: 8.x
dependencies:
- field
- text
- entity_test
# Information added by Drupal.org packaging script on 2016-09-03
version: '8.x-1.0-alpha1+23-dev'
core: '8.x'
project: 'devel'
datestamp: 1472897643
@@ -0,0 +1,2 @@
devel_entity_test.local_tasks:
deriver: 'Drupal\devel_entity_test\Plugin\Derivative\DevelEntityTestLocalTasks'
@@ -0,0 +1,29 @@
<?php
/**
* @file
* Test module for the entity API providing several entity types for testing.
*/
/**
* Implements hook_entity_view_mode_info_alter().
*/
function devel_entity_test_entity_view_mode_info_alter(&$view_modes) {
$entity_info = \Drupal::entityTypeManager()->getDefinitions();
foreach ($entity_info as $entity_type => $info) {
if ($entity_info[$entity_type]->getProvider() == 'devel_entity_test_canonical' && !isset($view_modes[$entity_type])) {
$view_modes[$entity_type] = array(
'full' => array(
'label' => t('Full object'),
'status' => TRUE,
'cache' => TRUE,
),
'teaser' => array(
'label' => t('Teaser'),
'status' => TRUE,
'cache' => TRUE,
),
);
}
}
}
@@ -0,0 +1,44 @@
<?php
namespace Drupal\devel_entity_test\Entity;
use Drupal\entity_test\Entity\EntityTest;
/**
* Defines the test entity class.
*
* @ContentEntityType(
* id = "devel_entity_test_canonical",
* label = @Translation("Devel test entity with canonical link"),
* handlers = {
* "list_builder" = "Drupal\entity_test\EntityTestListBuilder",
* "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
* "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
* "form" = {
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
* "views_data" = "Drupal\entity_test\EntityTestViewsData"
* },
* base_table = "devel_entity_test_canonical",
* persistent_cache = FALSE,
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
* "label" = "name",
* "langcode" = "langcode",
* },
* links = {
* "canonical" = "/devel_entity_test_canonical/{devel_entity_test_canonical}",
* },
* field_ui_base_route = "entity.entity_test.admin_form",
* )
*/
class DevelEntityTestCanonical extends EntityTest {
}
@@ -0,0 +1,44 @@
<?php
namespace Drupal\devel_entity_test\Entity;
use Drupal\entity_test\Entity\EntityTest;
/**
* Defines the test entity class.
*
* @ContentEntityType(
* id = "devel_entity_test_edit",
* label = @Translation("Devel test entity with edit form link"),
* handlers = {
* "list_builder" = "Drupal\entity_test\EntityTestListBuilder",
* "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
* "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
* "form" = {
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
* "views_data" = "Drupal\entity_test\EntityTestViewsData"
* },
* base_table = "devel_entity_test_edit",
* persistent_cache = FALSE,
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
* "label" = "name",
* "langcode" = "langcode",
* },
* links = {
* "edit-form" = "/devel_entity_test_edit/manage/{devel_entity_test_edit}",
* },
* field_ui_base_route = "entity.entity_test.admin_form",
* )
*/
class DevelEntityTestEdit extends EntityTest {
}
@@ -0,0 +1,41 @@
<?php
namespace Drupal\devel_entity_test\Entity;
use Drupal\entity_test\Entity\EntityTest;
/**
* Defines the test entity class.
*
* @ContentEntityType(
* id = "devel_entity_test_no_links",
* label = @Translation("Devel test entity with no links"),
* handlers = {
* "list_builder" = "Drupal\entity_test\EntityTestListBuilder",
* "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
* "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
* "form" = {
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
* "views_data" = "Drupal\entity_test\EntityTestViewsData"
* },
* base_table = "devel_entity_test_no_links",
* persistent_cache = FALSE,
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
* "label" = "name",
* "langcode" = "langcode",
* },
* field_ui_base_route = "entity.entity_test.admin_form",
* )
*/
class DevelEntityTestNoLinks extends EntityTest {
}
@@ -0,0 +1,31 @@
<?php
namespace Drupal\devel_entity_test\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
/**
* Defines the local tasks for all the entity_test entities.
*/
class DevelEntityTestLocalTasks extends DeriverBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = array();
$this->derivatives['devel_entity_test_canonical.canonical'] = array();
$this->derivatives['devel_entity_test_canonical.canonical']['base_route'] = "entity.devel_entity_test_canonical.canonical";
$this->derivatives['devel_entity_test_canonical.canonical']['route_name'] = "entity.devel_entity_test_canonical.canonical";
$this->derivatives['devel_entity_test_canonical.canonical']['title'] = 'View';
$this->derivatives['devel_entity_test_edit.edit'] = array();
$this->derivatives['devel_entity_test_edit.edit']['base_route'] = "entity.devel_entity_test_edit.edit_form";
$this->derivatives['devel_entity_test_edit.edit']['route_name'] = "entity.devel_entity_test_edit.edit_form";
$this->derivatives['devel_entity_test_edit.edit']['title'] = 'Edit';
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
@@ -0,0 +1,12 @@
name: 'Devel test module'
type: module
description: 'Support module for Devel testing.'
package: Testing
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2016-09-03
version: '8.x-1.0-alpha1+23-dev'
core: '8.x'
project: 'devel'
datestamp: 1472897643
@@ -0,0 +1,7 @@
devel.simple_page:
path: '/devel/simple-page'
defaults:
_controller: '\Drupal\devel_test\Controller\DevelTestController::simplePage'
_title: 'Simple Page'
requirements:
_permission: 'access devel information'
@@ -0,0 +1,24 @@
<?php
namespace Drupal\devel_test\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Returns responses for devel module routes.
*/
class DevelTestController extends ControllerBase {
/**
* Returns a simple page output.
*
* @return array
* A render array.
*/
public function simplePage() {
return [
'#markup' => $this->t('Simple page'),
];
}
}
@@ -0,0 +1,127 @@
<?php
namespace Drupal\Tests\devel\Kernel;
/**
* Provides a class for checking dumper output.
*/
trait DevelDumperTestTrait {
/**
* Asserts that the string passed in input is equals to the string
* representation of a variable obtained exporting the data.
*
* Use \Drupal\devel\DevelDumperManager::export().
*
* @param $dump
* The string that contains the dump output to test.
* @param $data
* The variable to dump.
* @param null $name
* (optional) The label to output before variable, defaults to NULL.
* @param string $message
* (optional) A message to display with the assertion.
*/
public function assertDumpExportEquals($dump, $data, $name = NULL, $message = '') {
$output = $this->getDumperExportDump($data, $name);
$this->assertEqual(rtrim($dump), $output, $message);
}
/**
* Asserts that a haystack contains the dump export output.
*
* Use \Drupal\devel\DevelDumperManager::export().
*
* @param $haystack
* The string that contains the dump output to test.
* @param $data
* The variable to dump.
* @param null $name
* (optional) The label to output before variable, defaults to NULL.
* @param string $message
* (optional) A message to display with the assertion.
*/
public function assertContainsDumpExport($haystack, $data, $name = NULL, $message = '') {
$output = $this->getDumperExportDump($data, $name);
$this->assertContains($output, (string) $haystack, $message);
}
/**
* Asserts that the string passed in input is equals to the string
* representation of a variable obtained dumping the data.
*
* Use \Drupal\devel\DevelDumperManager::dump().
*
* @param $dump
* The string that contains the dump output to test.
* @param $data
* The variable to dump.
* @param null $name
* (optional) The label to output before variable, defaults to NULL.
* @param string $message
* (optional) A message to display with the assertion.
*/
public function assertDumpEquals($dump, $data, $name = NULL, $message = '') {
$output = $this->getDumperDump($data, $name);
$this->assertEqual(rtrim($dump), $output, $message);
}
/**
* Asserts that a haystack contains the dump output.
*
* Use \Drupal\devel\DevelDumperManager::dump().
*
* @param $haystack
* The string that contains the dump output to test.
* @param $data
* The variable to dump.
* @param null $name
* (optional) The label to output before variable, defaults to NULL.
* @param string $message
* (optional) A message to display with the assertion.
*/
public function assertContainsDump($haystack, $data, $name = NULL, $message = '') {
$output = $this->getDumperDump($data, $name);
$this->assertContains($output, (string) $haystack, $message);
}
/**
* Returns a string representation of a variable.
*
* @param mixed $input
* The variable to dump.
* @param string $name
* (optional) The label to output before variable, defaults to NULL.
*
* @return string
* String representation of a variable.
*
* @see \Drupal\devel\DevelDumperManager::export()
*/
private function getDumperExportDump($input, $name = NULL) {
$output = \Drupal::service('devel.dumper')->export($input, $name);
return rtrim($output);
}
/**
* Returns a string representation of a variable.
*
* @param mixed $input
* The variable to dump.
* @param string $name
* (optional) The label to output before variable, defaults to NULL.
*
* @return string
* String representation of a variable.
*
* @see \Drupal\devel\DevelDumperManager::dump()
*/
private function getDumperDump($input, $name = NULL) {
ob_start();
\Drupal::service('devel.dumper')->dump($input, $name);
$output = ob_get_contents();
ob_end_clean();
return rtrim($output);
}
}
@@ -0,0 +1,80 @@
<?php
namespace Drupal\Tests\devel\Kernel;
use Drupal\block\Entity\Block;
use Drupal\KernelTests\KernelTestBase;
use Drupal\system\Entity\Menu;
/**
* Tests Devel enforced dependencies.
*
* @group devel
*/
class DevelEnforcedDependenciesTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['devel', 'block', 'user', 'system'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
$this->installConfig('devel');
// For uninstall to work.
$this->installSchema('user', ['users_data']);
}
/**
* Tests devel menu enforced dependencies.
*/
public function testMenuEnforcedDependencies() {
/** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
$config_manager = $this->container->get('config.manager');
// Ensure that the Devel menu has explicit enforced dependencies on devel
// module.
$menu = Menu::load('devel');
$this->assertEquals(['enforced' => ['module' => ['devel']]], $menu->get('dependencies'));
// Creates an instance of devel menu block so you can test if enforced
// dependencies work properly with it.
$block_id = strtolower($this->randomMachineName(8));
$block = Block::create([
'plugin' => 'system_menu_block:devel',
'region' => 'sidebar_first',
'id' => $block_id,
'theme' => $this->config('system.theme')->get('default'),
'label' => $this->randomMachineName(8),
'visibility' => array(),
'weight' => 0,
]);
$block->save();
// Ensure that the menu and block instance depend on devel module.
$dependents = $config_manager->findConfigEntityDependents('module', ['devel']);
$this->assertTrue(isset($dependents['system.menu.devel']));
$this->assertTrue(isset($dependents['block.block.' . $block_id]));
$this->container->get('module_installer')->uninstall(['devel']);
// Ensure that the menu and block instance are deleted when the dependency
// is uninstalled.
$this->assertNull(Menu::load('devel'));
$this->assertNull(Block::load($block_id));
// Ensure that no config entities depend on devel once uninstalled.
$dependents = $config_manager->findConfigEntityDependents('module', ['devel']);
$this->assertFalse(isset($dependents['system.menu.devel']));
$this->assertFalse(isset($dependents['block.block.' . $block_id]));
}
}
@@ -0,0 +1,203 @@
<?php
namespace Drupal\Tests\devel\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
use Drupal\devel\Twig\Extension\Debug;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
/**
* Tests Twig extensions.
*
* @group devel
*/
class DevelTwigExtensionTest extends KernelTestBase {
use DevelDumperTestTrait;
/**
* The user used in test.
*
* @var \Drupal\user\UserInterface
*/
protected $develUser;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['devel', 'user', 'system'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
$this->installSchema('system', 'sequences');
$devel_role = Role::create([
'id' => 'admin',
'permissions' => ['access devel information'],
]);
$devel_role->save();
$this->develUser = User::create([
'name' => $this->randomMachineName(),
'roles' => [$devel_role->id()],
]);
$this->develUser->save();
}
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
parent::register($container);
$parameters = $container->getParameter('twig.config');
$parameters['debug'] = TRUE;
$container->setParameter('twig.config', $parameters);
}
/**
* Tests that Twig extension loads appropriately.
*/
public function testTwigExtensionLoaded() {
$twig_service = \Drupal::service('twig');
$extension = $twig_service->getExtension('devel_debug');
$this->assertEquals(get_class($extension), Debug::class, 'Debug Extension loaded successfully.');
}
/**
* Tests that the Twig dump functions are registered properly.
*/
public function testDumpFunctionsRegistered() {
/** @var \Twig_SimpleFunction[] $functions */
$functions = \Drupal::service('twig')->getFunctions();
$dump_functions = ['devel_dump', 'kpr'];
$message_functions = ['devel_message', 'dpm', 'dsm'];
$registered_functions = $dump_functions + $message_functions;
foreach ($registered_functions as $name) {
$function = $functions[$name];
$this->assertTrue($function instanceof \Twig_SimpleFunction);
$this->assertEquals($function->getName(), $name);
$this->assertTrue($function->needsContext());
$this->assertTrue($function->needsEnvironment());
$this->assertTrue($function->isVariadic());
is_callable($function->getCallable(), TRUE, $callable);
if (in_array($name, $dump_functions)) {
$this->assertEquals($callable, 'Drupal\devel\Twig\Extension\Debug::dump');
}
else {
$this->assertEquals($callable, 'Drupal\devel\Twig\Extension\Debug::message');
}
}
}
/**
* Tests that the Twig function for XDebug integration is registered properly.
*/
public function testXDebugIntegrationFunctionsRegistered() {
/** @var \Twig_SimpleFunction $function */
$function = \Drupal::service('twig')->getFunction('devel_breakpoint');
$this->assertTrue($function instanceof \Twig_SimpleFunction);
$this->assertEquals($function->getName(), 'devel_breakpoint');
$this->assertTrue($function->needsContext());
$this->assertTrue($function->needsEnvironment());
$this->assertTrue($function->isVariadic());
is_callable($function->getCallable(), TRUE, $callable);
$this->assertEquals($callable, 'Drupal\devel\Twig\Extension\Debug::breakpoint');
}
/**
* Tests that the Twig extension's dump functions produce the expected output.
*/
public function testDumpFunctions() {
$template = 'test-with-context {{ twig_string }} {{ twig_array.first }} {{ twig_array.second }}{{ devel_dump() }}';
$expected_template_output = 'test-with-context context! first value second value';
$context = [
'twig_string' => 'context!',
'twig_array' => [
'first' => 'first value',
'second' => 'second value',
],
'twig_object' => new \stdClass(),
];
/** @var \Drupal\Core\Template\TwigEnvironment $environment */
$environment = \Drupal::service('twig');
// Ensures that the twig extension does nothing if the current
// user has not the adequate permission.
$this->assertTrue($environment->isDebug());
$this->assertEquals($environment->renderInline($template, $context), $expected_template_output);
\Drupal::currentUser()->setAccount($this->develUser);
// Ensures that if no argument is passed to the function the twig context is
// dumped.
$output = (string) $environment->renderInline($template, $context);
$this->assertContains($expected_template_output, $output);
$this->assertContainsDump($output, $context, 'Twig context');
// Ensures that if an argument is passed to the function it is dumped.
$template = 'test-with-context {{ twig_string }} {{ twig_array.first }} {{ twig_array.second }}{{ devel_dump(twig_array) }}';
$output = (string) $environment->renderInline($template, $context);
$this->assertContains($expected_template_output, $output);
$this->assertContainsDump($output, $context['twig_array']);
// Ensures that if more than one argument is passed the function works
// properly and every argument is dumped separately.
$template = 'test-with-context {{ twig_string }} {{ twig_array.first }} {{ twig_array.second }}{{ devel_dump(twig_string, twig_array.first, twig_array, twig_object) }}';
$output = (string) $environment->renderInline($template, $context);
$this->assertContains($expected_template_output, $output);
$this->assertContainsDump($output, $context['twig_string']);
$this->assertContainsDump($output, $context['twig_array']['first']);
$this->assertContainsDump($output, $context['twig_array']);
$this->assertContainsDump($output, $context['twig_object']);
// Clear messages.
drupal_get_messages();
$retrieve_message = function ($messages, $index) {
return isset($messages['status'][$index]) ? (string) $messages['status'][$index] : NULL;
};
// Ensures that if no argument is passed to the function the twig context is
// dumped.
$template = 'test-with-context {{ twig_string }} {{ twig_array.first }} {{ twig_array.second }}{{ devel_message() }}';
$output = (string) $environment->renderInline($template, $context);
$this->assertContains($expected_template_output, $output);
$messages = drupal_get_messages();
$this->assertDumpExportEquals($retrieve_message($messages, 0), $context, 'Twig context');
// Ensures that if an argument is passed to the function it is dumped.
$template = 'test-with-context {{ twig_string }} {{ twig_array.first }} {{ twig_array.second }}{{ devel_message(twig_array) }}';
$output = (string) $environment->renderInline($template, $context);
$this->assertContains($expected_template_output, $output);
$messages = drupal_get_messages();
$this->assertDumpExportEquals($retrieve_message($messages, 0), $context['twig_array']);
// Ensures that if more than one argument is passed to the function works
// properly and every argument is dumped separately.
$template = 'test-with-context {{ twig_string }} {{ twig_array.first }} {{ twig_array.second }}{{ devel_message(twig_string, twig_array.first, twig_array, twig_object) }}';
$output = (string) $environment->renderInline($template, $context);
$this->assertContains($expected_template_output, $output);
$messages = drupal_get_messages();
$this->assertDumpExportEquals($retrieve_message($messages, 0), $context['twig_string']);
$this->assertDumpExportEquals($retrieve_message($messages, 1), $context['twig_array']['first']);
$this->assertDumpExportEquals($retrieve_message($messages, 2), $context['twig_array']);
$this->assertDumpExportEquals($retrieve_message($messages, 3), $context['twig_object']);
}
}