-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #104 Co-authored-by: rvogel <[email protected]>
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<noinclude>Links to JIRA can be handled with "Interwiki-Links" | ||
</noinclude><includeonly>[[jira:{{{key}}}]]</includeonly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace HalloWelt\MigrateConfluence\Converter\Processor; | ||
|
||
use HalloWelt\MediaWiki\Lib\WikiText\Template; | ||
|
||
class StructuredMacroJira extends StructuredMacroProcessorBase { | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getMacroName(): string { | ||
return 'jira'; | ||
} | ||
|
||
/** | ||
* @param \DOMElement $node | ||
* @return void | ||
*/ | ||
protected function doProcessMacro( $node ): void { | ||
$params = $this->readParams( $node ); | ||
$wikitextTemplate = new Template( $this->getWikiTextTemplateName(), $params ); | ||
$wikitextTemplate->setRenderFormatted( false ); | ||
$node->parentNode->replaceChild( | ||
$node->ownerDocument->createTextNode( | ||
(string)$wikitextTemplate | ||
), | ||
$node | ||
); | ||
} | ||
|
||
protected function getWikiTextTemplateName(): string { | ||
return 'Jira'; | ||
} | ||
|
||
/** | ||
* @param \DOMElement $node | ||
* @return array | ||
*/ | ||
protected function readParams( \DOMElement $node ): array { | ||
$params = []; | ||
foreach ( $node->childNodes as $childNode ) { | ||
if ( $childNode->nodeName === 'ac:parameter' ) { | ||
$paramName = $childNode->getAttribute( 'ac:name' ); | ||
$paramValue = $childNode->nodeValue; | ||
$params[$paramName] = $paramValue; | ||
} | ||
} | ||
return $params; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
tests/phpunit/Converter/Processor/StructuredMacroJiraTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace HalloWelt\MigrateConfluence\Tests\Converter\Processor; | ||
|
||
use HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroJira; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class StructuredMacroJiraTest extends TestCase { | ||
|
||
/** | ||
* @covers \HalloWelt\MigrateConfluence\Converter\Processor\StructuredMacroJira::process | ||
* @return void | ||
*/ | ||
public function testProcess() { | ||
$jiraMacroProcessor = new StructuredMacroJira(); | ||
$dom = new \DOMDocument(); | ||
$dom->load( | ||
__DIR__ . '/../../data/jira-input.xml' | ||
); | ||
$expectedDOM = new \DOMDocument(); | ||
$expectedDOM->load( | ||
__DIR__ . '/../../data/jira-output.xml' | ||
); | ||
|
||
$jiraMacroProcessor->process( $dom ); | ||
|
||
$this->assertEqualXMLStructure( | ||
$expectedDOM->documentElement, | ||
$dom->documentElement | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<xml xmlns:ac="sample_namespace" xmlns:ri="sample_second_namespace"> | ||
<ac:structured-macro ac:name="jira" ac:schema-version="1" ac:macro-id="..."> | ||
<ac:parameter ac:name="server">My JIRA</ac:parameter> | ||
<ac:parameter ac:name="serverId">1a43h4459d325e4b</ac:parameter> | ||
<ac:parameter ac:name="key">ABC-3423</ac:parameter> | ||
</ac:structured-macro> | ||
</xml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<xml xmlns:ac="sample_namespace" xmlns:ri="sample_second_namespace"> | ||
{{Jira|server = My JIRA|serverId = 1a43h4459d325e4b|key = ABC-3423}} | ||
</xml> |