Issue #2889438 by chr.fritsch, seanB, marcoscano, Wim Leers, rogerpfaff, phenaproxima, larowlan: Delete media delivered icons on uninstall

8.4.x
Gabor Hojtsy 2017-07-20 15:46:26 +02:00
parent 337963d193
commit e018da5082
2 changed files with 52 additions and 1 deletions

View File

@ -17,8 +17,16 @@ function media_install() {
$files = file_scan_directory($source, '/.*\.(svg|png|jpg|jpeg|gif)$/');
foreach ($files as $file) {
// When reinstalling the media module we don't want to copy the icons when
// they already exist. The icons could be replaced (by a contrib module or
// manually), so we don't want to replace the existing files. Removing the
// files when we uninstall could also be a problem if the files are
// referenced somewhere else. Since showing an error that it was not
// possible to copy the files is also confusing, we silently do nothing.
if (!file_exists($destination . DIRECTORY_SEPARATOR . $file->filename)) {
file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR);
}
}
// Grant the "view media" permission to all users by default.
if (\Drupal::moduleHandler()->moduleExists('user')) {

View File

@ -0,0 +1,43 @@
<?php
namespace Drupal\Tests\media\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests media Install / Uninstall logic.
*
* @group media
*/
class MediaInstallTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['media'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer modules']));
}
/**
* Tests reinstalling after being uninstalled.
*/
public function testReinstallAfterUninstall() {
$page = $this->getSession()->getPage();
$this->container->get('module_installer')->uninstall(['media'], FALSE);
$this->drupalGet('/admin/modules');
$page->checkField('modules[media][enable]');
$page->pressButton('Install');
// @todo Remove this if-statement in https://www.drupal.org/node/2895059
if ($page->find('css', 'h1')->getText() == 'Are you sure you wish to enable experimental modules?') {
$page->pressButton('Continue');
}
$this->assertSession()->pageTextNotContains('could not be moved/copied because a file by that name already exists in the destination directory');
}
}