| 112 | | $t->diag('getModerationStatus(), setModerationStatus(), getModerationComment(), setModerationComment()'); |
|---|
| 113 | | $item1 = new $test_class(); |
|---|
| 114 | | // Object must be modified to be saved |
|---|
| 115 | | $item1->setByName($test_title_column, 'foo'); |
|---|
| 116 | | $item1->save(); |
|---|
| 117 | | $t->is($item1->getModerationStatus(), 1, 'getModerationStatus() returns the current moderation status (defaults to 1 = not checked)'); |
|---|
| 118 | | $item1->setModerationStatus(0); |
|---|
| 119 | | $t->is($item1->getModerationStatus(), 0, 'setModerationStatus() changes the moderation status'); |
|---|
| 120 | | $t->diag('getModerationComment() and setModerationComment()'); |
|---|
| 121 | | $t->is($item1->getModerationComment(), '', 'getModerationComment() returns the current moderation comment (defaults to empty string)'); |
|---|
| 122 | | $t->is($item1->setModerationComment('Moderated because foo bar'), null, 'setModerationComment() returns null if the moderation comment column exists'); |
|---|
| 123 | | $t->is($item1->getModerationComment(), 'Moderated because foo bar', 'getModerationComment() returns the current moderation comment'); |
|---|
| 124 | | |
|---|
| 125 | | |
|---|
| 126 | | $t->diag('modifications of selection and count methods'); |
|---|
| 127 | | call_user_func(array($test_peer_class, 'doDeleteAll')); |
|---|
| 128 | | $item1 = new $test_class(); |
|---|
| 129 | | $item1->setModerationStatus(sfPropelModerationBehavior::NOT_CHECKED); |
|---|
| 130 | | $item1->save(); |
|---|
| 131 | | $id1 = $item1->getId(); |
|---|
| 132 | | $item2 = new $test_class(); |
|---|
| 133 | | $item2->setModerationStatus(sfPropelModerationBehavior::TAGGED_UNSAFE); |
|---|
| 134 | | $item2->save(); |
|---|
| 135 | | $id2 = $item2->getId(); |
|---|
| 136 | | $item3 = new $test_class(); |
|---|
| 137 | | $item3->setModerationStatus(sfPropelModerationBehavior::TAGGED_SAFE); |
|---|
| 138 | | $item3->save(); |
|---|
| 139 | | $id3 = $item3->getId(); |
|---|
| 140 | | $t->isa_ok(call_user_func(array($test_peer_class, 'retrieveByPk'), $id1), $test_class, 'retrieveByPk() finds unmarked records'); |
|---|
| 141 | | $t->isa_ok(call_user_func(array($test_peer_class, 'retrieveByPk'), $id2), 'NULL', 'retrieveByPk() doesn\'t find records marked as spam'); |
|---|
| 142 | | $t->isa_ok(call_user_func(array($test_peer_class, 'retrieveByPk'), $id3), $test_class, 'retrieveByPk() finds records marked as safe'); |
|---|
| 143 | | $t->is(call_user_func(array($test_peer_class, 'doCount'), new Criteria()), 2, 'doCount() ignores records marked as spam'); |
|---|
| 144 | | $t->is(count(call_user_func(array($test_peer_class, 'doSelect'), new Criteria())), 2, 'doSelect() ignores records marked as spam'); |
|---|
| 145 | | |
|---|
| 146 | | $t->diag('Publish/unpublish messages by default via app.yml'); |
|---|
| 147 | | sfConfig::set('app_sfModerationPlugin_display_treshold', sfPropelModerationBehavior::TAGGED_SAFE); |
|---|
| 148 | | $t->isa_ok(call_user_func(array($test_peer_class, 'retrieveByPk'), $id1), 'NULL', 'Setting `app_sfModerationPlugin_display_treshold` to 0 ignores unchecked records from normal selection'); |
|---|
| 149 | | $t->is(call_user_func(array($test_peer_class, 'doCount'), new Criteria()), 1, 'Setting `app_sfModerationPlugin_display_treshold` to 0 ignores unchecked records from normal selection'); |
|---|
| 150 | | sfConfig::set('app_sfModerationPlugin_display_treshold', sfPropelModerationBehavior::NOT_CHECKED); |
|---|
| 151 | | $t->isa_ok(call_user_func(array($test_peer_class, 'retrieveByPk'), $id1), $test_class, 'Setting `app_sfModerationPlugin_display_treshold` to 1 revelas unchecked records from normal selection'); |
|---|
| 152 | | $t->is(call_user_func(array($test_peer_class, 'doCount'), new Criteria()), 2, 'Setting `app_sfModerationPlugin_display_treshold` to 1 reveals unchecked records from normal selection'); |
|---|
| 153 | | sfConfig::set('app_sfModerationPlugin_display_treshold', sfPropelModerationBehavior::TAGGED_UNSAFE); |
|---|
| 154 | | $t->isa_ok(call_user_func(array($test_peer_class, 'retrieveByPk'), $id1), $test_class, 'Setting `app_sfModerationPlugin_display_treshold` to 3 lets all records through'); |
|---|
| 155 | | $t->is(call_user_func(array($test_peer_class, 'doCount'), new Criteria()), 3, 'Setting `app_sfModerationPlugin_display_treshold` to 3 lets all records through'); |
|---|
| 156 | | sfConfig::set('app_sfModerationPlugin_display_treshold', sfPropelModerationBehavior::NOT_CHECKED); |
|---|
| 157 | | |
|---|
| 158 | | $t->diag('tagAsUnsafe() and tagAsSafe()'); |
|---|
| 159 | | call_user_func(array($test_peer_class, 'doDeleteAll')); |
|---|
| 160 | | $item1 = new $test_class(); |
|---|
| 161 | | // Object must be modified to be saved |
|---|
| 162 | | $item1->setByName($test_title_column, 'foo'); |
|---|
| 163 | | $item1->save(); |
|---|
| 164 | | $id1 = $item1->getId(); |
|---|
| 165 | | $item1->tagAsUnsafe(); |
|---|
| 166 | | $t->isa_ok(call_user_func(array($test_peer_class, 'retrieveByPk'), $id1), 'NULL', 'tagAsUnsafe() changes the status to spam and saves the record'); |
|---|
| 167 | | $t->is($item1->getModerationStatus(), sfPropelModerationBehavior::TAGGED_UNSAFE, 'tagAsUnsafe() changes the status to spam and saves the record'); |
|---|
| 168 | | $item1->tagAsUnsafe(sfPropelModerationBehavior::AUTO_TAGGED_UNSAFE); |
|---|
| 169 | | $t->is($item1->getModerationStatus(), sfPropelModerationBehavior::AUTO_TAGGED_UNSAFE, 'tagAsUnsafe(sfPropelModerationBehavior::AUTO_TAGGED_UNSAFE) changes the status to auto_spam and saves the record'); |
|---|
| 170 | | $item1->tagAsUnsafe(12); |
|---|
| 171 | | $t->is($item1->getModerationStatus(), 12, 'tagAsUnsafe() accepts custom status codes'); |
|---|
| 172 | | $item2 = new $test_class(); |
|---|
| 173 | | // Object must be modified to be saved |
|---|
| 174 | | $item2->setByName($test_title_column, 'foo'); |
|---|
| 175 | | $item2->save(); |
|---|
| 176 | | $id2 = $item2->getId(); |
|---|
| 177 | | $item2->tagAsSafe(); |
|---|
| 178 | | $t->isa_ok(call_user_func(array($test_peer_class, 'retrieveByPk'), $id2), $test_class, 'tagAsSafe() changes the status to safe and saves the record'); |
|---|
| 179 | | $t->is($item2->getModerationStatus(), sfPropelModerationBehavior::TAGGED_SAFE, 'tagAsSafe() changes the status to safe and saves the record'); |
|---|
| 180 | | |
|---|
| 181 | | $t->diag('sfPropelModerationBehavior::enable() and disable()'); |
|---|
| 182 | | call_user_func(array($test_peer_class, 'doDeleteAll')); |
|---|
| 183 | | $item1 = new $test_class(); |
|---|
| 184 | | $item1->setModerationStatus(sfPropelModerationBehavior::NOT_CHECKED); |
|---|
| 185 | | $item1->save(); |
|---|
| 186 | | $item2 = new $test_class(); |
|---|
| 187 | | $item2->setModerationStatus(sfPropelModerationBehavior::TAGGED_UNSAFE); |
|---|
| 188 | | $item2->save(); |
|---|
| 189 | | $item3 = new $test_class(); |
|---|
| 190 | | $item3->setModerationStatus(sfPropelModerationBehavior::TAGGED_SAFE); |
|---|
| 191 | | $item3->save(); |
|---|
| 192 | | $t->is(call_user_func(array($test_peer_class, 'doCount'), new Criteria()), 2, 'Spam check is enabled by default in selections'); |
|---|
| 193 | | sfPropelModerationBehavior::disable(); |
|---|
| 194 | | $t->is(call_user_func(array($test_peer_class, 'doCount'), new Criteria()), 3, 'Setting sfPropelModerationBehavior::disable() disables the spam check in selections'); |
|---|
| 195 | | sfPropelModerationBehavior::enable(); |
|---|
| 196 | | $t->is(call_user_func(array($test_peer_class, 'doCount'), new Criteria()), 2, 'Setting sfPropelModerationBehavior::enable() enables the spam check in selections'); |
|---|
| 197 | | |
|---|
| 198 | | |
|---|
| 199 | | //$t->is($item1->); |
|---|
| 200 | | |
|---|
| 201 | | $t->diag('Monitoring and sfModeratedContent'); |
|---|
| 202 | | sfConfig::set('app_sfModerationPlugin_monitoring_treshold', sfPropelModerationBehavior::TAGGED_SAFE); |
|---|
| 203 | | $item1 = new $test_class(); |
|---|
| 204 | | $item1->setByName($test_title_column, 'foo'); |
|---|
| 205 | | $item1->setByName($test_content_column, 'bar'); |
|---|
| 206 | | $item1->setByName($test_url_column, 'http://foo'); |
|---|
| 207 | | $item1->setByName($test_username_column, 'mister bar'); |
|---|
| 208 | | $item1->setByName($test_useremail_column, 'foo@bar.com'); |
|---|
| 209 | | $item1->save(); |
|---|
| 210 | | $t->is($item1->getModeratedContentFromObject(), null, 'monitoring is not enabled by default and getModeratedContentFromObject() returns null'); |
|---|
| 211 | | sfConfig::set('app_sfModerationPlugin_is_monitored', true); |
|---|
| 212 | | // Object must be modified to be saved |
|---|
| 213 | | $item1->setByName($test_title_column, 'bar'); |
|---|
| 214 | | $item1->save(); |
|---|
| 215 | | $t->isa_ok($item1->getModeratedContentFromObject(), 'sfModeratedContent', 'per class monitoring is enabled by default'); |
|---|
| 216 | | sfConfig::set('propel_behavior_moderation_'.$test_class.'_is_monitored', false); |
|---|
| 217 | | $t->is($item1->getModeratedContentFromObject(), null, 'monitoring can be disabled on a per class basis and getModeratedContentFromObject() returns null'); |
|---|
| 218 | | sfConfig::set('propel_behavior_moderation_'.$test_class.'_is_monitored', true); |
|---|
| 219 | | // Object must be modified to be saved |
|---|
| 220 | | $item1->setByName($test_title_column, 'foo'); |
|---|
| 221 | | $item1->save(); |
|---|
| 222 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 223 | | $t->isa_ok($moderated_content, 'sfModeratedContent', 'enabling monitoring both globally and on an object activates auto creation of an sfModeratedContent object each time a monitored object is saved'); |
|---|
| 224 | | $t->is($moderated_content->getObjectId(), $item1->getId(), 'sfModeratedContent object gets the Propel object id'); |
|---|
| 225 | | $t->is($moderated_content->getObjectModel(), $test_class, 'sfModeratedContent object gets the Propel object class'); |
|---|
| 226 | | $t->is($moderated_content->getTitle(), 'foo', 'sfModeratedContent object gets the Propel object title'); |
|---|
| 227 | | $t->is($moderated_content->getContent(), 'bar', 'sfModeratedContent object gets the Propel object content'); |
|---|
| 228 | | $t->is($moderated_content->getUrl(), 'http://foo', 'sfModeratedContent object gets the Propel object url'); |
|---|
| 229 | | $t->is($moderated_content->getUsername(), 'mister bar', 'sfModeratedContent object gets the Propel object user name'); |
|---|
| 230 | | $t->is($moderated_content->getUserEmail(), 'foo@bar.com', 'sfModeratedContent object gets the Propel object user email'); |
|---|
| 231 | | $item1->setModerationComment('This is foo'); |
|---|
| 232 | | $item1->tagAsUnsafe(); |
|---|
| 233 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 234 | | $t->is($moderated_content->getStatus(), sfPropelModerationBehavior::TAGGED_UNSAFE, 'sfModeratedContent object gets the Propel object moderation status'); |
|---|
| 235 | | $t->is($moderated_content->getComment(), 'This is foo', 'sfModeratedContent object gets the Propel object moderation comment'); |
|---|
| 236 | | $moderated_content_id = $moderated_content->getId(); |
|---|
| 237 | | $item1->save(); |
|---|
| 238 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 239 | | $t->is($moderated_content->getId(), $moderated_content_id, 'updating a moderated object updates the related sfModeratedContent and does not create a new one'); |
|---|
| 240 | | $item1->delete(); |
|---|
| 241 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 242 | | $t->is($item1->getModeratedContentFromObject(), null, 'deleting a monitored object also deletes its related sfModeratedContent'); |
|---|
| 243 | | |
|---|
| 244 | | $t->diag('Watched columns'); |
|---|
| 245 | | $watch_columns = sfPropelModerationBehavior::getWatchedColumns($test_class); |
|---|
| 246 | | $common_columns = array_intersect($watch_columns, $test_watch_columns); |
|---|
| 247 | | $t->is(count($common_columns), count($test_watch_columns), 'getWatchedColumns() includes all config watched columns'); |
|---|
| 248 | | $t->ok(in_array($test_status_column, $watch_columns), 'getWatchedColumns() includes config watched columns'); |
|---|
| 249 | | $t->ok(in_array($test_comment_column, $watch_columns), 'getWatchedColumns() includes config watched columns'); |
|---|
| 250 | | if (constant($test_peer_class.'::EXTRA')) |
|---|
| 251 | | { |
|---|
| 252 | | // We have extra non-moderated column |
|---|
| 253 | | sfConfig::set('app_sfModerationPlugin_is_monitored', true); |
|---|
| 254 | | sfConfig::set('propel_behavior_moderation_'.$test_class.'_is_monitored', true); |
|---|
| 255 | | $test_extra_column = 'Extra'; |
|---|
| 256 | | $item1 = new $test_class(); |
|---|
| 257 | | $item1->setByName($test_extra_column, 'foo'); |
|---|
| 258 | | $item1->save(); |
|---|
| 259 | | $t->is($item1->getModeratedContentFromObject(), null, 'Modifying non-watched columns doesn\'t trigger moderation and getModeratedContentFromObject() returns null'); |
|---|
| 260 | | } |
|---|
| 261 | | |
|---|
| 262 | | $t->diag('sfModeratedContent dates'); |
|---|
| 263 | | $item1 = new $test_class(); |
|---|
| 264 | | // Object must be modified to be saved |
|---|
| 265 | | $item1->setByName($test_title_column, 'foo'); |
|---|
| 266 | | $item1->save(); |
|---|
| 267 | | $item1_updated_at = $item1->getUpdatedAt('U'); |
|---|
| 268 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 269 | | $t->is($moderated_content->getObjectUpdatedAt('U'), $item1_updated_at, 'sfModeratedContent object gets the Propel object update date in object_updated_at'); |
|---|
| 270 | | $t->is($moderated_content->getModeratedAt('U'), $item1_updated_at, 'sfModeratedContent knows when it was last moderated in moderated_at'); |
|---|
| 271 | | sleep(1); |
|---|
| 272 | | $item1->tagAsSafe(); |
|---|
| 273 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 274 | | $t->is($moderated_content->getObjectUpdatedAt('U'), $item1_updated_at, 'Tagging a propel object doesn\'t change its update date'); |
|---|
| 275 | | $t->isnt($moderated_content->getModeratedAt('U'), $item1_updated_at, 'Tagging a propel object changes the related sfModeratedContent moderated_at date'); |
|---|
| 276 | | |
|---|
| 277 | | $t->diag('Monitoring treshold'); |
|---|
| 278 | | sfConfig::set('app_sfModerationPlugin_monitoring_treshold', sfPropelModerationBehavior::AUTO_TAGGED_UNSAFE); |
|---|
| 279 | | $item1 = new $test_class(); |
|---|
| 280 | | // Object must be modified to be saved |
|---|
| 281 | | $item1->setByName($test_title_column, 'foo'); |
|---|
| 282 | | $item1->save(); |
|---|
| 283 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 284 | | $t->isa_ok($moderated_content, 'NULL', 'Saving an object with a moderation status below the treshold doesn\'t save a sfModeratedContent'); |
|---|
| 285 | | $item1->tagAsUnsafe(); |
|---|
| 286 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 287 | | $t->isa_ok($moderated_content, 'sfModeratedContent', 'Saving an object with a moderation status greater than the treshold saves a sfModeratedContent'); |
|---|
| 288 | | $item1->tagAsSafe(); |
|---|
| 289 | | $moderated_content = $item1->getModeratedContentFromObject(); |
|---|
| 290 | | $t->isa_ok($moderated_content, 'NULL', 'Declaring an object as safe removes the related sfModeratedContent with the default monitoring treshold'); |
|---|
| 291 | | |
|---|
| 292 | | $t->diag('Utility methods'); |
|---|
| 293 | | class myClass |
|---|
| 294 | | { |
|---|
| 295 | | public function foo2() |
|---|
| 296 | | { |
|---|
| 297 | | return 'bar'; |
|---|
| 298 | | } |
|---|
| 299 | | public function foo3() |
|---|
| 300 | | { |
|---|
| 301 | | return 'bar3'; |
|---|
| 302 | | } |
|---|
| 303 | | |
|---|
| 304 | | } |
|---|
| 305 | | $myobject = new myClass(); |
|---|
| 306 | | $t->is(sfModeratedContentPeer::getOneOf($myobject, array('foo0', 'foo1', 'foo2', 'foo3')), 'bar', 'sfModeratedContentPeer::getOneOf() tests several methods on an object and returns the result of the first matching one'); |
|---|
| | 64 | $h->run(); |
|---|