parent
2b3a0caaee
commit
b32176682f
|
|
@ -4,7 +4,6 @@ use Model;
|
|||
|
||||
class Post extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string The database table used by the model.
|
||||
*/
|
||||
|
|
@ -122,3 +121,13 @@ class RevisionablePost extends Post
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
class ValidationPost extends Post
|
||||
{
|
||||
use \October\Rain\Database\Traits\Validation;
|
||||
|
||||
public $rules = [
|
||||
'title' => 'required|min:3|max:255',
|
||||
'slug' => ['required', 'regex:/^[a-z0-9\/\:_\-\*\[\]\+\?\|]*$/i', 'unique:database_tester_posts'],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,4 +31,4 @@ class ModelTest extends PluginTestCase
|
|||
{
|
||||
Post::create(['title' => 'Hi!', 'slug' => 'authenticity']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Database\Tester\Models\ValidationPost;
|
||||
|
||||
class ValidationModelTest extends PluginTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
include_once base_path().'/tests/fixtures/plugins/database/tester/models/Post.php';
|
||||
|
||||
$this->runPluginRefreshCommand('Database.Tester');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException October\Rain\Database\ModelException
|
||||
*/
|
||||
public function test_slug_has_to_be_unique()
|
||||
{
|
||||
$post = ValidationPost::create([
|
||||
'title' => 'This is a new post',
|
||||
'slug' => 'post-1',
|
||||
'description' => 'Testing...'
|
||||
]);
|
||||
|
||||
$this->assertNotFalse($post);
|
||||
|
||||
$post2 = ValidationPost::create([
|
||||
'title' => 'this is another post with the same slug',
|
||||
'slug' => 'post-1',
|
||||
'description' => 'testing....'
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue