Skip to content

Commit

Permalink
Bug fix replace operation with null values (#333)
Browse files Browse the repository at this point in the history
* Bugfix replace operation with null values

* Added change log
  • Loading branch information
Nyholm authored Sep 6, 2019
1 parent ecf4909 commit 584b8b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Catalogue/Operation/ReplaceOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ protected function processDomain($domain)

foreach ($this->source->all($domain) as $id => $message) {
$messageDomain = $this->source->defines($id, $intlDomain) ? $intlDomain : $domain;
$this->messages[$domain]['all'][$id] = $message;
$this->result->add([$id => $message], $messageDomain);

if (!$this->target->has($id, $domain)) {
// No merge required
$translation = $message;
$this->messages[$domain]['new'][$id] = $message;
$resultMeta = $this->getMetadata($this->source, $messageDomain, $id);
} else {
// Merge required
$translation = $message ?? $this->target->get($id, $domain);
$resultMeta = null;
$sourceMeta = $this->getMetadata($this->source, $messageDomain, $id);
$targetMeta = $this->getMetadata($this->target, $this->target->defines($id, $intlDomain) ? $intlDomain : $domain, $id);
Expand All @@ -68,6 +68,9 @@ protected function processDomain($domain)
}
}

$this->messages[$domain]['all'][$id] = $translation;
$this->result->add([$id => $translation], $messageDomain);

if (!empty($resultMeta)) {
$this->result->setMetadata($id, $resultMeta, $messageDomain);
}
Expand Down
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

## 0.9.1

### Fixed

- Fixed issue with translations falsely marked as obsolete

## 0.9.0

### Added
Expand Down
13 changes: 13 additions & 0 deletions Tests/Unit/Catalogue/Operation/ReplaceOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public function testGetResultFromSingleDomain()
);
}

public function testGetResultWithNullValues()
{
$this->assertEquals(
new MessageCatalogue('en', [
'messages' => ['a' => 'old_a', 'b' => 'old_b', 'c' => null],
]),
$this->createOperation(
new MessageCatalogue('en', ['messages' => ['a' => null, 'c' => null]]),
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']])
)->getResult()
);
}

public function testGetResultWithMetadata()
{
$leftCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'b' => 'new_b']]);
Expand Down

0 comments on commit 584b8b9

Please sign in to comment.