FileOwnershipTest.php in Automatic Updates 8
File
tests/src/Kernel/ReadinessChecker/FileOwnershipTest.php
View source
<?php
namespace Drupal\Tests\automatic_updates\Kernel\ReadinessChecker;
use Drupal\automatic_updates\ReadinessChecker\FileOwnership;
use Drupal\KernelTests\KernelTestBase;
use org\bovigo\vfs\vfsStream;
class FileOwnershipTest extends KernelTestBase {
public static $modules = [
'automatic_updates',
];
public function testFileOwnership() {
$file_ownership = new FileOwnership($this->container
->get('app.root'));
$messages = $file_ownership
->run();
$this
->assertEmpty($messages);
$file_ownership = new TestFileOwnership($this->container
->get('app.root'));
$messages = $file_ownership
->run();
$this
->assertCount(1, $messages);
$this
->assertStringStartsWith('Files are owned by uid "23"', (string) $messages[0]);
$this
->assertStringEndsWith('The file owner and PHP user should be the same during an update.', (string) $messages[0]);
}
}
class TestFileOwnership extends FileOwnership {
protected function doCheck() {
$file_stream = vfsStream::setup('core', '755', [
'core.api.php' => 'contents',
]);
$file = $file_stream
->getChild('core.api.php');
$file
->chown(23)
->chgrp(23);
return $this
->ownerIsScriptUser($file
->url());
}
}