-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model validation now correctly adds code to message
- Loading branch information
Showing
6 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Models\Validation; | ||
|
||
use Phalcon\Mvc\Model; | ||
use Phalcon\Mvc\Model\Resultset\Simple; | ||
use Phalcon\Test\Models\RobotsParts; | ||
use Phalcon\Validation; | ||
use Phalcon\Validation\Validator\PresenceOf; | ||
|
||
/** | ||
* \Phalcon\Test\Models\Validation\Robots | ||
* | ||
* @method static int countByType(string $type) | ||
* @method static Simple findByType(string $type) | ||
* @method static Robots findFirstById(string | int $id) | ||
* | ||
* @copyright 2011-2017 Phalcon Team | ||
* @link https://phalconphp.com | ||
* @author Andres Gutierrez <[email protected]> | ||
* @author Nikolaos Dimopoulos <[email protected]> | ||
* @package Phalcon\Test\Models\Validation | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
* | ||
* If you did not receive a copy of the license and are unable to obtain it | ||
* through the world-wide-web, please send an email to [email protected] | ||
* so that we can send you a copy immediately. | ||
*/ | ||
class Robots extends Model | ||
{ | ||
public function initialize() | ||
{ | ||
$this->hasMany( | ||
'id', | ||
RobotsParts::class, | ||
'robots_id', | ||
[ | ||
'foreignKey' => true, | ||
'reusable' => false, | ||
'alias' => 'parts', | ||
] | ||
); | ||
} | ||
|
||
public function validation() | ||
{ | ||
$validation = new Validation(); | ||
$validation->add( | ||
'name', | ||
new Validation\Validator\StringLength( | ||
[ | ||
'min' => '7', | ||
'max' => '50', | ||
'code' => 20, | ||
] | ||
) | ||
); | ||
|
||
return $this->validate($validation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Models; | ||
namespace Phalcon\Test\Models\Validation; | ||
|
||
use Phalcon\Mvc\Model; | ||
use Phalcon\Validation; | ||
|
@@ -14,7 +14,7 @@ | |
use Phalcon\Validation\Validator\StringLength; | ||
|
||
/** | ||
* \Phalcon\Test\Models\Subscriptores | ||
* \Phalcon\Test\Models\Validation\Subscriptores | ||
* | ||
* @property int id | ||
* @property string email | ||
|
@@ -25,7 +25,7 @@ | |
* @link http://www.phalconphp.com | ||
* @author Andres Gutierrez <[email protected]> | ||
* @author Serghei Iakovlev <[email protected]> | ||
* @package Phalcon\Test\Models | ||
* @package Phalcon\Test\Models\Validation | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Phalcon\Test\Unit\Mvc; | ||
|
||
use Helper\ModelTrait; | ||
use Phalcon\Mvc\Model\Message; | ||
use Phalcon\Test\Models\Users; | ||
use Phalcon\Cache\Backend\Apc; | ||
use Phalcon\Test\Models\Robots; | ||
|
@@ -19,6 +20,7 @@ | |
use Phalcon\Test\Models\BodyParts\Body; | ||
use Phalcon\Test\Models\News\Subscribers; | ||
use Phalcon\Test\Models\AlbumORama\Albums; | ||
use Phalcon\Test\Models\Validation; | ||
|
||
/** | ||
* \Phalcon\Test\Unit\Mvc\ModelTest | ||
|
@@ -613,4 +615,28 @@ function () { | |
} | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Tests setting code in message from validation messages | ||
* | ||
* @issue 12645 | ||
* @author Wojciech Ślawski <[email protected]> | ||
* @since 2017-03-03 | ||
*/ | ||
public function testIssue12645() | ||
{ | ||
$this->specify( | ||
"Issue #12645 is not fixed", | ||
function () { | ||
$robots = new Validation\Robots(); | ||
$robots->name = "asd"; | ||
expect($robots->create())->false(); | ||
/** @var Message $message */ | ||
$message = $robots->getMessages()[0]; | ||
expect($message)->isInstanceOf(Message::class); | ||
expect($message->getCode())->equals(20); | ||
} | ||
); | ||
} | ||
} |