Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
CommentTest.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  */
11 class CommentTest extends CDbTestCase
12 {
13 
14  public static function setUpBeforeClass()
15  {
16  Comment::model()->deleteAll();
17  parent::setUpBeforeClass();
18  }
19 
20  /**
21  * @dataProvider provider
22  */
23  public function testCreate($attributes)
24  {
25  $comment = new Comment();
26  $comment->attributes = $attributes;
27  $this->assertTrue($comment->save());
28 
29  return $comment;
30  }
31 
32  /**
33  * @depends testCreate
34  * @dataProvider provider
35  */
36  public function testFind($attributes)
37  {
38  $this->assertCount(1, Comment::model()->findAllByAttributes($attributes));
39  }
40 
41 
42  /**
43  * @depends testFind
44  * @dataProvider provider
45  */
46  public function testHash($attributes)
47  {
48  $this->assertNotEmpty(Comment::model()->findByAttributes($attributes)->hash());
49  }
50 
51  /**
52  * @depends testHash
53  * @dataProvider provider
54  */
55  public function testDelete($attributes)
56  {
57  $this->assertEquals(1, Comment::model()->deleteAllByAttributes($attributes));
58 
59  }
60 
61  public function testValidateEmail()
62  {
63  $comment = new Comment();
64  $comment->email = 'not valid';
65  $comment->moderator_email = 'not valid';
66  $comment->validate();
67  $this->assertNotNull($comment->getError('email'));
68  $this->assertNotNull($comment->getError('moderator_email'));
69 
70  $comment->email = 'valid@email.com';
71  $comment->moderator_email = 'valid@email.com';
72  $comment->validate();
73  $this->assertNull($comment->getError('email'));
74  $this->assertNull($comment->getError('moderator_email'));
75  }
76 
77  public function testCreateAnonymousScope()
78  {
79  $comment = new Comment('createAnonymous');
80  $comment->attributes = array(
81  'content_id' => 1,
82  'user_id' => null,
83  'moderator_email' => 'email@email.com',
84  'email' => 'email@email.com',
85  'subject' => 'Subject',
86  'description' => 'Description',
87  'notify_moderator' => 0,
88  'notify_user' => 0,
89  'status' => Comment::NOT_APPROVED,
90  'language' => 'en'
91  );
92  $comment->validate();
93  $this->assertTrue($comment->hasErrors('firstname'));
94  $this->assertTrue($comment->hasErrors('lastname'));
95 
96  $comment->firstname = 'Ivan';
97  $comment->lastname = 'Pupkin';
98  $comment->validate();
99  $this->assertFalse($comment->hasErrors('firstname'));
100  $this->assertFalse($comment->hasErrors('lastname'));
101 
102  }
103 
104  public function testCreateScope()
105  {
106  $comment = new Comment('create');
107  $comment->attributes = array(
108  'content_id' => 1,
109  'user_id' => null,
110  'moderator_email' => 'email@email.com',
111  'email' => 'email@email.com',
112  'subject' => 'Subject',
113  'description' => 'Description',
114  'notify_moderator' => 0,
115  'notify_user' => 0,
116  'status' => Comment::NOT_APPROVED,
117  'language' => 'en'
118  );
119  $this->assertTrue($comment->validate());
120  }
121 
122  public function provider()
123  {
124  return array(
125  array(array(
126  'parent_id' => null,
127  'content_id' => '1',
128  'user_id' => null,
129  'moderator_email' => 'email@email.com',
130  'firstname' => 'First name',
131  'lastname' => 'Last name',
132  'email' => 'email@email.com',
133  'subject' => 'Subject',
134  'description' => 'Description',
135  'notify_moderator' => 0,
136  'notify_user' => 0,
137  'status' => Comment::NOT_APPROVED,
138  'language' => 'en'
139  )),
140  array(array(
141  'parent_id' => null,
142  'content_id' => '1',
143  'user_id' => null,
144  'moderator_email' => 'email@email.com',
145  'firstname' => 'First name',
146  'lastname' => 'Last name',
147  'email' => 'email@email.com',
148  'subject' => 'Subject',
149  'description' => 'Description',
150  'notify_moderator' => 1,
151  'notify_user' => 1,
152  'status' => Comment::NOT_APPROVED,
153  'language' => 'en'
154  )),
155  array(array(
156  'parent_id' => null,
157  'content_id' => '1',
158  'user_id' => null,
159  'moderator_email' => 'email@email.com',
160  'firstname' => 'First name',
161  'lastname' => 'Last name',
162  'email' => 'email@email.com',
163  'subject' => 'Subject',
164  'description' => 'Description',
165  'notify_moderator' => 1,
166  'notify_user' => 1,
167  'status' => Comment::APPROVED,
168  'language' => 'en'
169  )),
170  array(array(
171  'parent_id' => null,
172  'content_id' => 'STRING_ID',
173  'user_id' => 1,
174  'moderator_email' => 'email@email.com',
175  'firstname' => 'First name',
176  'lastname' => 'Last name',
177  'email' => 'email@email.com',
178  'subject' => 'Subject',
179  'description' => 'Description',
180  'notify_moderator' => 1,
181  'notify_user' => 1,
182  'status' => Comment::APPROVED,
183  'language' => 'en'
184  )),
185  array(array(
186  'parent_id' => 100,
187  'content_id' => '1',
188  'user_id' => null,
189  'moderator_email' => 'email@email.com',
190  'firstname' => 'First name',
191  'lastname' => 'Last name',
192  'email' => 'email@email.com',
193  'subject' => 'Subject',
194  'description' => 'Description',
195  'notify_moderator' => 1,
196  'notify_user' => 1,
197  'status' => Comment::APPROVED,
198  'language' => 'en'
199  )),
200  );
201  }
202 
203  public function testSearch()
204  {
205  $this->assertInstanceOf('CActiveDataProvider', Comment::model()->search());
206  }
207 
208 }