-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlogPostTest.php
106 lines (94 loc) · 2.34 KB
/
BlogPostTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
App::uses('TestDataValidation', 'DataValidationTesting.Lib');
/**
* BlogPost Test Case
*
* @coversDefaultClass BlogPost
* @property BlogPost $_model
*/
class BlogPostTest extends CakeTestCase {
/**
* The data validation testing class.
*
* @var null|TestDataValidation
*/
protected $_testDataValidation = null;
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'app.blogPost',
);
/**
* Set up model and data validation testing object
*
* @return void
*/
public function setUp() {
$this->_model = ClassRegistry::init('BlogPost');
parent::setUp();
$this->_testDataValidation = new TestDataValidation($this, $this->_model);
}
/**
* Tests the data validation for the mandatory fields (if any)
*
* @param array $expected The array of expected validation errors.
* @return void
* @coversNothing
*/
public function testRequiredFieldsDataValidation($expected = array()) {
parent::testRequiredFieldsDataValidation($expected);
}
/**
* Tests the data validation for the 'title' field
*
* @coversNothing
* @return void
*/
public function testTitleDataValidation() {
$minLength = 4;
$maxLength = 255;
// Test the 'notempty' rule
$this->_testDataValidation->testNotEmptyDataValidation(
'title', 'Title must not be empty.', $minLength
);
// Test the 'minlength' rule
$this->_testDataValidation->testMinLengthDataValidation(
'title', 'Title must be at least 4 characters long.', $minLength
);
// Test the 'maxlength' rule
$this->_testDataValidation->testMaxLengthDataValidation(
'title', 'Title must be no longer than 255 characters.', $maxLength
);
}
/**
* Test the data validation for the 'is_active' field
*
* @coversNothing
* @return void
*/
public function testIsTrueDataValidation() {
// Test the 'boolean' rule
$this->_testDataValidation->testBooleanDataValidation(
'is_active', 'Is Active must be a boolean.'
);
}
/**
* Test the data validation for the 'user_id' field
*
* The validForeignKey data validation rule is provided
* by the ValidForeignKey behavior plugin.
*
* @coversNothing
* @return void
*/
public function testItemIdDataValidation() {
// Test the 'validForeignKey' rule
$valid = array(1, 2, 3);
$this->_testDataValidation->testValidForeignKeyDataValidation(
'user_id', 'User ID must exist.', $valid
);
}
}