Unverified Commit c3a9311a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3113989 by acbramley, mohit_aghera, maskedjellybean, scott_euser,...

Issue #3113989 by acbramley, mohit_aghera, maskedjellybean, scott_euser, yogeshmpawar, lendude, ranjith_kumar_k_u, ameymudras, kristen pol, rahul b, larowlan, quietone, dww, alexpott, daffie: Media author views filter should use the user_name plugin

(cherry picked from commit 68013115)
parent 41281d7c
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -20,3 +20,10 @@ function media_removed_post_updates(): array {
    'media_post_update_remove_mappings_targeting_source_field' => '11.0.0',
  ];
}

/**
 * Empty update function to clear the Views data cache.
 */
function media_post_update_media_author_views_filter_update(): void {
  // Empty update function to clear the Views data cache.
}
+6 −0
Original line number Diff line number Diff line
@@ -18,6 +18,12 @@ public function getViewsData() {
    $data['media_field_data']['table']['wizard_id'] = 'media';
    $data['media_field_revision']['table']['wizard_id'] = 'media_revision';

    $data['media_field_data']['user_name']['filter'] = $data['media_field_data']['uid']['filter'];
    $data['media_field_data']['user_name']['filter']['title'] = $this->t('Authored by');
    $data['media_field_data']['user_name']['filter']['help'] = $this->t('The username of the content author.');
    $data['media_field_data']['user_name']['filter']['id'] = 'user_name';
    $data['media_field_data']['user_name']['filter']['real field'] = 'uid';

    $data['media_field_data']['status_extra'] = [
      'title' => $this->t('Published status or admin user'),
      'help' => $this->t('Filters out unpublished media if the current user cannot view it.'),
+58 −0
Original line number Diff line number Diff line
@@ -236,4 +236,62 @@ public function testImageAltTextDisplay(): void {

  }

  /**
   * Tests the author views filter uses the user_name plugin.
   */
  public function testMediaOverviewAuthorFilter(): void {
    $this->drupalLogin($this->adminUser);
    // Create some content for the view.
    $media_type1 = $this->createMediaType('test');
    $media1 = Media::create([
      'bundle' => $media_type1->id(),
      'name' => 'Media 1',
      'uid' => $this->adminUser->id(),
    ]);
    $media1->save();
    $media2 = Media::create([
      'bundle' => $media_type1->id(),
      'name' => 'Media 2',
      'uid' => $this->adminUser->id(),
    ]);
    $media2->save();
    $media3 = Media::create([
      'bundle' => $media_type1->id(),
      'name' => 'Media 3',
      'uid' => $this->nonAdminUser->id(),
    ]);
    $media3->save();

    // Add the media author filter to the media overview view.
    $this->drupalGet('admin/structure/views/nojs/add-handler/media/media_page_list/filter');
    $edit = [
      'name[media_field_data.user_name]' => 1,
    ];
    $this->submitForm($edit, 'Add and configure filter criteria');

    $edit = [
      'options[expose_button][checkbox][checkbox]' => 1,
    ];
    $this->submitForm($edit, 'Expose filter');
    $edit = [
      'options[expose_button][checkbox][checkbox]' => 1,
      'options[group_button][radios][radios]' => 0,
    ];
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');

    $role = Role::load(RoleInterface::AUTHENTICATED_ID);
    $this->grantPermissions($role, ['access media overview']);
    $this->drupalGet('/admin/content/media');
    $this->assertSession()->statusCodeEquals(200);
    // Assert we are using the user_name filter.
    $this->assertSession()->pageTextContains('Authored by');
    $this->submitForm([
      'user_name' => $this->adminUser->getAccountName() . ' (' . $this->adminUser->id() . ')',
    ], 'Filter');
    $this->assertSession()->linkByHrefExists('/media/' . $media1->id());
    $this->assertSession()->linkByHrefExists('/media/' . $media2->id());
    $this->assertSession()->linkByHrefNotExists('/media/' . $media3->id());
  }

}