Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,9 @@
name: 'Dblog test views'
type: module
description: 'Provides default views for views dblog tests.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- dblog
- views

View file

@ -0,0 +1,65 @@
langcode: en
status: true
dependencies:
module:
- dblog
id: test_dblog
label: test_dblog
module: views
description: ''
tag: ''
base_table: watchdog
base_field: wid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: null
display_options:
access:
type: none
cache:
type: tag
query:
type: views_query
exposed_form:
type: basic
pager:
type: full
style:
type: default
row:
type: fields
fields:
wid:
id: wid
table: watchdog
field: wid
plugin_id: numeric
message:
id: message
table: watchdog
field: message
plugin_id: dblog_message
link:
id: link
table: watchdog
field: link
plugin_id: dblog_operations
filters: { }
sorts:
wid:
id: wid
table: watchdog
field: wid
order: ASC
plugin_id: standard
page_1:
display_plugin: page
id: page_1
display_title: Page
position: null
display_options:
path: test-dblog

View file

@ -0,0 +1,41 @@
<?php
namespace Drupal\Tests\dblog\Kernel;
use Drupal\dblog\Controller\DbLogController;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests for the DbLogController class.
*
* @group dblog
*/
class DbLogControllerTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['dblog', 'user'];
/**
* Tests corrupted log entries can still display available data.
*/
public function testDbLogCorrupted() {
$this->installEntitySchema('user');
$dblog_controller = DbLogController::create($this->container);
// Check message with properly serialized data.
$message = (object) [
'message' => 'Sample message with placeholder: @placeholder',
'variables' => serialize(['@placeholder' => 'test placeholder']),
];
$this->assertEquals('Sample message with placeholder: test placeholder', $dblog_controller->formatMessage($message));
// Check that controller work with corrupted data.
$message->variables = 'BAD SERIALIZED DATA';
$formatted = $dblog_controller->formatMessage($message);
$this->assertEquals('Log data is corrupted and cannot be unserialized: Sample message with placeholder: @placeholder', $formatted);
}
}

View file

@ -0,0 +1,109 @@
<?php
namespace Drupal\Tests\dblog\Kernel;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User;
/**
* Tests serializing a form with an injected dblog logger instance.
*
* @group dblog
*/
class DbLogFormInjectionTest extends KernelTestBase implements FormInterface {
use DependencySerializationTrait;
/**
* A Dblog logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('system', 'dblog', 'user');
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'dblog_test_injection_form';
}
/**
* Process callback.
*
* @param array $element
* Form element
*
* @return array
* Processed element.
*/
public function process($element) {
return $element;
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#process'][] = [$this, 'process'];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRebuild();
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('dblog', ['watchdog']);
$this->installSchema('system', ['key_value_expire', 'sequences']);
$this->installEntitySchema('user');
$this->logger = \Drupal::logger('test_logger');
$test_user = User::create(array(
'name' => 'foobar',
'mail' => 'foobar@example.com',
));
$test_user->save();
\Drupal::service('current_user')->setAccount($test_user);
}
/**
* Tests db log injection serialization.
*/
public function testLoggerSerialization() {
$form_state = new FormState();
// Forms are only serialized during POST requests.
$form_state->setRequestMethod('POST');
$form_state->setCached();
$form_builder = $this->container->get('form_builder');
$form_id = $form_builder->getFormId($this, $form_state);
$form = $form_builder->retrieveForm($form_id, $form_state);
$form_builder->prepareForm($form_id, $form, $form_state);
$form_builder->processForm($form_id, $form, $form_state);
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace Drupal\Tests\dblog\Kernel\Migrate\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to dblog.settings.yml.
*
* @group migrate_drupal_6
*/
class MigrateDblogConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['dblog'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_dblog_settings');
}
/**
* Tests migration of dblog variables to dblog.settings.yml.
*/
public function testBookSettings() {
$config = $this->config('dblog.settings');
$this->assertIdentical(10000, $config->get('row_limit'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'dblog.settings', $config->get());
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\dblog\Kernel\Migrate\d7;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Upgrade variables to dblog.settings.yml.
*
* @group migrate_drupal_7
*/
class MigrateDblogConfigsTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['dblog'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigration('d7_dblog_settings');
}
/**
* Tests migration of dblog variables to dblog.settings.yml.
*/
public function testDblogSettings() {
$config = $this->config('dblog.settings');
$this->assertIdentical(10000, $config->get('row_limit'));
}
}

View file

@ -0,0 +1,116 @@
<?php
namespace Drupal\Tests\dblog\Kernel\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Url;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the views integration of dblog module.
*
* @group dblog
*/
class ViewsIntegrationTest extends ViewsKernelTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_dblog');
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('dblog', 'dblog_test_views', 'user');
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp();
// Rebuild the router, otherwise we can't generate links.
$this->container->get('router.builder')->rebuild();
$this->installSchema('dblog', array('watchdog'));
ViewTestData::createTestViews(get_class($this), array('dblog_test_views'));
}
/**
* Tests the integration.
*/
public function testIntegration() {
// Remove the watchdog entries added by the potential batch process.
$this->container->get('database')->truncate('watchdog')->execute();
$entries = array();
// Setup a watchdog entry without tokens.
$entries[] = array(
'message' => $this->randomMachineName(),
'variables' => array('link' => \Drupal::l('Link', new Url('<front>'))),
);
// Setup a watchdog entry with one token.
$entries[] = array(
'message' => '@token1',
'variables' => array('@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', new Url('<front>'))),
);
// Setup a watchdog entry with two tokens.
$entries[] = array(
'message' => '@token1 @token2',
// Setup a link with a tag which is filtered by
// \Drupal\Component\Utility\Xss::filterAdmin() in order to make sure
// that strings which are not marked as safe get filtered.
'variables' => array(
'@token1' => $this->randomMachineName(),
'@token2' => $this->randomMachineName(),
'link' => '<a href="' . \Drupal::url('<front>') . '"><object>Link</object></a>',
),
);
$logger_factory = $this->container->get('logger.factory');
foreach ($entries as $entry) {
$entry += array(
'type' => 'test-views',
'severity' => RfcLogLevel::NOTICE,
);
$logger_factory->get($entry['type'])->log($entry['severity'], $entry['message'], $entry['variables']);
}
$view = Views::getView('test_dblog');
$this->executeView($view);
$view->initStyle();
foreach ($entries as $index => $entry) {
$this->assertEqual($view->style_plugin->getField($index, 'message'), SafeMarkup::format($entry['message'], $entry['variables']));
$link_field = $view->style_plugin->getField($index, 'link');
// The 3rd entry contains some unsafe markup that needs to get filtered.
if ($index == 2) {
// Make sure that unsafe link differs from the rendered link, so we know
// that some filtering actually happened.
$this->assertNotEqual($link_field, $entry['variables']['link']);
}
$this->assertEqual($link_field, Xss::filterAdmin($entry['variables']['link']));
}
// Disable replacing variables and check that the tokens aren't replaced.
$view->destroy();
$view->storage->invalidateCaches();
$view->initHandlers();
$this->executeView($view);
$view->initStyle();
$view->field['message']->options['replace_variables'] = FALSE;
foreach ($entries as $index => $entry) {
$this->assertEqual($view->style_plugin->getField($index, 'message'), $entry['message']);
}
}
}