protected function setUp() { parent::setUp(); $this->image = entity_create('file'); $this->image->setFileUri('core/misc/druplicon.png'); $this->image->setFilename(drupal_basename($this->image->getFileUri())); $this->nonImage = entity_create('file'); $this->nonImage->setFileUri('core/assets/vendor/jquery/jquery.min.js'); $this->nonImage->setFilename(drupal_basename($this->nonImage->getFileUri())); }
/** * Rename potentially executable files. * * @param \Drupal\file\FileInterface $file * The file entity object. * * @return bool * Whether the file was renamed or not. */ protected function renameExecutableExtensions(FileInterface $file) { if (!$this->configFactory->get('system.file')->get('allow_insecure_uploads') && preg_match('/\\.(php|pl|py|cgi|asp|js)(\\.|$)/i', $file->getFilename()) && substr($file->getFilename(), -4) != '.txt') { $file->setMimeType('text/plain'); // The destination filename will also later be used to create the URI. $file->setFilename($file->getFilename() . '.txt'); return TRUE; } return FALSE; }