You are here

class ModifiedFilesTest in Automatic Updates 8

Same name in this branch
  1. 8 tests/src/Build/ModifiedFilesTest.php \Drupal\Tests\automatic_updates\Build\ModifiedFilesTest
  2. 8 tests/src/Kernel/ReadinessChecker/ModifiedFilesTest.php \Drupal\Tests\automatic_updates\Kernel\ReadinessChecker\ModifiedFilesTest

@coversDefaultClass \Drupal\automatic_updates\Services\ModifiedFiles

@group Update

@requires externalCommand composer @requires externalCommand curl @requires externalCommand git @requires externalCommand tar

Hierarchy

Expanded class hierarchy of ModifiedFilesTest

File

tests/src/Build/ModifiedFilesTest.php, line 19

Namespace

Drupal\Tests\automatic_updates\Build
View source
class ModifiedFilesTest extends QuickStartTestBase {
  use InstallTestTrait;

  /**
   * Symfony file system.
   *
   * @var \Symfony\Component\Filesystem\Filesystem
   */
  protected $symfonyFileSystem;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->symfonyFileSystem = new SymfonyFilesystem();
  }

  /**
   * @covers ::getModifiedFiles
   * @dataProvider coreProjectProvider
   */
  public function testCoreModified($version, array $modifications = []) {
    $this
      ->installCore($version);

    // Assert modifications.
    $this
      ->assertModifications('core', 'drupal', $modifications);
  }

  /**
   * @covers ::getModifiedFiles
   * @dataProvider contribProjectsProvider
   */
  public function testContribModified($project, $project_type, $version, array $modifications = []) {
    $this
      ->markTestSkipped('Contrib updates are not currently supported');
    $this
      ->copyCodebase();

    // Download the project.
    $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();

    // Assert modifications.
    $this
      ->assertModifications($project_type, $project, $modifications);
  }

  /**
   * Core project data provider.
   */
  public function coreProjectProvider() {
    $datum[] = [
      'version' => '8.7.3',
      'modifications' => [
        'core/LICENSE.txt',
      ],
    ];
    return $datum;
  }

  /**
   * Contrib project data provider.
   */
  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;
  }

  /**
   * Assert modified files.
   *
   * @param string $project_type
   *   The project type.
   * @param string $project
   *   The project to assert.
   * @param array $modifications
   *   The modified files to assert.
   */
  protected function assertModifications($project_type, $project, array $modifications) {

    // Validate project is not modified.
    $this
      ->visit("/automatic_updates/modified-files/{$project_type}/{$project}");
    $assert = $this
      ->getMink()
      ->assertSession();
    $assert
      ->statusCodeEquals(200);
    $assert
      ->pageTextContains('No modified files!');

    // Assert modifications.
    $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);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BuildTestBase::$commandProcess private property The most recent command process.
BuildTestBase::$destroyBuild protected property Default to destroying build artifacts after a test finishes.
BuildTestBase::$hostName private static property Our native host name, used by PHP when it starts up the server.
BuildTestBase::$hostPort private property Port that will be tested.
BuildTestBase::$mink private property The Mink session manager.
BuildTestBase::$portLocks private property A list of ports used by the test.
BuildTestBase::$serverDocroot private property The docroot for the server process.
BuildTestBase::$serverProcess private property The process that's running the HTTP server.
BuildTestBase::$workspaceDir private property The working directory where this test will manipulate files.
BuildTestBase::assertCommandExitCode public function Asserts that the last command returned the specified exit code.
BuildTestBase::assertCommandOutputContains public function Assert that text is present in the output of the most recent command.
BuildTestBase::assertCommandSuccessful public function Asserts that the last command ran without error.
BuildTestBase::assertDrupalVisit public function Helper function to assert that the last visit was a Drupal site.
BuildTestBase::assertErrorOutputContains public function Assert that text is present in the error output of the most recent command.
BuildTestBase::checkPortIsAvailable protected function Checks whether a port is available.
BuildTestBase::copyCodebase public function Copy the current working codebase into a workspace.
BuildTestBase::executeCommand public function Run a command.
BuildTestBase::findAvailablePort protected function Discover an available port number.
BuildTestBase::getCodebaseFinder public function Get a default Finder object for a Drupal codebase.
BuildTestBase::getDrupalRoot protected function Get the root path of this Drupal codebase.
BuildTestBase::getMink public function Get the Mink instance.
BuildTestBase::getPortNumber protected function Get the port number for requests.
BuildTestBase::getWorkingPath protected function Get the working directory within the workspace, creating if necessary.
BuildTestBase::getWorkspaceDirectory public function Full path to the workspace where this test can build.
BuildTestBase::initMink protected function Set up the Mink session manager.
BuildTestBase::instantiateServer protected function Do the work of making a server process.
BuildTestBase::setUpBeforeClass public static function
BuildTestBase::standUpServer protected function Makes a local test server using PHP's internal HTTP server.
BuildTestBase::stopServer protected function Stop the HTTP server, zero out all necessary variables.
BuildTestBase::tearDown protected function
BuildTestBase::visit public function Visit a URI on the HTTP server.
ExternalCommandRequirementsTrait::$existingCommands private static property A list of existing external commands we've already discovered.
ExternalCommandRequirementsTrait::checkClassCommandRequirements private static function Checks whether required external commands are available per test class.
ExternalCommandRequirementsTrait::checkExternalCommandRequirements private static function Checks missing external command requirements.
ExternalCommandRequirementsTrait::checkMethodCommandRequirements private static function Checks whether required external commands are available per method.
ExternalCommandRequirementsTrait::externalCommandIsAvailable private static function Determine if an external command is available. 3
InstallTestTrait::moduleInstall protected function Helper method that uses Drupal's module page to install a module.
InstallTestTrait::themeInstall protected function Helper method that uses Drupal's theme page to install a theme.
ModifiedFilesTest::$symfonyFileSystem protected property Symfony file system.
ModifiedFilesTest::assertModifications protected function Assert modified files.
ModifiedFilesTest::contribProjectsProvider public function Contrib project data provider.
ModifiedFilesTest::coreProjectProvider public function Core project data provider.
ModifiedFilesTest::setUp protected function Overrides BuildTestBase::setUp
ModifiedFilesTest::testContribModified public function @covers ::getModifiedFiles @dataProvider contribProjectsProvider
ModifiedFilesTest::testCoreModified public function @covers ::getModifiedFiles @dataProvider coreProjectProvider
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
QuickStartTestBase::$adminPassword protected property Password of the admin account generated during install.
QuickStartTestBase::$adminUsername protected property User name of the admin account generated during install.
QuickStartTestBase::formLogin public function Helper that uses Drupal's user/login form to log in.
QuickStartTestBase::installCore protected function Prepare core for testing.
QuickStartTestBase::installQuickStart public function Install a Drupal site using the quick start feature.