mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '4.7' into 4
This commit is contained in:
commit
7a04090bdf
@ -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
|
||||
*/
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user