Skip to content

Commit 1b43e06

Browse files
committed
Added instance settings for messages and templates
1 parent 7d4ab40 commit 1b43e06

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,21 @@ public function getTemplate(string $id)
4747
return array_key_exists($id, $this->templates) ? $this->templates[$id] : null;
4848
}
4949

50+
public function setIMessages(array $messages)
51+
{
52+
static::getInstance()->setMessages($messages);
53+
}
54+
5055
public function setMessages(array $messages)
5156
{
5257
$this->messages = array_merge($this->messages, $messages);
5358
}
5459

60+
public function setITemplates(array $templates)
61+
{
62+
static::getInstance()->setTemplates($templates);
63+
}
64+
5565
public function setTemplates(array $templates)
5666
{
5767
$this->templates = array_merge($this->templates, $templates);

tests/unit/PHPFormConfigTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ public function testGetTemplate()
4040
$this->assertNull($instance->getTemplate("Inexistent"));
4141
}
4242

43+
public function testSetIMessages()
44+
{
45+
PHPFormConfig::setIMessages(array(
46+
"Invalid 2" => "Invalid 2",
47+
"Invalid 3" => "Invalid 3",
48+
));
49+
50+
$this->assertEquals("This field is required.", PHPFormConfig::getIMessage("REQUIRED"));
51+
$this->assertEquals("Invalid 2", PHPFormConfig::getIMessage("Invalid 2"));
52+
$this->assertEquals("Invalid 3", PHPFormConfig::getIMessage("Invalid 3"));
53+
}
54+
4355
public function testSetMessages()
4456
{
4557
$instance = PHPFormConfig::getInstance();
@@ -53,6 +65,18 @@ public function testSetMessages()
5365
$this->assertEquals("Invalid 3", $instance->getMessage("Invalid 3"));
5466
}
5567

68+
public function testSetITemplates()
69+
{
70+
PHPFormConfig::setITemplates(array(
71+
"Invalid 2" => "Invalid 2",
72+
"Invalid 3" => "Invalid 3",
73+
));
74+
75+
$this->assertEquals('<span class="required">*</span>', PHPFormConfig::getITemplate("LABEL_REQUIRED"));
76+
$this->assertEquals("Invalid 2", PHPFormConfig::getITemplate("Invalid 2"));
77+
$this->assertEquals("Invalid 3", PHPFormConfig::getITemplate("Invalid 3"));
78+
}
79+
5680
public function testSetTemplates()
5781
{
5882
$instance = PHPFormConfig::getInstance();

0 commit comments

Comments
 (0)