Skip to content

Commit

Permalink
Add processors for "details" and "detailsummary" macros
Browse files Browse the repository at this point in the history
Fixes
- #101
- #103
  • Loading branch information
Robert Vogel committed Dec 2, 2024
1 parent 6b9adc9 commit b123ddc
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Composer/_defaultpages/Template/Details
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{SimplePanel
|type=info
|title={{{headings|}}}
|body={{{cql|}}}
}}
6 changes: 6 additions & 0 deletions src/Composer/_defaultpages/Template/DetailsSummary
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{| class="mw-collapsible mw-collapsed wikitable"
! {{{title|}}}
|-
|
{{{body|}}}
|}
6 changes: 6 additions & 0 deletions src/Composer/_defaultpages/Template/Excerpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{| class="mw-collapsible mw-collapsed wikitable"
! {{{title|}}}
|-
|
{{{body|}}}
|}
4 changes: 4 additions & 0 deletions src/Converter/ConfluenceConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use HalloWelt\MigrateConfluence\Converter\Processor\ConvertTaskListMacro;
use HalloWelt\MigrateConfluence\Converter\Processor\ConvertTipMacro;
use HalloWelt\MigrateConfluence\Converter\Processor\ConvertWarningMacro;
use HalloWelt\MigrateConfluence\Converter\Processor\DetailsMacro;
use HalloWelt\MigrateConfluence\Converter\Processor\DetailsSummaryMacro;
use HalloWelt\MigrateConfluence\Converter\Processor\Emoticon;
use HalloWelt\MigrateConfluence\Converter\Processor\ExpandMacro;
use HalloWelt\MigrateConfluence\Converter\Processor\Image;
Expand Down Expand Up @@ -251,6 +253,8 @@ private function runProcessors( $dom ) {
),
new StructuredMacroContenByLabel( $this->currentPageTitle ),
new ExpandMacro(),
new DetailsMacro(),
new DetailsSummaryMacro(),
new MacroAlign(),
new StructuredMacroJira(),
new StructuredMacroViewFile(
Expand Down
27 changes: 27 additions & 0 deletions src/Converter/Processor/DetailsMacro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace HalloWelt\MigrateConfluence\Converter\Processor;

/**
* <ac:structured-macro ac:name="details" ac:schema-version="1" ac:macro-id="...">
* <ac:parameter ac:name="id">control</ac:parameter>
* <ac:rich-text-body>
* <h3>Control details</h3>
* <table class="wrapped">
*/
class DetailsMacro extends ConvertMacroToTemplateBase {

/**
* @inheritDoc
*/
protected function getMacroName(): string {
return 'details';
}

/**
* @inheritDoc
*/
protected function getWikiTextTemplateName(): string {
return 'Details';
}
}
28 changes: 28 additions & 0 deletions src/Converter/Processor/DetailsSummaryMacro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace HalloWelt\MigrateConfluence\Converter\Processor;

/**
* <ac:structured-macro ac:name="detailssummary" ac:schema-version="3" ac:macro-id="...">
* <ac:parameter ac:name="firstcolumn">...</ac:parameter>
* <ac:parameter ac:name="headings">...</ac:parameter>
* <ac:parameter ac:name="sortBy">Title</ac:parameter>
* <ac:parameter ac:name="cql">label = "..." and parent = currentContent ( )</ac:parameter>
* </ac:structured-macro>
*/
class DetailsSummaryMacro extends ConvertMacroToTemplateBase {

/**
* @inheritDoc
*/
protected function getMacroName(): string {
return 'detailssummary';
}

/**
* @inheritDoc
*/
protected function getWikiTextTemplateName(): string {
return 'DetailsSummary';
}
}
37 changes: 37 additions & 0 deletions tests/phpunit/Converter/Processor/DetailsMacroTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace HalloWelt\MigrateConfluence\Tests\Converter\Processor;

use DOMDocument;
use HalloWelt\MigrateConfluence\Converter\Processor\DetailsMacro;
use PHPUnit\Framework\TestCase;

class DetailsMacroTest extends TestCase {

/**
* @var string
*/
private $dir = '';

/**
* @covers HalloWelt\MigrateConfluence\Converter\Processor\DetailsMacro::process
* @return void
*/
public function testProcess() {
$this->dir = dirname( dirname( __DIR__ ) ) . '/data';

$input = file_get_contents( "$this->dir/details-macro-input.xml" );

$dom = new DOMDocument();
$dom->loadXML( $input );

$processor = new DetailsMacro();
$processor->process( $dom );

$actualOutput = $dom->saveXML( $dom->documentElement );
$expectedOutput = file_get_contents( "$this->dir/details-macro-output.xml" );

$this->assertEquals( $expectedOutput, $actualOutput );
}

}
37 changes: 37 additions & 0 deletions tests/phpunit/Converter/Processor/DetailsSummaryMacroTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace HalloWelt\MigrateConfluence\Tests\Converter\Processor;

use DOMDocument;
use HalloWelt\MigrateConfluence\Converter\Processor\DetailsSummaryMacro;
use PHPUnit\Framework\TestCase;

class DetailsSummaryMacroTest extends TestCase {

/**
* @var string
*/
private $dir = '';

/**
* @covers HalloWelt\MigrateConfluence\Converter\Processor\DetailsSummaryMacro::process
* @return void
*/
public function testProcess() {
$this->dir = dirname( dirname( __DIR__ ) ) . '/data';

$input = file_get_contents( "$this->dir/detailssummary-macro-input.xml" );

$dom = new DOMDocument();
$dom->loadXML( $input );

$processor = new DetailsSummaryMacro();
$processor->process( $dom );

$actualOutput = $dom->saveXML( $dom->documentElement );
$expectedOutput = file_get_contents( "$this->dir/detailssummary-macro-output.xml" );

$this->assertEquals( $expectedOutput, $actualOutput );
}

}
8 changes: 8 additions & 0 deletions tests/phpunit/data/details-macro-input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<xml xmlns:ac="sample_namespace">
<ac:structured-macro ac:name="details">
<ac:parameter ac:name="id">Lorem</ac:parameter>
<ac:rich-text-body>
<h3>Ipsum dolor</h3>
</ac:rich-text-body>
</ac:structured-macro>
</xml>
9 changes: 9 additions & 0 deletions tests/phpunit/data/details-macro-output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<xml xmlns:ac="sample_namespace">
{{Details###BREAK###
|id = Lorem###BREAK###
|body = ###BREAK###

<h3>Ipsum dolor</h3>
}}###BREAK###

</xml>
8 changes: 8 additions & 0 deletions tests/phpunit/data/detailssummary-macro-input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<xml xmlns:ac="sample_namespace">
<ac:structured-macro ac:name="detailssummary">
<ac:parameter ac:name="firstcolumn">Col 1</ac:parameter>
<ac:parameter ac:name="headings">Heading 1, Heading 2, Heading 3, Heading 4</ac:parameter>
<ac:parameter ac:name="sortBy">Title</ac:parameter>
<ac:parameter ac:name="cql">label = "Label 1" and parent = currentContent ( )</ac:parameter>
</ac:structured-macro>
</xml>
9 changes: 9 additions & 0 deletions tests/phpunit/data/detailssummary-macro-output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<xml xmlns:ac="sample_namespace">
{{DetailsSummary###BREAK###
|firstcolumn = Col 1###BREAK###
|headings = Heading 1, Heading 2, Heading 3, Heading 4###BREAK###
|sortBy = Title###BREAK###
|cql = label = "Label 1" and parent = currentContent ( )###BREAK###
}}###BREAK###

</xml>

0 comments on commit b123ddc

Please sign in to comment.