Révision b08d2851
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/flag/tests/flag.test | ||
---|---|---|
245 | 245 |
*/ |
246 | 246 |
function testFlagAdmin() { |
247 | 247 |
// Add a new flag using the UI. |
248 |
$this->drupalGet(FLAG_ADMIN_PATH . '/add/node'); |
|
249 |
|
|
250 |
// Check the form has the expected defaults. |
|
251 |
$this->assertFieldByName('flag_short', 'Flag this item', "The flag message default value shows in the form."); |
|
252 |
$this->assertFieldByName('unflag_short', 'Unflag this item', "The unflag message default value shows in the form."); |
|
253 |
$this->assertFieldByName('show_in_links[full]', 'full', "The view mode option is set to the node 'full' view mode by default."); |
|
254 |
$this->assertFieldByName('show_in_links[teaser]', 'teaser', "The view mode option is set to the node 'teaser' view mode by default."); |
|
255 |
|
|
248 | 256 |
$edit = array( |
249 | 257 |
'name' => drupal_strtolower($this->randomName()), |
250 | 258 |
'title' => $this->randomName(), |
... | ... | |
463 | 471 |
|
464 | 472 |
} |
465 | 473 |
|
474 |
/** |
|
475 |
* Tokens we provide on generic entities. |
|
476 |
*/ |
|
477 |
class FlagEntityTokensTestCase extends FlagTestCaseBase { |
|
478 |
|
|
479 |
/** |
|
480 |
* Implements getInfo(). |
|
481 |
*/ |
|
482 |
public static function getInfo() { |
|
483 |
return array( |
|
484 |
'name' => 'Flag: Entity tokens', |
|
485 |
'description' => 'Tokens for flag count on entities.', |
|
486 |
'group' => 'Flag', |
|
487 |
); |
|
488 |
} |
|
489 |
|
|
490 |
/** |
|
491 |
* Implements setUp(). |
|
492 |
*/ |
|
493 |
function setUp() { |
|
494 |
// Our entity tokens require token module. |
|
495 |
parent::setUp('flag', 'token'); |
|
496 |
} |
|
497 |
|
|
498 |
/** |
|
499 |
* Test tokens on nodes. |
|
500 |
*/ |
|
501 |
function testNodeFlagToken() { |
|
502 |
// Create a flag on article nodes. |
|
503 |
$flag_data = array( |
|
504 |
'entity_type' => 'node', |
|
505 |
'name' => 'node_flag', |
|
506 |
'title' => 'Node Flag', |
|
507 |
'global' => 0, |
|
508 |
'types' => array( |
|
509 |
0 => 'article', |
|
510 |
), |
|
511 |
'flag_short' => 'Flag this item', |
|
512 |
'flag_long' => '', |
|
513 |
'flag_message' => '', |
|
514 |
'unflag_short' => 'Unflag this item', |
|
515 |
'unflag_long' => '', |
|
516 |
'unflag_message' => '', |
|
517 |
'unflag_denied_text' => 'You may not unflag this item', |
|
518 |
'link_type' => 'normal', |
|
519 |
'weight' => 0, |
|
520 |
// Show the flag on the form. |
|
521 |
'show_on_form' => 1, |
|
522 |
'access_author' => '', |
|
523 |
'show_contextual_link' => 0, |
|
524 |
'show_in_links' => array( |
|
525 |
'full' => 1, |
|
526 |
'teaser' => 1, |
|
527 |
), |
|
528 |
'i18n' => 0, |
|
529 |
'api_version' => 3, |
|
530 |
); |
|
531 |
$flag = $this->createFlag($flag_data); |
|
532 |
|
|
533 |
// Create a node to flag. |
|
534 |
$node = (object) array( |
|
535 |
'type' => 'article', |
|
536 |
'title' => $this->randomName(), |
|
537 |
); |
|
538 |
node_save($node); |
|
539 |
|
|
540 |
// Flag it by several users. |
|
541 |
$flag_user_1 = $this->drupalCreateUser(array('flag node_flag',)); |
|
542 |
|
|
543 |
// Flag the node as the user. |
|
544 |
$flag = flag_get_flag('node_flag'); |
|
545 |
$flag->flag('flag', $node->nid, $flag_user_1); |
|
546 |
|
|
547 |
$flag_user_2 = $this->drupalCreateUser(array('flag node_flag',)); |
|
548 |
|
|
549 |
// Flag the node as the user. |
|
550 |
$flag->flag('flag', $node->nid, $flag_user_2); |
|
551 |
|
|
552 |
$text = '[node:flag-node-flag-count]'; |
|
553 |
|
|
554 |
$replaced_text = token_replace($text, array('node' => $node)); |
|
555 |
|
|
556 |
$this->assertEqual($replaced_text, 2, "The flag count token for the node is correct."); |
|
557 |
} |
|
558 |
|
|
559 |
/** |
|
560 |
* Test tokens on taxonomy terms. |
|
561 |
* |
|
562 |
* These are worthy of a separate test, as the token type is a special case. |
|
563 |
*/ |
|
564 |
function testTaxonomyTermFlagToken() { |
|
565 |
// Create a flag on tag terms. |
|
566 |
$flag_data = array( |
|
567 |
'entity_type' => 'taxonomy_term', |
|
568 |
'name' => 'term_flag', |
|
569 |
'title' => 'Term Flag', |
|
570 |
'global' => 0, |
|
571 |
'types' => array( |
|
572 |
0 => 'tags', |
|
573 |
), |
|
574 |
'flag_short' => 'Flag this item', |
|
575 |
'flag_long' => '', |
|
576 |
'flag_message' => '', |
|
577 |
'unflag_short' => 'Unflag this item', |
|
578 |
'unflag_long' => '', |
|
579 |
'unflag_message' => '', |
|
580 |
'unflag_denied_text' => 'You may not unflag this item', |
|
581 |
'link_type' => 'normal', |
|
582 |
'weight' => 0, |
|
583 |
// Show the flag on the form. |
|
584 |
'show_on_form' => 1, |
|
585 |
'access_author' => '', |
|
586 |
'show_contextual_link' => 0, |
|
587 |
'show_in_links' => array( |
|
588 |
'full' => 1, |
|
589 |
'teaser' => 1, |
|
590 |
), |
|
591 |
'i18n' => 0, |
|
592 |
'api_version' => 3, |
|
593 |
); |
|
594 |
$flag = $this->createFlag($flag_data); |
|
595 |
|
|
596 |
$vocabulary = taxonomy_vocabulary_load(1); |
|
597 |
|
|
598 |
// Create a term to flag. |
|
599 |
$term = (object) array( |
|
600 |
'name' => $this->randomName(), |
|
601 |
'vid' => 1, |
|
602 |
); |
|
603 |
taxonomy_term_save($term); |
|
604 |
|
|
605 |
// Flag it by several users. |
|
606 |
$flag_user_1 = $this->drupalCreateUser(array('flag term_flag',)); |
|
607 |
|
|
608 |
// Flag the term as the user. |
|
609 |
$flag = flag_get_flag('term_flag'); |
|
610 |
$flag->flag('flag', $term->tid, $flag_user_1); |
|
611 |
|
|
612 |
$flag_user_2 = $this->drupalCreateUser(array('flag term_flag',)); |
|
613 |
|
|
614 |
// Flag the term as the user. |
|
615 |
$flag = flag_get_flag('term_flag'); |
|
616 |
$flag->flag('flag', $term->tid, $flag_user_2); |
|
617 |
|
|
618 |
$text = '[term:flag-term-flag-count]'; |
|
619 |
|
|
620 |
$replaced_text = token_replace($text, array('term' => $term)); |
|
621 |
|
|
622 |
debug($replaced_text); |
|
623 |
|
|
624 |
$this->assertEqual($replaced_text, 2, "The flag count token for the term is correct."); |
|
625 |
} |
|
626 |
|
|
627 |
} |
|
628 |
|
|
466 | 629 |
/** |
467 | 630 |
* Access to flags using the basic flag link. |
468 | 631 |
*/ |
... | ... | |
642 | 805 |
'i18n' => 0, |
643 | 806 |
'api_version' => 3, |
644 | 807 |
); |
645 |
$flag = flag_flag::factory_by_array($this->flag_data); |
|
646 |
$flag->save(); |
|
808 |
$this->flag = flag_flag::factory_by_array($this->flag_data);
|
|
809 |
$this->flag->save();
|
|
647 | 810 |
// Reset our cache so our permissions show up. |
648 | 811 |
drupal_static_reset('flag_get_flags'); |
649 | 812 |
|
... | ... | |
651 | 814 |
$this->checkPermissions(array(), TRUE); |
652 | 815 |
|
653 | 816 |
// Create test user who can flag and unflag. |
654 |
$flag_unflag_user = $this->drupalCreateUser(array('flag test_flag', 'unflag test_flag')); |
|
655 |
$this->drupalLogin($flag_unflag_user); |
|
817 |
$this->flag_unflag_user = $this->drupalCreateUser(array('flag test_flag', 'unflag test_flag'));
|
|
818 |
$this->drupalLogin($this->flag_unflag_user);
|
|
656 | 819 |
|
657 | 820 |
// Create an article node to flag and unflag. |
658 | 821 |
$title = $this->randomName(8); |
... | ... | |
669 | 832 |
} |
670 | 833 |
|
671 | 834 |
/** |
672 |
* Test that a user sees the flag confirm form.
|
|
835 |
* Test usage of the flag confirm form.
|
|
673 | 836 |
*/ |
674 | 837 |
function testFlag() { |
675 | 838 |
// Look at our node. |
... | ... | |
694 | 857 |
$this->assertText($this->flag_data['flag_message'], 'The flag message appears once the item has been flagged.'); |
695 | 858 |
$this->assertLink($this->flag_data['unflag_short'], 0, 'The unflag link appears once the item has been flagged.'); |
696 | 859 |
|
860 |
// Reset the static cache before we get data from it. |
|
861 |
drupal_static_reset('flag_get_user_flags'); |
|
862 |
$this->assertTrue($this->flag->is_flagged($this->nid, $this->flag_unflag_user->uid), "The node is recorded as flagged by the user."); |
|
863 |
|
|
697 | 864 |
// Click the link to unflag the node. |
698 | 865 |
$this->clickLink($this->flag_data['unflag_short']); |
699 | 866 |
|
... | ... | |
709 | 876 |
$this->drupalPost(NULL, array(), $this->flag_data['unflag_short']); |
710 | 877 |
|
711 | 878 |
$this->assertText($this->flag_data['unflag_message'], 'The unflag message appears once the item has been flagged.'); |
879 |
|
|
880 |
// Reset the static cache before we get data from it. |
|
881 |
drupal_static_reset('flag_get_user_flags'); |
|
882 |
$this->assertFalse($this->flag->is_flagged($this->nid, $this->flag_unflag_user->uid), "The node is recorded as not flagged by the user."); |
|
712 | 883 |
} |
713 | 884 |
|
714 | 885 |
} |
... | ... | |
969 | 1140 |
} |
970 | 1141 |
|
971 | 1142 |
} |
1143 |
|
|
1144 |
/** |
|
1145 |
* Verifies the invocation of hooks when performing flagging and unflagging. |
|
1146 |
*/ |
|
1147 |
class FlagHookInvocationsTestCase extends FlagTestCaseBase { |
|
1148 |
|
|
1149 |
/** |
|
1150 |
* Implements getInfo(). |
|
1151 |
*/ |
|
1152 |
public static function getInfo() { |
|
1153 |
return array( |
|
1154 |
'name' => 'Flag hook invocations', |
|
1155 |
'description' => 'Invocation of flag and entity hooks and rules during flagging and unflagging.', |
|
1156 |
'group' => 'Flag', |
|
1157 |
); |
|
1158 |
} |
|
1159 |
|
|
1160 |
/** |
|
1161 |
* Implements setUp(). |
|
1162 |
*/ |
|
1163 |
function setUp() { |
|
1164 |
parent::setUp('flag', 'rules', 'flag_hook_test'); |
|
1165 |
|
|
1166 |
// Note the test module contains our test flag. |
|
1167 |
|
|
1168 |
// Create test user who can flag and unflag. |
|
1169 |
$this->flag_unflag_user = $this->drupalCreateUser(array('flag flag_hook_test_flag', 'unflag flag_hook_test_flag')); |
|
1170 |
$this->drupalLogin($this->flag_unflag_user); |
|
1171 |
} |
|
1172 |
|
|
1173 |
/** |
|
1174 |
* Test invocation of hooks and their data during flagging and unflagging. |
|
1175 |
* |
|
1176 |
* For each operation (flagging, re-flagging, unflagging) we test: |
|
1177 |
* - the order in which Flag hooks, entity hooks, and rules are invoked. |
|
1178 |
* - the parameters each hook receives |
|
1179 |
* - the data that a hook implementation obtains when it calls the Flag data |
|
1180 |
* API functions. |
|
1181 |
*/ |
|
1182 |
function testHookInvocation() { |
|
1183 |
// Create an article node that we try to create a flagging entity for. |
|
1184 |
$title = $this->randomName(8); |
|
1185 |
$node = array( |
|
1186 |
'title' => $title, |
|
1187 |
'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))), |
|
1188 |
'uid' => 1, |
|
1189 |
'type' => 'article', |
|
1190 |
'is_new' => TRUE, |
|
1191 |
); |
|
1192 |
$node = node_submit((object) $node); |
|
1193 |
node_save($node); |
|
1194 |
|
|
1195 |
// Initialize a tracking variable. The test module will update this when |
|
1196 |
// its hooks are invoked. |
|
1197 |
variable_set('flag_hook_test_hook_tracking', array()); |
|
1198 |
|
|
1199 |
// Flag the node as the user. |
|
1200 |
$flag = flag_get_flag('flag_hook_test_flag'); |
|
1201 |
$flag->flag('flag', $node->nid, $this->flag_unflag_user); |
|
1202 |
|
|
1203 |
// Get the variable the test module sets the hook order into. |
|
1204 |
$hook_data_variable = variable_get('flag_hook_test_hook_tracking', array()); |
|
1205 |
//debug($hook_data_variable['hook_entity_presave']); |
|
1206 |
//debug($hook_data_variable['hook_entity_insert']); |
|
1207 |
|
|
1208 |
$expected_hook_order = array( |
|
1209 |
'hook_entity_presave', |
|
1210 |
'hook_entity_insert', |
|
1211 |
'hook_flag_flag', |
|
1212 |
'rules_event', |
|
1213 |
); |
|
1214 |
|
|
1215 |
// Check the hooks are invoked in the correct order. |
|
1216 |
$this->assertIdentical($expected_hook_order, array_keys($hook_data_variable), "The hooks are invoked in the correct order when flagging a node."); |
|
1217 |
|
|
1218 |
// Check the parameters received by hook_entity_presave(). |
|
1219 |
// Param 0: $flagging. |
|
1220 |
// There is a bug with what is passed to entity hooks; for now, just check |
|
1221 |
// the things that do get passed. |
|
1222 |
// See https://drupal.org/node/2196055. |
|
1223 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_presave() has the expected flag name property."); |
|
1224 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid); |
|
1225 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node'); |
|
1226 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_presave() has the expected entity ID property."); |
|
1227 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_presave() has the expected uid property."); |
|
1228 |
// Param 1: $entity_type. |
|
1229 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][1], 'flagging', "hook_entity_presave() is passed the correct entity type."); |
|
1230 |
|
|
1231 |
// Check the API data available to hook_entity_presave(). |
|
1232 |
//debug($hook_data_variable['hook_entity_presave']['api_calls']); |
|
1233 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['api_calls']['flag_get_entity_flags'], array(), "hook_entity_presave() gets no data from from flag_get_entity_flags(), as the flagging has not yet taken place."); |
|
1234 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['api_calls']['flag_get_user_flags'], array(), "hook_entity_presave() gets no data from from flag_get_user_flags(), as the flagging has not yet taken place."); |
|
1235 |
// The flag counts have not yet been increased. |
|
1236 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['api_calls']['flag_get_counts'], array(), "hook_entity_presave() gets no data from from flag_get_counts(), as the flagging has not yet taken place."); |
|
1237 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['api_calls']['flag_get_flag_counts'], 0, "hook_entity_presave() gets no data from from flag_get_flag_counts(), as the flagging has not yet taken place."); |
|
1238 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['api_calls']['flag_get_entity_flag_counts'], 0, "hook_entity_presave() gets no data from from flag_get_entity_flag_counts(), as the flagging has not yet taken place."); |
|
1239 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['api_calls']['flag_get_user_flag_counts'], 0, "hook_entity_presave() gets no data from from flag_get_user_flag_counts(), as the flagging has not yet taken place."); |
|
1240 |
|
|
1241 |
// Check the parameters received by hook_entity_insert(). |
|
1242 |
// Param 0: $flagging. |
|
1243 |
// See https://drupal.org/node/2196055. |
|
1244 |
$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_insert() has the expected flag name property."); |
|
1245 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid); |
|
1246 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node'); |
|
1247 |
$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_insert() has the expected entity ID property."); |
|
1248 |
$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_insert() has the expected uid property."); |
|
1249 |
$this->assertTrue(!empty($hook_data_variable['hook_entity_insert']['parameters'][0]->flagging_id), "The Flagging entity passed to hook_entity_insert() has the flagging ID set."); |
|
1250 |
// Param 1: $entity_type. |
|
1251 |
$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][1], 'flagging', "hook_entity_insert() is passed the correct entity type."); |
|
1252 |
|
|
1253 |
// Check the API data available to hook_entity_insert(). |
|
1254 |
//debug($hook_data_variable['hook_entity_insert']['api_calls']); |
|
1255 |
$flag_get_entity_flags = $hook_data_variable['hook_entity_insert']['api_calls']['flag_get_entity_flags']; |
|
1256 |
$flag_get_entity_flags_uids = array_keys($flag_get_entity_flags); |
|
1257 |
$this->assertEqual($flag_get_entity_flags_uids, array($this->flag_unflag_user->uid), "hook_entity_insert() gets correct data for flagging users from flag_get_entity_flags()"); |
|
1258 |
$flag_get_entity_flags_flagging = $flag_get_entity_flags[$this->flag_unflag_user->uid]; |
|
1259 |
$this->assertEqual($flag_get_entity_flags_flagging->fid, $flag->fid, "hook_entity_insert() gets a correct fid on the Flagging obtained from flag_get_entity_flags()"); |
|
1260 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_type, 'node', "hook_entity_insert() gets a correct entity type on the Flagging obtained from flag_get_entity_flags()"); |
|
1261 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_id, $node->nid, "hook_entity_insert() gets a correct entity ID on the Flagging obtained from flag_get_entity_flags()"); |
|
1262 |
|
|
1263 |
$flag_get_user_flags = $hook_data_variable['hook_entity_insert']['api_calls']['flag_get_user_flags']; |
|
1264 |
$flag_get_user_flags_flagging = $flag_get_user_flags[$flag->name]; |
|
1265 |
$this->assertEqual($flag_get_user_flags_flagging->fid, $flag->fid, "hook_entity_insert() gets a correct fid on the Flagging obtained from flag_get_user_flags()"); |
|
1266 |
$this->assertEqual($flag_get_user_flags_flagging->entity_type, 'node', "hook_entity_insert() gets a correct entity type on the Flagging obtained from flag_get_user_flags()"); |
|
1267 |
$this->assertEqual($flag_get_user_flags_flagging->entity_id, $node->nid, "hook_entity_insert() gets a correct entity ID on the Flagging obtained from flag_get_user_flags()"); |
|
1268 |
|
|
1269 |
// The flag counts have been increased. |
|
1270 |
$flag_get_counts = $hook_data_variable['hook_entity_insert']['api_calls']['flag_get_counts']; |
|
1271 |
$this->assertEqual($flag_get_counts[$flag->name], 1, "hook_entity_insert() gets a correct flag count from flag_get_counts()."); |
|
1272 |
|
|
1273 |
$flag_get_flag_counts = $hook_data_variable['hook_entity_insert']['api_calls']['flag_get_flag_counts']; |
|
1274 |
$this->assertEqual($flag_get_flag_counts, 1, "hook_entity_insert() gets a correct flag count from flag_get_flag_counts()."); |
|
1275 |
|
|
1276 |
$flag_get_entity_flag_counts = $hook_data_variable['hook_entity_insert']['api_calls']['flag_get_entity_flag_counts']; |
|
1277 |
$this->assertEqual($flag_get_entity_flag_counts, 1, "hook_entity_insert() gets a correct flag count from flag_get_entity_flag_counts()."); |
|
1278 |
|
|
1279 |
$flag_get_user_flag_counts = $hook_data_variable['hook_entity_insert']['api_calls']['flag_get_user_flag_counts']; |
|
1280 |
$this->assertEqual($flag_get_user_flag_counts, 1, "hook_entity_insert() gets a correct flag count from flag_get_user_flag_counts()."); |
|
1281 |
|
|
1282 |
// Check the parameters received by hook_flag_flag(). |
|
1283 |
// Param 0: $flag. |
|
1284 |
$this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][0], $flag, "The flag object is passed to hook_flag_flag()."); |
|
1285 |
// Param 1: $entity_id. |
|
1286 |
$this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][1], $node->nid, "The entity ID is passed to hook_flag_flag()."); |
|
1287 |
// Param 2: $account. |
|
1288 |
$this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][2]->uid, $this->flag_unflag_user->uid, "The user account is passed to hook_flag_flag()."); |
|
1289 |
// Param 3: $flagging. |
|
1290 |
// See https://drupal.org/node/2196055. |
|
1291 |
$this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->flag_name, $flag->name, "The Flagging entity passed to hook_flag_flag() has the expected flag name property."); |
|
1292 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][3]->fid, $flag->fid); |
|
1293 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][3]->entity_type, 'node'); |
|
1294 |
$this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->entity_id, $node->nid, "The Flagging entity passed to hook_flag_flag() has the expected entity ID property."); |
|
1295 |
$this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_flag_flag() has the expected uid property."); |
|
1296 |
|
|
1297 |
// Check the API data available to hook_flag_flag(). |
|
1298 |
//debug($hook_data_variable['hook_flag_flag']['api_calls']); |
|
1299 |
$flag_get_entity_flags = $hook_data_variable['hook_flag_flag']['api_calls']['flag_get_entity_flags']; |
|
1300 |
$flag_get_entity_flags_uids = array_keys($flag_get_entity_flags); |
|
1301 |
$this->assertEqual($flag_get_entity_flags_uids, array($this->flag_unflag_user->uid), "hook_flag_flag() gets correct data for flagging users from flag_get_entity_flags()"); |
|
1302 |
$flag_get_entity_flags_flagging = $flag_get_entity_flags[$this->flag_unflag_user->uid]; |
|
1303 |
$this->assertEqual($flag_get_entity_flags_flagging->fid, $flag->fid, "hook_flag_flag() gets a correct fid on the Flagging obtained from flag_get_entity_flags()"); |
|
1304 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_type, 'node', "hook_flag_flag() gets a correct entity type on the Flagging obtained from flag_get_entity_flags()"); |
|
1305 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_id, $node->nid, "hook_flag_flag() gets a correct entity ID on the Flagging obtained from flag_get_entity_flags()"); |
|
1306 |
|
|
1307 |
$flag_get_user_flags = $hook_data_variable['hook_flag_flag']['api_calls']['flag_get_user_flags']; |
|
1308 |
$flag_get_user_flags_flagging = $flag_get_user_flags[$flag->name]; |
|
1309 |
$this->assertEqual($flag_get_user_flags_flagging->fid, $flag->fid, "hook_flag_flag() gets a correct fid on the Flagging obtained from flag_get_user_flags()"); |
|
1310 |
$this->assertEqual($flag_get_user_flags_flagging->entity_type, 'node', "hook_flag_flag() gets a correct entity type on the Flagging obtained from flag_get_user_flags()"); |
|
1311 |
$this->assertEqual($flag_get_user_flags_flagging->entity_id, $node->nid, "hook_flag_flag() gets a correct entity ID on the Flagging obtained from flag_get_user_flags()"); |
|
1312 |
|
|
1313 |
// The flag counts have been increased. |
|
1314 |
$flag_get_counts = $hook_data_variable['hook_flag_flag']['api_calls']['flag_get_counts']; |
|
1315 |
$this->assertEqual($flag_get_counts[$flag->name], 1, "hook_flag_flag() gets a correct flag count from flag_get_counts()."); |
|
1316 |
|
|
1317 |
$flag_get_flag_counts = $hook_data_variable['hook_flag_flag']['api_calls']['flag_get_flag_counts']; |
|
1318 |
$this->assertEqual($flag_get_flag_counts, 1, "hook_flag_flag() gets a correct flag count from flag_get_flag_counts()."); |
|
1319 |
|
|
1320 |
$flag_get_entity_flag_counts = $hook_data_variable['hook_flag_flag']['api_calls']['flag_get_entity_flag_counts']; |
|
1321 |
$this->assertEqual($flag_get_entity_flag_counts, 1, "hook_flag_flag() gets a correct flag count from flag_get_entity_flag_counts()."); |
|
1322 |
|
|
1323 |
$flag_get_user_flag_counts = $hook_data_variable['hook_flag_flag']['api_calls']['flag_get_user_flag_counts']; |
|
1324 |
$this->assertEqual($flag_get_user_flag_counts, 1, "hook_flag_flag() gets a correct flag count from flag_get_user_flag_counts()."); |
|
1325 |
|
|
1326 |
// Clear the tracking variable. |
|
1327 |
variable_set('flag_hook_test_hook_tracking', array()); |
|
1328 |
|
|
1329 |
// Get the Flagging, and re-flag the node. |
|
1330 |
// This does nothing in our case, but is the API for updating a Flagging |
|
1331 |
// entity with changes to its Field API fields. |
|
1332 |
// Query the database to get the Flagging ID rather than Flag API so we |
|
1333 |
// don't interefere with any caches. |
|
1334 |
$query = db_select('flagging', 'f'); |
|
1335 |
$query->addField('f', 'flagging_id'); |
|
1336 |
$query->condition('fid', $flag->fid) |
|
1337 |
->condition('entity_id', $node->nid); |
|
1338 |
$flagging_id = $query |
|
1339 |
->execute() |
|
1340 |
->fetchField(); |
|
1341 |
$flagging = flagging_load($flagging_id); |
|
1342 |
|
|
1343 |
// Re-flag the node passing in the flagging entity. |
|
1344 |
$flag->flag('flag', $node->nid, $this->flag_unflag_user, FALSE, $flagging); |
|
1345 |
|
|
1346 |
// Get the variable the test module sets the hook order into. |
|
1347 |
$hook_data_variable = variable_get('flag_hook_test_hook_tracking', array()); |
|
1348 |
//debug($hook_data_variable); |
|
1349 |
|
|
1350 |
$expected_hook_order = array( |
|
1351 |
'hook_entity_presave', |
|
1352 |
'hook_entity_update', |
|
1353 |
// Note that hook_flag() and the rule are not invoked, as this is not a |
|
1354 |
// new act of flagging. |
|
1355 |
); |
|
1356 |
|
|
1357 |
// Check the hooks are invoked in the correct order. |
|
1358 |
$this->assertIdentical($expected_hook_order, array_keys($hook_data_variable), "The hooks are invoked in the correct order when re-flagging a node."); |
|
1359 |
|
|
1360 |
// Check the parameters received by hook_entity_presave(). |
|
1361 |
// Param 0: $flagging. |
|
1362 |
// There is a bug with what is passed to entity hooks; for now, just check |
|
1363 |
// the things that do get passed. |
|
1364 |
// See https://drupal.org/node/2196055. |
|
1365 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_presave() has the expected flag name property."); |
|
1366 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid); |
|
1367 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node'); |
|
1368 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_presave() has the expected entity ID property."); |
|
1369 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_presave() has the expected uid property."); |
|
1370 |
// Param 1: $entity_type. |
|
1371 |
$this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][1], 'flagging', "hook_entity_presave() is passed the correct entity type."); |
|
1372 |
|
|
1373 |
// Check the API data available to hook_entity_presave(). |
|
1374 |
//debug($hook_data_variable['hook_entity_presave']['api_calls']); |
|
1375 |
$flag_get_entity_flags = $hook_data_variable['hook_entity_presave']['api_calls']['flag_get_entity_flags']; |
|
1376 |
$flag_get_entity_flags_uids = array_keys($flag_get_entity_flags); |
|
1377 |
$this->assertEqual($flag_get_entity_flags_uids, array($this->flag_unflag_user->uid), "hook_entity_presave() gets correct data for flagging users from flag_get_entity_flags()"); |
|
1378 |
$flag_get_entity_flags_flagging = $flag_get_entity_flags[$this->flag_unflag_user->uid]; |
|
1379 |
$this->assertEqual($flag_get_entity_flags_flagging->fid, $flag->fid, "hook_entity_presave() gets a correct fid on the Flagging obtained from flag_get_entity_flags()"); |
|
1380 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_type, 'node', "hook_entity_presave() gets a correct entity type on the Flagging obtained from flag_get_entity_flags()"); |
|
1381 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_id, $node->nid, "hook_entity_presave() gets a correct entity ID on the Flagging obtained from flag_get_entity_flags()"); |
|
1382 |
|
|
1383 |
$flag_get_user_flags = $hook_data_variable['hook_entity_presave']['api_calls']['flag_get_user_flags']; |
|
1384 |
$flag_get_user_flags_flagging = $flag_get_user_flags[$flag->name]; |
|
1385 |
$this->assertEqual($flag_get_user_flags_flagging->fid, $flag->fid, "hook_entity_presave() gets a correct fid on the Flagging obtained from flag_get_user_flags()"); |
|
1386 |
$this->assertEqual($flag_get_user_flags_flagging->entity_type, 'node', "hook_entity_presave() gets a correct entity type on the Flagging obtained from flag_get_user_flags()"); |
|
1387 |
$this->assertEqual($flag_get_user_flags_flagging->entity_id, $node->nid, "hook_entity_presave() gets a correct entity ID on the Flagging obtained from flag_get_user_flags()"); |
|
1388 |
|
|
1389 |
// The flag counts have not changed. |
|
1390 |
$flag_get_counts = $hook_data_variable['hook_entity_presave']['api_calls']['flag_get_counts']; |
|
1391 |
$this->assertEqual($flag_get_counts[$flag->name], 1, "hook_entity_presave() gets a correct flag count from flag_get_counts()."); |
|
1392 |
|
|
1393 |
$flag_get_flag_counts = $hook_data_variable['hook_entity_presave']['api_calls']['flag_get_flag_counts']; |
|
1394 |
$this->assertEqual($flag_get_flag_counts, 1, "hook_entity_presave() gets a correct flag count from flag_get_flag_counts()."); |
|
1395 |
|
|
1396 |
$flag_get_entity_flag_counts = $hook_data_variable['hook_entity_presave']['api_calls']['flag_get_entity_flag_counts']; |
|
1397 |
$this->assertEqual($flag_get_entity_flag_counts, 1, "hook_entity_presave() gets a correct flag count from flag_get_entity_flag_counts()."); |
|
1398 |
|
|
1399 |
$flag_get_user_flag_counts = $hook_data_variable['hook_entity_presave']['api_calls']['flag_get_user_flag_counts']; |
|
1400 |
$this->assertEqual($flag_get_user_flag_counts, 1, "hook_entity_presave() gets a correct flag count from flag_get_user_flag_counts()."); |
|
1401 |
|
|
1402 |
// Check the parameters received by hook_entity_update(). |
|
1403 |
// Param 0: $flagging. |
|
1404 |
// See https://drupal.org/node/2196055. |
|
1405 |
$this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_update() has the expected flag name property."); |
|
1406 |
//$this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->fid, $flag->fid); |
|
1407 |
//$this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->entity_type, 'node'); |
|
1408 |
$this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_update() has the expected entity ID property."); |
|
1409 |
$this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_update() has the expected uid property."); |
|
1410 |
$this->assertTrue(!empty($hook_data_variable['hook_entity_update']['parameters'][0]->flagging_id), "The Flagging entity passed to hook_entity_update() has the flagging ID set."); |
|
1411 |
// Param 1: $entity_type. |
|
1412 |
$this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][1], 'flagging', "hook_entity_update() is passed the correct entity type."); |
|
1413 |
|
|
1414 |
// Check the API data available to hook_entity_update(). |
|
1415 |
//debug($hook_data_variable['hook_entity_update']['api_calls']); |
|
1416 |
$flag_get_entity_flags = $hook_data_variable['hook_entity_update']['api_calls']['flag_get_entity_flags']; |
|
1417 |
$flag_get_entity_flags_uids = array_keys($flag_get_entity_flags); |
|
1418 |
$this->assertEqual($flag_get_entity_flags_uids, array($this->flag_unflag_user->uid), "hook_entity_update() gets correct data for flagging users from flag_get_entity_flags()"); |
|
1419 |
$flag_get_entity_flags_flagging = $flag_get_entity_flags[$this->flag_unflag_user->uid]; |
|
1420 |
$this->assertEqual($flag_get_entity_flags_flagging->fid, $flag->fid, "hook_entity_update() gets a correct fid on the Flagging obtained from flag_get_entity_flags()"); |
|
1421 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_type, 'node', "hook_entity_update() gets a correct entity type on the Flagging obtained from flag_get_entity_flags()"); |
|
1422 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_id, $node->nid, "hook_entity_update() gets a correct entity ID on the Flagging obtained from flag_get_entity_flags()"); |
|
1423 |
|
|
1424 |
$flag_get_user_flags = $hook_data_variable['hook_entity_update']['api_calls']['flag_get_user_flags']; |
|
1425 |
$flag_get_user_flags_flagging = $flag_get_user_flags[$flag->name]; |
|
1426 |
$this->assertEqual($flag_get_user_flags_flagging->fid, $flag->fid, "hook_entity_update() gets a correct fid on the Flagging obtained from flag_get_user_flags()"); |
|
1427 |
$this->assertEqual($flag_get_user_flags_flagging->entity_type, 'node', "hook_entity_update() gets a correct entity type on the Flagging obtained from flag_get_user_flags()"); |
|
1428 |
$this->assertEqual($flag_get_user_flags_flagging->entity_id, $node->nid, "hook_entity_update() gets a correct entity ID on the Flagging obtained from flag_get_user_flags()"); |
|
1429 |
|
|
1430 |
// The flag counts have not changed. |
|
1431 |
$flag_get_counts = $hook_data_variable['hook_entity_update']['api_calls']['flag_get_counts']; |
|
1432 |
$this->assertEqual($flag_get_counts[$flag->name], 1, "hook_entity_update() gets a correct flag count from flag_get_counts()."); |
|
1433 |
|
|
1434 |
$flag_get_flag_counts = $hook_data_variable['hook_entity_update']['api_calls']['flag_get_flag_counts']; |
|
1435 |
$this->assertEqual($flag_get_flag_counts, 1, "hook_entity_update() gets a correct flag count from flag_get_flag_counts()."); |
|
1436 |
|
|
1437 |
$flag_get_entity_flag_counts = $hook_data_variable['hook_entity_update']['api_calls']['flag_get_entity_flag_counts']; |
|
1438 |
$this->assertEqual($flag_get_entity_flag_counts, 1, "hook_entity_update() gets a correct flag count from flag_get_entity_flag_counts()."); |
|
1439 |
|
|
1440 |
$flag_get_user_flag_counts = $hook_data_variable['hook_entity_update']['api_calls']['flag_get_user_flag_counts']; |
|
1441 |
$this->assertEqual($flag_get_user_flag_counts, 1, "hook_entity_update() gets a correct flag count from flag_get_user_flag_counts()."); |
|
1442 |
|
|
1443 |
// Clear the tracking variable. |
|
1444 |
variable_set('flag_hook_test_hook_tracking', array()); |
|
1445 |
|
|
1446 |
// Unflag the node as the user. |
|
1447 |
$flag->flag('unflag', $node->nid, $this->flag_unflag_user); |
|
1448 |
|
|
1449 |
// Get the variable the test module sets the hook order into. |
|
1450 |
$hook_data_variable = variable_get('flag_hook_test_hook_tracking', array()); |
|
1451 |
//debug($hook_data_variable); |
|
1452 |
|
|
1453 |
$expected_hook_order = array( |
|
1454 |
'hook_flag_unflag', |
|
1455 |
'rules_event', |
|
1456 |
'hook_entity_delete', |
|
1457 |
); |
|
1458 |
|
|
1459 |
// Check the hooks are invoked in the correct order. |
|
1460 |
$this->assertIdentical($expected_hook_order, array_keys($hook_data_variable), "The hooks are invoked in the correct order when unflagging a node."); |
|
1461 |
|
|
1462 |
// Check the parameters received by hook_flag_unflag(). |
|
1463 |
// Param 0: $flag. |
|
1464 |
$this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][0], $flag, "The flag object is passed to hook_flag_unflag()."); |
|
1465 |
// Param 1: $entity_id. |
|
1466 |
$this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][1], $node->nid, "The entity ID is passed to hook_flag_unflag()."); |
|
1467 |
// Param 2: $account. |
|
1468 |
$this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][2]->uid, $this->flag_unflag_user->uid, "The user account is passed to hook_flag_unflag()."); |
|
1469 |
// Param 3: $flagging. |
|
1470 |
// See https://drupal.org/node/2196055. |
|
1471 |
$this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->flag_name, $flag->name, "The Flagging entity passed to hook_flag_unflag() has the expected flag name property."); |
|
1472 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][3]->fid, $flag->fid); |
|
1473 |
//$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][3]->entity_type, 'node'); |
|
1474 |
$this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->entity_id, $node->nid, "The Flagging entity passed to hook_flag_unflag() has the expected entity ID property."); |
|
1475 |
$this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_flag_unflag() has the expected uid property."); |
|
1476 |
|
|
1477 |
// Check the API data available to hook_flag_unflag(). |
|
1478 |
//debug($hook_data_variable['hook_flag_unflag']['api_calls']); |
|
1479 |
// The unflagging is not yet done, so flag_get_entity_flags() will find the |
|
1480 |
// flagging data. |
|
1481 |
$flag_get_entity_flags = $hook_data_variable['hook_flag_unflag']['api_calls']['flag_get_entity_flags']; |
|
1482 |
$flag_get_entity_flags_uids = array_keys($flag_get_entity_flags); |
|
1483 |
$this->assertEqual($flag_get_entity_flags_uids, array($this->flag_unflag_user->uid), "hook_flag_unflag() gets correct data for flagging users from flag_get_entity_flags()"); |
|
1484 |
$flag_get_entity_flags_flagging = $flag_get_entity_flags[$this->flag_unflag_user->uid]; |
|
1485 |
$this->assertEqual($flag_get_entity_flags_flagging->fid, $flag->fid, "hook_flag_unflag() gets a correct fid on the Flagging obtained from flag_get_entity_flags(): the Flagging has not yet been deleted."); |
|
1486 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_type, 'node', "hook_flag_unflag() gets a correct entity type on the Flagging obtained from flag_get_entity_flags()"); |
|
1487 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_id, $node->nid, "hook_flag_unflag() gets a correct entity ID on the Flagging obtained from flag_get_entity_flags()"); |
|
1488 |
|
|
1489 |
$flag_get_user_flags = $hook_data_variable['hook_flag_unflag']['api_calls']['flag_get_user_flags']; |
|
1490 |
$flag_get_user_flags_flagging = $flag_get_user_flags[$flag->name]; |
|
1491 |
$this->assertEqual($flag_get_user_flags_flagging->fid, $flag->fid, "hook_flag_unflag() gets a correct fid on the Flagging obtained from flag_get_user_flags()"); |
|
1492 |
$this->assertEqual($flag_get_user_flags_flagging->entity_type, 'node', "hook_flag_unflag() gets a correct entity type on the Flagging obtained from flag_get_user_flags()"); |
|
1493 |
$this->assertEqual($flag_get_user_flags_flagging->entity_id, $node->nid, "hook_flag_unflag() gets a correct entity ID on the Flagging obtained from flag_get_user_flags()"); |
|
1494 |
|
|
1495 |
// The flag counts have already been decreased. |
|
1496 |
$flag_get_counts = $hook_data_variable['hook_flag_unflag']['api_calls']['flag_get_counts']; |
|
1497 |
$this->assertEqual($flag_get_counts, array(), "hook_flag_unflag() gets a correct flag count from flag_get_counts()."); |
|
1498 |
|
|
1499 |
$flag_get_flag_counts = $hook_data_variable['hook_flag_unflag']['api_calls']['flag_get_flag_counts']; |
|
1500 |
$this->assertEqual($flag_get_flag_counts, 0, "hook_flag_unflag() gets a correct flag count from flag_get_flag_counts()."); |
|
1501 |
|
|
1502 |
// flag_get_entity_flag_counts() queries the {flagging} table, so is not |
|
1503 |
// updated yet. |
|
1504 |
$flag_get_entity_flag_counts = $hook_data_variable['hook_flag_unflag']['api_calls']['flag_get_entity_flag_counts']; |
|
1505 |
$this->assertEqual($flag_get_entity_flag_counts, 1, "hook_flag_unflag() gets a correct flag count from flag_get_entity_flag_counts()."); |
|
1506 |
|
|
1507 |
// flag_get_user_flag_counts() queries the {flagging} table, so is not |
|
1508 |
// updated yet. |
|
1509 |
$flag_get_user_flag_counts = $hook_data_variable['hook_flag_unflag']['api_calls']['flag_get_user_flag_counts']; |
|
1510 |
$this->assertEqual($flag_get_user_flag_counts, 1, "hook_flag_unflag() gets a correct flag count from flag_get_user_flag_counts()."); |
|
1511 |
|
|
1512 |
// Check the parameters received by hook_entity_delete(). |
|
1513 |
// Param 0: $flagging. |
|
1514 |
// See https://drupal.org/node/2196055. |
|
1515 |
$this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_delete() has the expected flag name property."); |
|
1516 |
//$this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->fid, $flag->fid); |
|
1517 |
//$this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->entity_type, 'node'); |
|
1518 |
$this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_delete() has the expected entity ID property."); |
|
1519 |
$this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_delete() has the expected uid property."); |
|
1520 |
$this->assertTrue(!empty($hook_data_variable['hook_entity_delete']['parameters'][0]->flagging_id), "The Flagging entity passed to hook_entity_delete() has the flagging ID set."); |
|
1521 |
// Param 1: $entity_type. |
|
1522 |
$this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][1], 'flagging', "hook_entity_delete() is passed the correct entity type."); |
|
1523 |
|
|
1524 |
// Check the API data available to hook_entity_delete(). |
|
1525 |
//debug($hook_data_variable['hook_entity_delete']['api_calls']); |
|
1526 |
// The unflagging is not yet done, so hook_entity_delete() will find the |
|
1527 |
// flagging data. |
|
1528 |
$flag_get_entity_flags = $hook_data_variable['hook_entity_delete']['api_calls']['flag_get_entity_flags']; |
|
1529 |
$flag_get_entity_flags_uids = array_keys($flag_get_entity_flags); |
|
1530 |
$this->assertEqual($flag_get_entity_flags_uids, array($this->flag_unflag_user->uid), "hook_entity_delete() gets correct data for flagging users from flag_get_entity_flags()"); |
|
1531 |
$flag_get_entity_flags_flagging = $flag_get_entity_flags[$this->flag_unflag_user->uid]; |
|
1532 |
$this->assertEqual($flag_get_entity_flags_flagging->fid, $flag->fid, "hook_entity_delete() gets a correct fid on the Flagging obtained from flag_get_entity_flags()"); |
|
1533 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_type, 'node', "hook_entity_delete() gets a correct entity type on the Flagging obtained from flag_get_entity_flags()"); |
|
1534 |
$this->assertEqual($flag_get_entity_flags_flagging->entity_id, $node->nid, "hook_entity_delete() gets a correct entity ID on the Flagging obtained from flag_get_entity_flags()"); |
|
1535 |
|
|
1536 |
$flag_get_user_flags = $hook_data_variable['hook_entity_delete']['api_calls']['flag_get_user_flags']; |
|
1537 |
$flag_get_user_flags_flagging = $flag_get_user_flags[$flag->name]; |
|
1538 |
$this->assertEqual($flag_get_user_flags_flagging->fid, $flag->fid, "hook_entity_delete() gets a correct fid on the Flagging obtained from flag_get_user_flags()"); |
|
1539 |
$this->assertEqual($flag_get_user_flags_flagging->entity_type, 'node', "hook_entity_delete() gets a correct entity type on the Flagging obtained from flag_get_user_flags()"); |
|
1540 |
$this->assertEqual($flag_get_user_flags_flagging->entity_id, $node->nid, "hook_entity_delete() gets a correct entity ID on the Flagging obtained from flag_get_user_flags()"); |
|
1541 |
|
|
1542 |
// The flag counts have already been decreased. |
|
1543 |
$flag_get_counts = $hook_data_variable['hook_entity_delete']['api_calls']['flag_get_counts']; |
|
1544 |
$this->assertEqual($flag_get_counts, array(), "hook_entity_delete() gets a correct flag count from flag_get_counts()."); |
|
1545 |
|
|
1546 |
$flag_get_flag_counts = $hook_data_variable['hook_entity_delete']['api_calls']['flag_get_flag_counts']; |
|
1547 |
$this->assertEqual($flag_get_flag_counts, 0, "hook_entity_delete() gets a correct flag count from flag_get_flag_counts()."); |
|
1548 |
|
|
1549 |
// flag_get_entity_flag_counts() queries the {flagging} table, so is not |
|
1550 |
// updated yet. |
|
1551 |
$flag_get_entity_flag_counts = $hook_data_variable['hook_entity_delete']['api_calls']['flag_get_entity_flag_counts']; |
|
1552 |
$this->assertEqual($flag_get_entity_flag_counts, 1, "hook_entity_delete() gets a correct flag count from flag_get_entity_flag_counts()."); |
|
1553 |
|
|
1554 |
// flag_get_user_flag_counts() queries the {flagging} table, so is not |
|
1555 |
// updated yet. |
|
1556 |
$flag_get_user_flag_counts = $hook_data_variable['hook_entity_delete']['api_calls']['flag_get_user_flag_counts']; |
|
1557 |
$this->assertEqual($flag_get_user_flag_counts, 1, "hook_entity_delete() gets a correct flag count from flag_get_user_flag_counts()."); |
|
1558 |
} |
|
1559 |
|
|
1560 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules