View source
<?php
namespace Drupal\Tests\update\Kernel;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
class UpdateReportTest extends KernelTestBase {
use UserCreationTrait;
protected static $modules = [
'system',
'update',
];
public function testTemplatePreprocessUpdateReport($variables) {
\Drupal::moduleHandler()
->loadInclude('update', 'inc', 'update.report');
template_preprocess_update_report($variables);
$this
->assertArrayHasKey('no_updates_message', $variables);
}
public function providerTemplatePreprocessUpdateReport() {
return [
'$variables with data not set' => [
[],
],
'$variables with data as an integer' => [
[
'data' => 4,
],
],
'$variables with data as a string' => [
[
'data' => 'I am a string',
],
],
];
}
public function testTemplatePreprocessUpdateFetchErrorMessageNoDblog() {
$build = [
'#theme' => 'update_fetch_error_message',
];
$this
->render($build);
$this
->assertRaw('Failed to fetch available update data:<ul><li>See <a href="https://www.drupal.org/node/3170647">PHP OpenSSL requirements</a> in the Drupal.org handbook for possible reasons this could happen and what you can do to resolve them.</li><li>Check your local system logs for additional error messages.</li></ul>');
\Drupal::moduleHandler()
->loadInclude('update', 'inc', 'update.report');
$variables = [];
template_preprocess_update_fetch_error_message($variables);
$this
->assertArrayHasKey('error_message', $variables);
$this
->assertEquals('Failed to fetch available update data:', $variables['error_message']['message']['#markup']);
$this
->assertArrayHasKey('documentation_link', $variables['error_message']['items']['#items']);
$this
->assertArrayHasKey('logs', $variables['error_message']['items']['#items']);
$this
->assertArrayNotHasKey('dblog', $variables['error_message']['items']['#items']);
}
public function testTemplatePreprocessUpdateFetchErrorMessageWithDblog() {
\Drupal::moduleHandler()
->loadInclude('update', 'inc', 'update.report');
$this
->enableModules([
'dblog',
'user',
]);
$this
->installEntitySchema('user');
$this
->setUpCurrentUser();
$build = [
'#theme' => 'update_fetch_error_message',
];
$this
->render($build);
$this
->assertRaw('Failed to fetch available update data:<ul><li>See <a href="https://www.drupal.org/node/3170647">PHP OpenSSL requirements</a> in the Drupal.org handbook for possible reasons this could happen and what you can do to resolve them.</li><li>Check your local system logs for additional error messages.</li></ul>');
$variables = [];
template_preprocess_update_fetch_error_message($variables);
$this
->assertArrayHasKey('error_message', $variables);
$this
->assertEquals('Failed to fetch available update data:', $variables['error_message']['message']['#markup']);
$this
->assertArrayHasKey('documentation_link', $variables['error_message']['items']['#items']);
$this
->assertArrayHasKey('logs', $variables['error_message']['items']['#items']);
$this
->assertArrayNotHasKey('dblog', $variables['error_message']['items']['#items']);
$this
->setUpCurrentUser([], [
'access content',
'access site reports',
]);
$this
->render($build);
$this
->assertRaw('Failed to fetch available update data:<ul><li>See <a href="https://www.drupal.org/node/3170647">PHP OpenSSL requirements</a> in the Drupal.org handbook for possible reasons this could happen and what you can do to resolve them.</li><li>Check');
$dblog_url = Url::fromRoute('dblog.overview', [], [
'query' => [
'type' => [
'update',
],
],
]);
$this
->assertRaw(Link::fromTextAndUrl('your local system logs', $dblog_url)
->toString());
$this
->assertRaw(' for additional error messages.</li></ul>');
$variables = [];
template_preprocess_update_fetch_error_message($variables);
$this
->assertArrayHasKey('error_message', $variables);
$this
->assertEquals('Failed to fetch available update data:', $variables['error_message']['message']['#markup']);
$this
->assertArrayHasKey('documentation_link', $variables['error_message']['items']['#items']);
$this
->assertArrayNotHasKey('logs', $variables['error_message']['items']['#items']);
$this
->assertArrayHasKey('dblog', $variables['error_message']['items']['#items']);
}
}