Merge branch '4.7' into 4

This commit is contained in:
Maxime Rainville 2021-03-15 14:27:47 +13:00
commit 7a04090bdf
2 changed files with 48 additions and 0 deletions

View File

@ -570,6 +570,7 @@ class Email extends ViewableData
public function setData($data)
{
$this->data = $data;
$this->invalidateBody();
return $this;
}
@ -589,6 +590,8 @@ class Email extends ViewableData
$this->data->$name = $value;
}
$this->invalidateBody();
return $this;
}
@ -606,6 +609,8 @@ class Email extends ViewableData
$this->data->$name = null;
}
$this->invalidateBody();
return $this;
}
@ -635,6 +640,16 @@ class Email extends ViewableData
return $this;
}
/**
* @return $this
*/
public function invalidateBody()
{
$this->setBody(null);
return $this;
}
/**
* @return string The base URL for the email
*/

View File

@ -559,6 +559,39 @@ class EmailTest extends SapphireTest
$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();