ModifiedFilesTest.php in Automatic Updates 8
File
tests/src/Build/ModifiedFilesTest.php
View source
<?php
namespace Drupal\Tests\automatic_updates\Build;
use Drupal\Tests\automatic_updates\Build\QuickStart\QuickStartTestBase;
use Drupal\Tests\automatic_updates\Traits\InstallTestTrait;
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
class ModifiedFilesTest extends QuickStartTestBase {
use InstallTestTrait;
protected $symfonyFileSystem;
protected function setUp() {
parent::setUp();
$this->symfonyFileSystem = new SymfonyFilesystem();
}
public function testCoreModified($version, array $modifications = []) {
$this
->installCore($version);
$this
->assertModifications('core', 'drupal', $modifications);
}
public function testContribModified($project, $project_type, $version, array $modifications = []) {
$this
->markTestSkipped('Contrib updates are not currently supported');
$this
->copyCodebase();
$this->symfonyFileSystem
->mkdir($this
->getWorkspaceDirectory() . "/{$project_type}s/contrib/{$project}");
$this
->executeCommand("curl -fsSL https://ftp.drupal.org/files/projects/{$project}-{$version}.tar.gz | tar xvz -C {$project_type}s/contrib/{$project} --strip 1");
$this
->assertCommandSuccessful();
$this
->assertModifications($project_type, $project, $modifications);
}
public function coreProjectProvider() {
$datum[] = [
'version' => '8.7.3',
'modifications' => [
'core/LICENSE.txt',
],
];
return $datum;
}
public function contribProjectsProvider() {
$datum[] = [
'project' => 'bootstrap',
'project_type' => 'theme',
'version' => '8.x-3.20',
'modifications' => [
'themes/contrib/bootstrap/LICENSE.txt',
],
];
$datum[] = [
'project' => 'token',
'project_type' => 'module',
'version' => '8.x-1.5',
'modifications' => [
'modules/contrib/token/LICENSE.txt',
],
];
return $datum;
}
protected function assertModifications($project_type, $project, array $modifications) {
$this
->visit("/automatic_updates/modified-files/{$project_type}/{$project}");
$assert = $this
->getMink()
->assertSession();
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('No modified files!');
$this
->assertNotEmpty($modifications);
foreach ($modifications as $modification) {
$file = $this
->getWorkspaceDirectory() . DIRECTORY_SEPARATOR . $modification;
$this
->fileExists($file);
$this->symfonyFileSystem
->appendToFile($file, PHP_EOL . '// file is modified' . PHP_EOL);
}
$this
->visit("/automatic_updates/modified-files/{$project_type}/{$project}");
$assert
->pageTextContains('Modified files include:');
foreach ($modifications as $modification) {
$assert
->pageTextContains($modification);
}
}
}