TestSiteOliveroInstallTestScript.php in Drupal 10
File
core/tests/Drupal/TestSite/TestSiteOliveroInstallTestScript.php
View source
<?php
namespace Drupal\TestSite;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Extension\ThemeInstallerInterface;
use Drupal\node\Entity\Node;
use Drupal\comment\Entity\Comment;
class TestSiteOliveroInstallTestScript implements TestSetupInterface {
public function setup() {
$module_installer = \Drupal::service('module_installer');
assert($module_installer instanceof ModuleInstallerInterface);
$module_installer
->install([
'olivero_test',
]);
$theme_installer = \Drupal::service('theme_installer');
assert($theme_installer instanceof ThemeInstallerInterface);
$theme_installer
->install([
'olivero',
], TRUE);
$system_theme_config = \Drupal::configFactory()
->getEditable('system.theme');
$system_theme_config
->set('default', 'olivero')
->save();
$article_no_comments = Node::create([
'type' => 'article',
]);
$article_no_comments
->set('title', 'Article without comments');
$article_no_comments
->set('comment', 2);
$article_no_comments
->save();
$article_with_comments = Node::create([
'type' => 'article',
]);
$article_with_comments
->set('title', 'Article with comments');
$article_with_comments
->set('comment', 2);
$article_with_comments
->save();
$values = [
'entity_type' => 'node',
'entity_id' => 2,
'field_name' => 'comment',
'uid' => 1,
'comment_type' => 'comment',
'subject' => 'A comment',
'comment_body' => 'Body of comment',
'status' => 1,
];
$comment1 = Comment::create($values);
$comment1
->save();
$comment2 = Comment::create($values);
$comment2
->save();
}
}