Skip to content

Commit

Permalink
Fix: Allow Email to re-render when data changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NikxDa committed Mar 1, 2021
1 parent 2c54a3f commit c43789c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Control/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ public function getData()
public function setData($data)
{
$this->data = $data;
$this->setBody(null);

return $this;
}
Expand All @@ -589,6 +590,8 @@ public function addData($name, $value = null)
$this->data->$name = $value;
}

$this->setBody(null);

return $this;
}

Expand All @@ -606,6 +609,8 @@ public function removeData($name)
$this->data->$name = null;
}

$this->setBody(null);

return $this;
}

Expand Down
33 changes: 33 additions & 0 deletions tests/php/Control/Email/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,39 @@ public function testRenderAgain()
$this->assertCount(1, $email->getSwiftMessage()->getChildren());
}

public function testRerender()
{
$email = new Email();
$email->setData([
'EmailContent' => 'my content',
]);
$email->render();
$this->assertContains('my content', $email->getBody());
$children = $email->getSwiftMessage()->getChildren();
$this->assertCount(1, $children);
$plainPart = reset($children);
$this->assertEquals('my content', $plainPart->getBody());

// Ensure setting data causes a rerender
$email->setData([
'EmailContent' => 'your content'
]);
$email->render();
$this->assertContains('your content', $email->getBody());

// Ensure removing data causes a rerender
$email->removeData('EmailContent');
$email->render();
$this->assertNotContains('your content', $email->getBody());

// Ensure adding data causes a rerender
$email->addData([
'EmailContent' => 'their content'
]);
$email->render();
$this->assertContains('their content', $email->getBody());
}

public function testRenderPlainOnly()
{
$email = new Email();
Expand Down

0 comments on commit c43789c

Please sign in to comment.