<?php
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
function update_test_system_theme_info() {
$themes['update_test_basetheme'] = drupal_get_path('module', 'update') . '/tests/themes/update_test_basetheme/update_test_basetheme.info.yml';
$themes['update_test_subtheme'] = drupal_get_path('module', 'update') . '/tests/themes/update_test_subtheme/update_test_subtheme.info.yml';
return $themes;
}
function update_test_menu() {
$items = array();
$items['update-test'] = array(
'title' => t('Update test'),
'page callback' => 'update_test_mock_page',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['503-error'] = array(
'title' => t('503 Service unavailable'),
'page callback' => 'update_callback_service_unavailable',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function update_test_system_info_alter(&$info, $file) {
$setting = config('update_test.settings')
->get('system_info');
foreach (array(
'#all',
$file->name,
) as $id) {
if (!empty($setting[$id])) {
foreach ($setting[$id] as $key => $value) {
$info[$key] = $value;
}
}
}
}
function update_test_update_status_alter(&$projects) {
$setting = config('update_test.settings')
->get('update_status');
if (!empty($setting)) {
foreach ($projects as $project_name => &$project) {
foreach (array(
'#all',
$project_name,
) as $id) {
if (!empty($setting[$id])) {
foreach ($setting[$id] as $key => $value) {
$project[$key] = $value;
}
}
}
}
}
}
function update_test_mock_page($project_name) {
$xml_map = config('update_test.settings')
->get('xml_map');
if (isset($xml_map[$project_name])) {
$availability_scenario = $xml_map[$project_name];
}
elseif (isset($xml_map['#all'])) {
$availability_scenario = $xml_map['#all'];
}
else {
$availability_scenario = '#broken#';
}
$path = drupal_get_path('module', 'update_test');
$file = "{$path}/{$project_name}.{$availability_scenario}.xml";
$headers = array(
'Content-Type' => 'text/xml; charset=utf-8',
);
if (!is_file($file)) {
return new Response('', 200, $headers);
}
return new BinaryFileResponse($file, 200, $headers);
}
function update_test_archiver_info_alter(&$definitions) {
$definitions['update_test_archiver'] = array(
'extensions' => array(
'update-test-extension',
),
);
}
function update_test_filetransfer_info() {
return array(
'system_test' => array(
'title' => t('Update Test FileTransfer'),
'class' => 'Drupal\\update_test\\MockFileTransfer',
'weight' => -20,
),
);
}
function update_callback_service_unavailable() {
drupal_add_http_header('Status', '503 Service unavailable');
print "503 Service Temporarily Unavailable";
}