Projet

Général

Profil

Révision 76e2e7c3

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/flag/tests/flag.test
43 43
   */
44 44
  public static function getInfo() {
45 45
    return array(
46
      'name' => 'Flagging CRUD',
46
      'name' => 'CRUD API',
47 47
      'description' => 'Basic CRUD operations on flagging entities.',
48 48
      'group' => 'Flag',
49 49
    );
......
216 216
 * Test Flag admin UI.
217 217
 */
218 218
class FlagAdminTestCase extends FlagTestCaseBase {
219
  var $_flag = FALSE;
219
  public $_flag = FALSE;
220 220

  
221 221
  /**
222 222
   * Implements getInfo().
223 223
   */
224 224
  public static function getInfo() {
225 225
    return array(
226
      'name' => 'Flag admin tests',
226
      'name' => 'Admin UI',
227 227
      'description' => 'Add, edit and delete flags.',
228 228
      'group' => 'Flag',
229 229
    );
......
235 235
  function setUp() {
236 236
    parent::setUp('flag');
237 237

  
238
    // Create and login user
238
    // Create and login user.
239 239
    $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer flags'));
240 240
    $this->drupalLogin($admin_user);
241 241
  }
......
277 277
    $saved = $edit;
278 278
    $saved['roles'] = array('flag' => array(2), 'unflag' => array(2));
279 279
    $saved['types'] = array('page');
280
    $saved['show_in_links'] = array('full' => 0, 'teaser' => 0, 'rss' => 0, 'search_index' => 0, 'search_result' => 0);
280
    $saved['show_in_links'] = array(
281
      'full' => 0,
282
      'teaser' => 0,
283
      'rss' => 0,
284
      'search_index' => 0,
285
      'search_result' => 0,
286
    );
281 287
    unset($saved['roles[flag][2]'], $saved['roles[unflag][2]'], $saved['types[article]'], $saved['types[page]'], $saved['show_in_links[full]'], $saved['show_in_links[teaser]'], $saved['show_in_links[rss]'], $saved['show_in_links[search_index]'], $saved['show_in_links[search_result]']);
282 288

  
283 289
    $this->drupalPost(FLAG_ADMIN_PATH . '/add/node', $edit, t('Save flag'));
......
299 305
    $permissions = user_role_permissions(user_roles());
300 306
    foreach ($saved['roles'] as $action => $rids) {
301 307
      foreach ($rids as $rid) {
302
        $permission_string = "$action ". $saved['name'];
308
        $permission_string = "$action " . $saved['name'];
303 309
        $this->assertTrue(isset($permissions[$rid][$permission_string]), t('Permission %perm set for flag.', array(
304 310
          '%perm' => $permission_string,
305 311
        )));
......
331 337
    $saved = $edit;
332 338
    $saved['roles'] = array('flag' => array(2), 'unflag' => array(2));
333 339
    $saved['types'] = array('article');
334
    $saved['show_in_links'] = array('full' => TRUE, 'teaser' => TRUE, 'rss' => 0, 'search_index' => 0, 'search_result' => 0);
340
    $saved['show_in_links'] = array(
341
      'full' => TRUE,
342
      'teaser' => TRUE,
343
      'rss' => 0,
344
      'search_index' => 0,
345
      'search_result' => 0,
346
    );
335 347
    unset($saved['roles[flag][2]'], $saved['roles[unflag][2]'], $saved['types[article]'], $saved['types[page]'], $saved['show_in_links[full]'], $saved['show_in_links[teaser]'], $saved['show_in_links[rss]'], $saved['show_in_links[search_index]'], $saved['show_in_links[search_result]']);
336 348

  
337 349
    $this->drupalPost(FLAG_ADMIN_PATH . '/manage/' . $flag->name, $edit, t('Save flag'));
......
358 370

  
359 371
    foreach ($saved['roles'] as $action => $rids) {
360 372
      foreach ($rids as $rid) {
361
        $permission_string = "$action ". $saved['name'];
373
        $permission_string = "$action " . $saved['name'];
362 374
        $this->assertTrue(isset($permissions[$rid][$permission_string]), t('Permission %perm set for flag.', array(
363 375
          '%perm' => $permission_string,
364 376
        )));
......
385 397
   */
386 398
  public static function getInfo() {
387 399
    return array(
388
      'name' => 'Flag access: entity forms',
400
      'name' => 'Access to flags via entity forms',
389 401
      'description' => 'Access to flag and unflag entities via entity forms.',
390 402
      'group' => 'Flag',
391 403
    );
......
439 451

  
440 452
    $this->drupalGet('node/add/article');
441 453

  
442
    // Check that the flag form element cannot be seen
454
    // Check that the flag form element cannot be seen.
443 455
    $this->assertNoText('Flag this item', t('Flag form element was not found.'));
444 456

  
445 457
    // Have the user create a node.
......
481 493
   */
482 494
  public static function getInfo() {
483 495
    return array(
484
      'name' => 'Flag: Entity tokens',
496
      'name' => 'Entity tokens',
485 497
      'description' => 'Tokens for flag count on entities.',
486 498
      'group' => 'Flag',
487 499
    );
......
636 648
   */
637 649
  public static function getInfo() {
638 650
    return array(
639
      'name' => 'Flag access tests',
651
      'name' => 'Access to flags via basic link',
640 652
      'description' => 'Access to flag and unflag entities using the basic link.',
641 653
      'group' => 'Flag',
642 654
    );
......
762 774
   */
763 775
  public static function getInfo() {
764 776
    return array(
765
      'name' => 'Flag confirm link tests',
777
      'name' => 'Confirm form',
766 778
      'description' => 'Flag confirm form link type.',
767 779
      'group' => 'Flag',
768 780
    );
......
784 796
      'types' => array(
785 797
        0 => 'article',
786 798
      ),
787
      'flag_short' => 'Flag this item',
799
      'flag_short' => 'Flag <em>this</em> item',
788 800
      'flag_long' => '',
789 801
      'flag_message' => 'You have flagged this item.',
790 802
      'unflag_short' => 'Unflag this item',
......
838 850
    // Look at our node.
839 851
    $this->drupalGet('node/' . $this->nid);
840 852

  
841
    $this->assertLink($this->flag_data['flag_short'], 0, 'The flag link appears on the page');
853
    $flag_short_label = strip_tags($this->flag_data['flag_short']);
854

  
855
    $this->assertRaw($this->flag_data['flag_short'], 'The flag text, including HTML, appears on the page.');
856

  
857
    // assertLink() appears to have interesting problems dealing with an A
858
    // element which contains other tags. However, the xpath it uses appears to
859
    // be fine with being given just the portion of the link text that comes
860
    // before the interior tag.
861
    // Fortunately, there will be no other text on the page that matches 'Flag'.
862
    $this->assertLink('Flag', 0, 'The flag link appears on the page.');
842 863

  
843 864
    // Click the link to flag the node.
844
    $this->clickLink($this->flag_data['flag_short']);
865
    // clickLink() has the same problem, as it uses the same xpath expression as
866
    // assertLink().
867
    $this->clickLink('Flag');
845 868

  
846 869
    $this->assertUrl('flag/confirm/flag/test_flag/' . $this->nid, array(
847 870
      'query' => array(
......
851 874

  
852 875
    $this->assertText($this->flag_data['flag_confirmation'], 'The flag confirmation text appears as the confirmation page title.');
853 876

  
877
    $this->assertPattern('@<input [^>]* value="' . $flag_short_label . '" [^>]*>@', 'The flag text, excluding HTML, is shown in the button.');
878

  
854 879
    // Click the button to confirm the flagging.
855
    $this->drupalPost(NULL, array(), $this->flag_data['flag_short']);
880
    $this->drupalPost(NULL, array(), $flag_short_label);
856 881

  
857 882
    $this->assertText($this->flag_data['flag_message'], 'The flag message appears once the item has been flagged.');
858 883
    $this->assertLink($this->flag_data['unflag_short'], 0, 'The unflag link appears once the item has been flagged.');
......
894 919
   */
895 920
  public static function getInfo() {
896 921
    return array(
897
      'name' => 'Flag hook_flag_access() tests',
922
      'name' => 'hook_flag_access()',
898 923
      'description' => 'Checks the ability of modules to use hook_flag_access().',
899 924
      'group' => 'Flag',
900 925
    );
......
1002 1027
  }
1003 1028

  
1004 1029
  /**
1005
   * Verifies that the user sees the flag if a module returns TRUE (Allow) to override default access check.
1030
   * Verifies that the user sees the flag if a module returns TRUE (Allow) to
1031
   * override default access check.
1006 1032
   */
1007 1033
  function testFlagAccessAllowOverride() {
1008 1034
    variable_set('FlagHookFlagAccessTestCaseMode', 'allow');
......
1026 1052
  }
1027 1053

  
1028 1054
  /**
1029
   * Verifies that the user does not see the flag if a module returns FALSE (Deny).
1055
   * Verifies that the user does not see the flag if a module returns FALSE
1056
   * (Deny).
1030 1057
   */
1031 1058
  function testFlagAccessDeny() {
1032 1059
    variable_set('FlagHookFlagAccessTestCaseMode', 'deny');
......
1041 1068

  
1042 1069
}
1043 1070

  
1071
/**
1072
 * Test use of fields on flagging entities.
1073
 */
1074
class FlagFlaggingFieldTestCase extends FlagTestCaseBase {
1075

  
1076
  /**
1077
   * Implements getInfo().
1078
   */
1079
  public static function getInfo() {
1080
    return array(
1081
      'name' => 'Flagging fields',
1082
      'description' => 'Fields on Flagging entities.',
1083
      'group' => 'Flag',
1084
    );
1085
  }
1086

  
1087
  /**
1088
   * Implements setUp().
1089
   */
1090
  function setUp() {
1091
    parent::setUp('flag', 'flag_fields_test');
1092
  }
1093

  
1094
  function testFlaggingFields() {
1095
    $this->assertTrue(1);
1096

  
1097
    $flag_user = $this->drupalCreateUser(array(
1098
      'flag flag_fields_test_flag',
1099
      'unflag flag_fields_test_flag',
1100
    ));
1101
    $this->drupalLogin($flag_user);
1102

  
1103
    $node = $this->drupalCreateNode();
1104

  
1105
    $this->drupalGet('node/' . $node->nid);
1106

  
1107
    $this->clickLink('Flag with the test flag');
1108

  
1109
    // Try to fail the form validation by providing something non-numeric.
1110
    // This validation is only present in the widget validation: this is a core
1111
    // bug, but lets us test widget validation works correctly until it's fixed.
1112
    $edit = array(
1113
      'flag_fields_test_integer[und][0][value]' => 'banana',
1114
    );
1115
    $this->drupalPost(NULL, $edit, 'Flag with the test flag');
1116

  
1117
    $this->assertText("Only numbers are allowed in Test integer.", "Form validation correctly failed the input.");
1118

  
1119
    // Try to fail the form validation by a number that's out of bounds.
1120
    $edit = array(
1121
      'flag_fields_test_integer[und][0][value]' => 12,
1122
    );
1123
    $this->drupalPost(NULL, $edit, 'Flag with the test flag');
1124

  
1125
    $this->assertText("Test integer: the value may be no greater than 11.", "Form validation correctly failed the input.");
1126

  
1127
    $edit = array(
1128
      'flag_fields_test_integer[und][0][value]' => 6,
1129
    );
1130
    $this->drupalPost(NULL, $edit, 'Flag with the test flag');
1131

  
1132
    $this->assertUrl('node/' . $node->nid, array(), "The flagging form submission succeeded.");
1133

  
1134
    // Try to load the flagging, querying for the field value.
1135
    $query = new EntityFieldQuery();
1136
    $query->entityCondition('entity_type', 'flagging')
1137
      ->entityCondition('bundle', 'flag_fields_test_flag')
1138
      ->propertyCondition('entity_id', $node->nid)
1139
      ->fieldCondition('flag_fields_test_integer', 'value', 6);
1140

  
1141
    $result = $query->execute();
1142

  
1143
    $this->assertEqual(count($result['flagging']), 1, "The Flagging entity was found with the correct field values.");
1144
  }
1145

  
1146
}
1147

  
1044 1148
/**
1045 1149
 * Test use of EntityFieldQueries with flagging entities.
1046 1150
 */
......
1050 1154
   * Implements getInfo().
1051 1155
   */
1052 1156
  public static function getInfo() {
1053
     return array(
1054
      'name' => 'Flagging Entity Field Query Extension',
1157
    return array(
1158
      'name' => 'Entity Field Query',
1055 1159
      'description' => 'Entity Field Query for flagging entities.',
1056 1160
      'group' => 'Flag',
1057 1161
    );
......
1099 1203
    $this->flag3 = $this->createFlag($flag_data);
1100 1204

  
1101 1205
    // Create test user who can flag and unflag.
1102
    $this->flag_unflag_user = $this->drupalCreateUser(array('flag test_flag_1', 'unflag test_flag_1', 'flag test_flag_2', 'unflag test_flag_2'));
1206
    $this->flag_unflag_user = $this->drupalCreateUser(array(
1207
      'flag test_flag_1',
1208
      'unflag test_flag_1',
1209
      'flag test_flag_2',
1210
      'unflag test_flag_2',
1211
    ));
1103 1212
    $this->drupalLogin($this->flag_unflag_user);
1104 1213

  
1105 1214
  }
......
1108 1217
   * Test use of EntityFieldQuery with flagging entities.
1109 1218
   */
1110 1219
  function testEntityFieldQuery() {
1111
     $node_settings = array(
1220
    $node_settings = array(
1112 1221
      'title' => $this->randomName(),
1113 1222
      'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
1114 1223
      'uid' => 1,
......
1150 1259
   * Implements getInfo().
1151 1260
   */
1152 1261
  public static function getInfo() {
1153
     return array(
1154
      'name' => 'Flag hook invocations',
1262
    return array(
1263
      'name' => 'Hook invocations',
1155 1264
      'description' => 'Invocation of flag and entity hooks and rules during flagging and unflagging.',
1156 1265
      'group' => 'Flag',
1157 1266
    );
......
1217 1326

  
1218 1327
    // Check the parameters received by hook_entity_presave().
1219 1328
    // 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 1329
    $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');
1330
    $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->fid, $flag->fid, "The Flagging entity passed to hook_entity_presave() has the expected fid property.");
1331
    $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->entity_type, 'node', "The Flagging entity passed to hook_entity_presave() has the expected entity type property.");
1226 1332
    $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 1333
    $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 1334
    // Param 1: $entity_type.
......
1240 1346

  
1241 1347
    // Check the parameters received by hook_entity_insert().
1242 1348
    // Param 0: $flagging.
1243
    // See https://drupal.org/node/2196055.
1244 1349
    $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');
1350
    $this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid, "The Flagging entity passed to hook_entity_insert() has the expected fid property.");
1351
    $this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node', "The Flagging entity passed to hook_entity_insert() has the expected entity type property.");
1247 1352
    $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 1353
    $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 1354
    $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.");
......
1287 1392
    // Param 2: $account.
1288 1393
    $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 1394
    // Param 3: $flagging.
1290
    // See https://drupal.org/node/2196055.
1291 1395
    $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');
1396
    $this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->fid, $flag->fid, "The Flagging entity passed to hook_flag_flag() has the expected fid property.");
1397
    $this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->entity_type, 'node', "The Flagging entity passed to hook_flag_flag() has the expected entity type property.");
1294 1398
    $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 1399
    $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 1400

  
......
1359 1463

  
1360 1464
    // Check the parameters received by hook_entity_presave().
1361 1465
    // 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 1466
    $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 1467
    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid);
1367 1468
    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node');
......
1401 1502

  
1402 1503
    // Check the parameters received by hook_entity_update().
1403 1504
    // Param 0: $flagging.
1404
    // See https://drupal.org/node/2196055.
1405 1505
    $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');
1506
    $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->fid, $flag->fid, "The Flagging entity passed to hook_entity_presave() has the expected fid property.");
1507
    $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->entity_type, 'node', "The Flagging entity passed to hook_entity_presave() has the expected entity type property.");
1408 1508
    $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 1509
    $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 1510
    $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.");
......
1467 1567
    // Param 2: $account.
1468 1568
    $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 1569
    // Param 3: $flagging.
1470
    // See https://drupal.org/node/2196055.
1471 1570
    $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');
1571
    $this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->fid, $flag->fid, "The Flagging entity passed to hook_entity_presave() has the expected fid property.");
1572
    $this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->entity_type, 'node', "The Flagging entity passed to hook_entity_presave() has the expected entity type property.");
1474 1573
    $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 1574
    $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 1575

  
......
1511 1610

  
1512 1611
    // Check the parameters received by hook_entity_delete().
1513 1612
    // Param 0: $flagging.
1514
    // See https://drupal.org/node/2196055.
1515 1613
    $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');
1614
    $this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->fid, $flag->fid, "The Flagging entity passed to hook_entity_presave() has the expected fid property.");
1615
    $this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->entity_type, 'node', "The Flagging entity passed to hook_entity_presave() has the expected entity type property.");
1518 1616
    $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 1617
    $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 1618
    $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.");

Formats disponibles : Unified diff