mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 00:54:41 +00:00
mvc: Phalcon framework dependency (https://github.com/opnsense/core/issues/6389)
fix regression in c2ea9aa3039eb4d24ba53a7aa2190642150f20eb and amend unit tests.
This commit is contained in:
parent
098a89b965
commit
75bb361e24
@ -575,7 +575,7 @@ abstract class BaseModel
|
||||
// If for some reason the developer chooses to ignore the errors, let's at least log there something
|
||||
// wrong in this model.
|
||||
$messages = $this->performValidation($validateFullModel);
|
||||
if ($messages->count() > 0) {
|
||||
if (count($messages) > 0) {
|
||||
$exception_msg = "";
|
||||
foreach ($messages as $msg) {
|
||||
$exception_msg_part = "[" . get_class($this) . ":" . $msg->getField() . "] ";
|
||||
|
||||
@ -36,13 +36,25 @@ class Message
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
|
||||
/**
|
||||
* OPNsense\Base\Messages\Message constructor
|
||||
*/
|
||||
public function __construct($message, $field = "")
|
||||
public function __construct($message, $field = "", $type = "")
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->field = $field;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,4 +98,12 @@ class Message
|
||||
$this->message = $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class ComparedToFieldConstraintTest extends \PHPUnit\Framework\TestCase
|
||||
$validate = $this->make_validator(2, 3, 'test', 'lt');
|
||||
$ret = $validate->validate($validator, '');
|
||||
$messages = $validator->getMessages();
|
||||
$this->assertEquals(0, $messages->count());
|
||||
$this->assertEquals(0, count($messages));
|
||||
$this->assertEquals(true, $ret);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ class ComparedToFieldConstraintTest extends \PHPUnit\Framework\TestCase
|
||||
$validate = $this->make_validator(3, 3, 'test', 'lt');
|
||||
$ret = $validate->validate($validator, '');
|
||||
$messages = $validator->getMessages();
|
||||
$this->assertEquals(1, $messages->count());
|
||||
$this->assertEquals(1, count($messages));
|
||||
$this->assertEquals(true, $ret);
|
||||
}
|
||||
// greater then
|
||||
@ -64,7 +64,7 @@ class ComparedToFieldConstraintTest extends \PHPUnit\Framework\TestCase
|
||||
$validate = $this->make_validator(5, 3, 'test', 'gt');
|
||||
$ret = $validate->validate($validator, '');
|
||||
$messages = $validator->getMessages();
|
||||
$this->assertEquals(0, $messages->count());
|
||||
$this->assertEquals(0, count($messages));
|
||||
$this->assertEquals(true, $ret);
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ class ComparedToFieldConstraintTest extends \PHPUnit\Framework\TestCase
|
||||
$validate = $this->make_validator(2, 3, 'test', 'gt');
|
||||
$ret = $validate->validate($validator, '');
|
||||
$messages = $validator->getMessages();
|
||||
$this->assertEquals(1, $messages->count());
|
||||
$this->assertEquals(1, count($messages));
|
||||
$this->assertEquals(true, $ret);
|
||||
}
|
||||
|
||||
|
||||
@ -106,12 +106,12 @@ class UniqueConstraintTest extends \PHPUnit\Framework\Testcase
|
||||
$container->addNode(['unique_test' => 'value2']);
|
||||
|
||||
$msgs = $container->validate();
|
||||
$this->assertEquals(0, $msgs->count());
|
||||
$this->assertEquals(0, count($msgs));
|
||||
|
||||
$container->addNode(['unique_test' => 'value1']);
|
||||
|
||||
$msgs = $container->validate();
|
||||
$this->assertEquals(1, $msgs->count());
|
||||
$this->assertEquals(1, count($msgs));
|
||||
}
|
||||
|
||||
public function testMultipleNonEqualAndEqualValues()
|
||||
@ -121,12 +121,12 @@ class UniqueConstraintTest extends \PHPUnit\Framework\Testcase
|
||||
$container->addNode(['unique_test' => 'value1', 'unique_test2' => 'value3']);
|
||||
|
||||
$msgs = $container->validate();
|
||||
$this->assertEquals(0, $msgs->count());
|
||||
$this->assertEquals(0, count($msgs));
|
||||
|
||||
$container->addNode(['unique_test' => 'value1', 'unique_test2' => 'value2']);
|
||||
|
||||
$msgs = $container->validate();
|
||||
$this->assertEquals(1, $msgs->count());
|
||||
$this->assertEquals(1, count($msgs));
|
||||
}
|
||||
|
||||
public function testEmptyValuesNotRequiredAndRequired()
|
||||
@ -137,13 +137,13 @@ class UniqueConstraintTest extends \PHPUnit\Framework\Testcase
|
||||
|
||||
$msgs = $container->validate();
|
||||
|
||||
$this->assertEquals(0, $msgs->count());
|
||||
$this->assertEquals(0, count($msgs));
|
||||
|
||||
$container->setRequired(true);
|
||||
|
||||
$msgs = $container->validate();
|
||||
|
||||
$this->assertEquals(1, $msgs->count());
|
||||
$this->assertEquals(1, count($msgs));
|
||||
}
|
||||
|
||||
public function testMultipleEmptyValuesNotRequiredAndRequired()
|
||||
@ -154,13 +154,13 @@ class UniqueConstraintTest extends \PHPUnit\Framework\Testcase
|
||||
|
||||
$msgs = $container->validate();
|
||||
|
||||
$this->assertEquals(0, $msgs->count());
|
||||
$this->assertEquals(0, count($msgs));
|
||||
|
||||
$container->setRequired(true);
|
||||
|
||||
$msgs = $container->validate();
|
||||
|
||||
$this->assertEquals(1, $msgs->count());
|
||||
$this->assertEquals(1, count($msgs));
|
||||
}
|
||||
|
||||
public function testFirstValueEmptyPassAll()
|
||||
@ -171,12 +171,12 @@ class UniqueConstraintTest extends \PHPUnit\Framework\Testcase
|
||||
|
||||
$msgs = $container->validate();
|
||||
|
||||
$this->assertEquals(0, $msgs->count());
|
||||
$this->assertEquals(0, count($msgs));
|
||||
|
||||
$container->setRequired(true);
|
||||
|
||||
$msgs = $container->validate();
|
||||
|
||||
$this->assertEquals(1, $msgs->count());
|
||||
$this->assertEquals(1, count($msgs));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user