Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 95 additions & 5 deletions admin/tinymce/front_page_button/plugin.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,124 @@
text: 'Service Body',
menu: [
{
text: 'Service Body 1',
text: 'Service Body 1 (UPPER CASE)',
onclick: function () {
editor.insertContent('[service_body_1]');
}
},
{
text: 'Service Body 2',
text: 'Service Body 1 (as stored)',
onclick: function () {
editor.insertContent('[service_body_1_name]');
}
},
{
text: 'Service Body 1 Description',
onclick: function () {
editor.insertContent('[service_body_1_description]');
}
},
{
text: 'Service Body 1 Helpline',
onclick: function () {
editor.insertContent('[service_body_1_helpline]');
}
},
{
text: 'Service Body 2 (UPPER CASE)',
onclick: function () {
editor.insertContent('[service_body_2]');
}
},
{
text: 'Service Body 3',
text: 'Service Body 2 (as stored)',
onclick: function () {
editor.insertContent('[service_body_2_name]');
}
},
{
text: 'Service Body 2 Description',
onclick: function () {
editor.insertContent('[service_body_2_description]');
}
},
{
text: 'Service Body 2 Helpline',
onclick: function () {
editor.insertContent('[service_body_2_helpline]');
}
},
{
text: 'Service Body 3 (UPPER CASE)',
onclick: function () {
editor.insertContent('[service_body_3]');
}
},
{
text: 'Service Body 4',
text: 'Service Body 3 (as stored)',
onclick: function () {
editor.insertContent('[service_body_3_name]');
}
},
{
text: 'Service Body 3 Description',
onclick: function () {
editor.insertContent('[service_body_3_description]');
}
},
{
text: 'Service Body 3 Helpline',
onclick: function () {
editor.insertContent('[service_body_3_helpline]');
}
},
{
text: 'Service Body 4 (UPPER CASE)',
onclick: function () {
editor.insertContent('[service_body_4]');
}
},
{
text: 'Service Body 5',
text: 'Service Body 4 (as stored)',
onclick: function () {
editor.insertContent('[service_body_4_name]');
}
},
{
text: 'Service Body 4 Description',
onclick: function () {
editor.insertContent('[service_body_4_description]');
}
},
{
text: 'Service Body 4 Helpline',
onclick: function () {
editor.insertContent('[service_body_4_helpline]');
}
},
{
text: 'Service Body 5 (UPPER CASE)',
onclick: function () {
editor.insertContent('[service_body_5]');
}
},
{
text: 'Service Body 5 (as stored)',
onclick: function () {
editor.insertContent('[service_body_5_name]');
}
},
{
text: 'Service Body 5 Description',
onclick: function () {
editor.insertContent('[service_body_5_description]');
}
},
{
text: 'Service Body 5 Helpline',
onclick: function () {
editor.insertContent('[service_body_5_helpline]');
}
}
]
},
Expand Down
10 changes: 10 additions & 0 deletions includes/class-bread-bmlt.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Bread_Bmlt
public $connection_error;
private $bmlt_server_lang = '';
private array $unique_areas;
private array $service_bodies_by_id = [];
private Bread $bread;
private ?array $preloaded = null;

Expand Down Expand Up @@ -72,6 +73,7 @@ public function get_areas()
$this->unique_areas = array();

foreach ($result as $value) {
$this->service_bodies_by_id[$value['id']] = $value;
$parent_name = 'Parent ID';
foreach ($result as $parent) {
if ($value['parent_id'] == $parent['id']) {
Expand All @@ -86,6 +88,14 @@ public function get_areas()

return $this->unique_areas;
}
/**
* Returns the GetServiceBodies entry for $id, or null.
*/
public function get_service_body(string $id): ?array
{
$this->get_areas();
return $this->service_bodies_by_id[$id] ?? null;
}
public function generateMainQuery($json = 'json')
{
$sort_keys = 'weekday_tinyint,start_time,meeting_name';
Expand Down
34 changes: 28 additions & 6 deletions public/class-bread-content-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,9 @@ function __construct(Mpdf $mpdf, Bread $bread, array $result_meetings, Bread_For
"[month]" => strtoupper(gmdate("F")),
"[day]" => strtoupper(gmdate("j")),
"[year]" => strtoupper(gmdate("Y")),
"[service_body]" => (count($this->options['service_bodies']) > 0) ? explode(',', strtoupper($this->options['service_bodies'][0]))[0] : 'Not Used',
"[service_body_1]" => (count($this->options['service_bodies']) > 0) ?explode(',', strtoupper($this->options['service_bodies'][0]))[0] : 'Not Used',
"[service_body_2]" => (count($this->options['service_bodies']) > 1) ? explode(',', strtoupper($this->options['service_bodies'][1]))[0] : 'Not Used',
"[service_body_3]" => (count($this->options['service_bodies']) > 2) ? explode(',', strtoupper($this->options['service_bodies'][2]))[0] : 'Not Used',
"[service_body_4]" => (count($this->options['service_bodies']) > 3) ? explode(',', strtoupper($this->options['service_bodies'][3]))[0] : 'Not Used',
"[service_body_5]" => (count($this->options['service_bodies']) > 4) ? explode(',', strtoupper($this->options['service_bodies'][4]))[0] : 'Not Used',

);
$this->addServiceBodyShortcodes();
$this->shortcodes = apply_filters("Bread_Section_Shortcodes", $this->shortcodes, $this->bread->bmlt()->get_areas(), $formatsManager->getFormatsUsed());
if ($this->options['page_fold'] == 'half' || $this->options['page_fold'] == 'full') {
@$this->mpdf->DefHTMLFooterByName('MyFooter', '<div style="text-align:center;font-size:' . $this->options['pagenumbering_font_size'] . 'pt;font-style: italic;">' . $this->options['nonmeeting_footer'] . '</div>');
Expand Down Expand Up @@ -176,6 +171,33 @@ function __construct(Mpdf $mpdf, Bread $bread, array $result_meetings, Bread_For
'line_break' => '<br />',
);
}
/**
* Adds [service_body_N] (upper case), [service_body_N_name], [service_body_N_description] and [service_body_N_helpline].
*/
private function addServiceBodyShortcodes(): void
{
for ($i = 0; $i < 5; $i++) {
$name = 'Not Used';
$description = 'Not Used';
$helpline = 'Not Used';
if (isset($this->options['service_bodies'][$i])) {
$area_data = explode(',', $this->options['service_bodies'][$i]);
$name = $area_data[0];
$service_body = isset($area_data[1]) ? $this->bread->bmlt()->get_service_body($area_data[1]) : null;
$description = $service_body['description'] ?? '';
$helpline = $service_body['helpline'] ?? '';
}
$n = $i + 1;
$this->shortcodes["[service_body_$n]"] = $name == 'Not Used' ? $name : mb_strtoupper($name, 'UTF-8');
$this->shortcodes["[service_body_{$n}_name]"] = $name;
$this->shortcodes["[service_body_{$n}_description]"] = $description;
$this->shortcodes["[service_body_{$n}_helpline]"] = $helpline;
}
$this->shortcodes['[service_body]'] = $this->shortcodes['[service_body_1]'];
$this->shortcodes['[service_body_name]'] = $this->shortcodes['[service_body_1_name]'];
$this->shortcodes['[service_body_description]'] = $this->shortcodes['[service_body_1_description]'];
$this->shortcodes['[service_body_helpline]'] = $this->shortcodes['[service_body_1_helpline]'];
}
/**
* Generates the contents of the meeting list.
*
Expand Down
110 changes: 110 additions & 0 deletions tests/BreadContentGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

use Mpdf\Mpdf;
use PHPUnit\Framework\TestCase;

use function PHPUnit\Framework\assertEquals;

final class BreadContentGeneratorTest extends TestCase
{
private function getConfiguration(string $config): array
{
$json = file_get_contents('tests/configurations/' . $config . ".json");
return json_decode($json, true);
}
private function getServiceBodies(string $service_bodies): array
{
$json = file_get_contents('tests/serviceBodies/' . $service_bodies . ".json");
return json_decode($json, true);
}
private function getFormats($formats)
{
$json = file_get_contents('tests/formats/' . $formats . ".json");
return json_decode($json, true)['formats'];
}
public function testServiceBodyShortcodes()
{
$this->doTest(
'berlin-booklet',
[],
'berlin-service-bodies',
[
'[service_body]' => 'GEBIET BERLIN',
'[service_body_name]' => 'Gebiet Berlin',
'[service_body_description]' => 'Zuständig für: Berlin und Umland',
'[service_body_helpline]' => '+49 30 12345678',
'[service_body_1]' => 'GEBIET BERLIN',
'[service_body_1_name]' => 'Gebiet Berlin',
'[service_body_1_description]' => 'Zuständig für: Berlin und Umland',
'[service_body_1_helpline]' => '+49 30 12345678',
'[service_body_2]' => 'Not Used',
'[service_body_2_name]' => 'Not Used',
'[service_body_2_description]' => 'Not Used',
'[service_body_2_helpline]' => 'Not Used',
'[service_body_5]' => 'Not Used',
'[service_body_5_name]' => 'Not Used',
'[service_body_5_description]' => 'Not Used',
'[service_body_5_helpline]' => 'Not Used',
]
);
}
public function testServiceBodyShortcodesMultiple()
{
$this->doTest(
'berlin-booklet',
['service_bodies' => [
'Gebiet Süd,7,1,Deutschsprachige Region',
'Gebiet Österreich,10,1,Deutschsprachige Region',
'Online Gebiet,12,1,Deutschsprachige Region',
]],
'berlin-service-bodies',
[
'[service_body_1]' => 'GEBIET SÜD',
'[service_body_1_name]' => 'Gebiet Süd',
'[service_body_1_description]' => 'Zuständig für: Stuttgart, Bayern, Österreich',
'[service_body_1_helpline]' => '0800 4453362',
'[service_body_2]' => 'GEBIET ÖSTERREICH',
'[service_body_2_name]' => 'Gebiet Österreich',
'[service_body_2_description]' => 'Zuständig für: Österreich',
'[service_body_2_helpline]' => '',
'[service_body_3]' => 'ONLINE GEBIET',
'[service_body_3_name]' => 'Online Gebiet',
'[service_body_3_description]' => '',
'[service_body_3_helpline]' => '',
'[service_body_4]' => 'Not Used',
]
);
}
public function testServiceBodyMissingFromBmlt()
{
$this->doTest(
'berlin-booklet',
['service_bodies' => ['Gebiet Gelöscht,99,1,Deutschsprachige Region']],
'berlin-service-bodies',
[
'[service_body_1]' => 'GEBIET GELÖSCHT',
'[service_body_1_name]' => 'Gebiet Gelöscht',
'[service_body_1_description]' => '',
'[service_body_1_helpline]' => '',
]
);
}
public function doTest($config, $changes, $serviceBodiesJson, $expected): void
{
$options = $this->getConfiguration($config);
foreach ($changes as $key => $value) {
$options[$key] = $value;
}
$bread = new Bread($options);
$bread->bmlt()->setFormatBase('german-formats');
$bread->bmlt()->set_service_bodies($this->getServiceBodies($serviceBodiesJson));
$formats = $this->getFormats('berlin-formats-de');
$formatMgr = new Bread_FormatsManager($formats, 'de', $bread->bmlt());

$generator = new Bread_ContentGenerator($this->createMock(Mpdf::class), $bread, [], $formatMgr);
$shortcodes = (new ReflectionProperty($generator, 'shortcodes'))->getValue($generator);
foreach ($expected as $shortcode => $value) {
assertEquals($value, $shortcodes[$shortcode], $shortcode);
}
}
}
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require_once __DIR__.'/../public/class-bread-meetingslist-structure.php';
require_once __DIR__.'/../public/class-bread-meeting-enhancer.php';
require_once __DIR__.'/../public/class-bread-format-manager.php';
require_once __DIR__.'/../public/class-bread-content-generator.php';
// Mock WordPress functions used for testing.
//phpcs:ignore
function apply_filters($hook_name, $value, $args)
Expand Down
Loading