Skip to content

Commit

Permalink
Fix default overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
rvogel committed Dec 3, 2021
1 parent 3f63410 commit 67d0ddb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,14 @@ public function addRevision( $pagetitle, $wikitext, $timestamp = '', $username =
$this->pages[$pagetitle] = [];
}
$modelAndFormat = $this->getDefaultModelAndFormat( $pagetitle );
$defaults = [
'timestamp' => '',
'username' => '',
'model' => $modelAndFormat['model'],
'format' => $modelAndFormat['format']
];

$this->pages[$pagetitle][] = array_merge( [
$this->pages[$pagetitle][] = [
'text' => $wikitext,
'timestamp' => $timestamp,
'username' => $username,
'model' => $model,
'format' => $format
], $defaults );
'model' => empty( $model ) ? $modelAndFormat['model'] : $model,
'format' => empty( $format ) ? $modelAndFormat['format'] : $format
];

return $this;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public function provideTestBuildAndSaveData() {
[ "Coffee & Tea", "raffiné" ]
],
__DIR__ . '/data/expected2.xml'
],
'explicit-model-and-format' => [
[
[ "Some.form", "...", '', '', 'form', 'text/x-form' ]
],
__DIR__ . '/data/expected3.xml'
]
];
}
Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/data/expected3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<mediawiki>
<page>
<title>Some.form</title>
<revision>
<model>form</model>
<format>text/x-form</format>
<text>...</text>
</revision>
</page>
</mediawiki>

0 comments on commit 67d0ddb

Please sign in to comment.