DefaultUserImageTest.php in Lightning Core 8.3
File
tests/src/Kernel/DefaultUserImageTest.php
View source
<?php
namespace Drupal\Tests\lightning_core\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\KernelTests\KernelTestBase;
class DefaultUserImageTest extends KernelTestBase {
protected static $modules = [
'system',
];
public function testDefaultUserImage() {
\Drupal::service('module_installer')
->install([
'lightning_core',
'image',
]);
$this
->assertFileExists('public://default-avatar.png');
$config = FieldConfig::load('user.user.user_picture');
$setting = $config
->getSetting('default_image');
$this
->assertNotEmpty($setting['uuid']);
$this
->assertSame('A generic silhouette of a person.', $setting['alt']);
$this
->assertSame('', $setting['title']);
$this
->assertSame(140, $setting['width']);
$this
->assertSame(140, $setting['height']);
}
public function testAlreadyExists() {
file_put_contents('public://default-avatar.png', '');
\Drupal::service('module_installer')
->install([
'lightning_core',
'image',
]);
$this
->assertEmpty(File::loadMultiple());
$config = FieldConfig::load('user.user.user_picture');
$setting = $config
->getSetting('default_image');
$this
->assertNull($setting['uuid']);
$this
->assertSame('', $setting['alt']);
$this
->assertSame('', $setting['title']);
$this
->assertNull($setting['width']);
$this
->assertNull($setting['height']);
}
}