Fix mailtemplate tests

This commit is contained in:
Ivan Diaz 2018-11-16 17:24:43 -03:00
parent a187e06ce3
commit 85eced56ff
2 changed files with 19 additions and 12 deletions

View File

@ -51,7 +51,7 @@ class HashingTest extends TestCase {
foreach($nonPrimes as $number) $this->assertFalse(Hashing::isPrime($number)); foreach($nonPrimes as $number) $this->assertFalse(Hashing::isPrime($number));
} }
public function testShouldGenerateRandsomPrime() { public function testShouldGenerateRandomPrime() {
$TEST_TIMES = 10; $TEST_TIMES = 10;
for ($i = 0; $i < $TEST_TIMES; $i++) { for ($i = 0; $i < $TEST_TIMES; $i++) {
@ -63,7 +63,6 @@ class HashingTest extends TestCase {
$this->assertTrue($min < $number1 && $number1 < $max); $this->assertTrue($min < $number1 && $number1 < $max);
$this->assertTrue($min < $number2 && $number2 < $max); $this->assertTrue($min < $number2 && $number2 < $max);
$this->assertNotEquals($number1, $number2);
$this->assertTrue(Hashing::isPrime($number1)); $this->assertTrue(Hashing::isPrime($number1));
$this->assertTrue(Hashing::isPrime($number2)); $this->assertTrue(Hashing::isPrime($number2));
} }

View File

@ -19,11 +19,11 @@ class MailTemplateTest extends TestCase {
} }
public function testGetTemplateShouldReturnSpecifiedTemplate() { public function testGetTemplateShouldReturnSpecifiedTemplate() {
$mailTemplate = MailTemplate::getTemplate(MailTemplate::USER_SIGNUP); $mailTemplate = MailTemplate::getMailTemplate(MailTemplate::USER_SIGNUP);
$this->assertEquals('TEST_TYPE', $mailTemplate->type); $this->assertEquals('USER_SIGNUP', $mailTemplate->type);
$this->assertTrue(Redbean::get('findOne')->hasBeenCalledWithArgs('mailtemplate', 'type = :type AND language = :language', array( $this->assertTrue(Redbean::get('findOne')->hasBeenCalledWithArgs('mailtemplate', 'template = :template AND language = :language', array(
':type' => 'USER_SIGNUP', ':template' => 'USER_SIGNUP',
':language' => 'MOCK_SETTING_VALUE' ':language' => 'MOCK_SETTING_VALUE'
))); )));
} }
@ -31,23 +31,31 @@ class MailTemplateTest extends TestCase {
public function testCompilation() { public function testCompilation() {
$mailTemplate = new MailTemplate(); $mailTemplate = new MailTemplate();
$mailTemplate->setProperties([ $mailTemplate->setProperties([
'template' => 'USER_SIGNUP',
'subject' => 'Welcoming to {{to}}', 'subject' => 'Welcoming to {{to}}',
'body' => 'Welcome, {{userName}} to our team' 'text1' => 'Welcome, {{userName}} to our team'
]); ]);
$result = $mailTemplate->compile([ $resultSubject = $mailTemplate->getSubject([
'to' => 'cersei@opensupports.com', 'to' => 'cersei@opensupports.com',
'userName' => 'Cersei Lannister', 'userName' => 'Cersei Lannister',
]); ]);
$this->assertEquals($result['subject'], 'Welcoming to cersei@opensupports.com'); $resultBody = $mailTemplate->getBody([
$this->assertEquals($result['body'], 'Welcome, Cersei Lannister to our team'); 'to' => 'cersei@opensupports.com',
'userName' => 'Cersei Lannister',
]);
$this->assertEquals($resultSubject, 'Welcoming to cersei@opensupports.com');
$this->assertContains('Welcome, Cersei Lannister to our team', $resultBody);
} }
private function getMockTemplateBean() { private function getMockTemplateBean() {
$mailTemplateBean = new BeanMock(); $mailTemplateBean = new BeanMock();
$mailTemplateBean->type = 'TEST_TYPE'; $mailTemplateBean->type = 'USER_SIGNUP';
$mailTemplateBean->body = 'Some body'; $mailTemplateBean->text1 = 'Text1';
$mailTemplateBean->text2 = 'Text1';
$mailTemplateBean->text3 = 'Text1';
$mailTemplateBean->subject = 'Some subject'; $mailTemplateBean->subject = 'Some subject';
$mailTemplateBean->language = 'en'; $mailTemplateBean->language = 'en';