Skip to content

Commit

Permalink
ACMS-3281: Add PHPUnit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshreeputra committed Nov 15, 2023
1 parent 6edc58b commit 39c5534
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"acquia/coding-standards": "^1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
"ergebnis/composer-normalize": "~2.21.0",
"phpro/grumphp-shim": "^1.5"
"phpro/grumphp-shim": "^1.5",
"phpunit/phpunit": "^9 || ^10"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
88 changes: 88 additions & 0 deletions tests/unit/SettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Acquia\Drupal\RecommendedSettings\Tests;

use Acquia\Drupal\RecommendedSettings\Helpers\Filesystem as DrsFilesystem;
use Acquia\Drupal\RecommendedSettings\Settings;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;

class SettingsTest extends TestCase {

/**
* The recommended settings object.
*
* @var string
*/
protected $settings;

/**
* The path to drupal webroot directory.
*
* @var string
*/
protected $drupalRoot;

/**
* The symfony file-system object.
*
* @var \Symfony\Component\Filesystem\Filesystem
*/
protected Filesystem $fileSystem;

/**
* The symfony file-system object.
*
* @var \Acquia\Drupal\RecommendedSettings\Helpers\Filesystem
*/
protected DrsFilesystem $drsFileSystem;

/**
* Set up test environmemt.
*/
public function setUp(): void {
$this->drupalRoot = dirname(__FILE__);
$docroot = $this->drupalRoot . '/docroot';
$this->drsFileSystem = new DrsFilesystem();
$this->drsFileSystem->ensureDirectoryExists($docroot . '/sites/default');
$this->fileSystem = new Filesystem();
$this->fileSystem->touch($docroot . '/sites/default/default.settings.php');
$this->settings = new Settings($docroot, "default");
$this->settings->generate();
}

/**
* Test that the file is created.
*/
public function testFileIsCreated() {
// Assert that settings/default.global.settings.php file exist.
$this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/settings/default.global.settings.php'));
// Assert that settings.php file exist.
$this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/default/settings.php'));
// Assert that settings.php file has content.
$content = '
require DRUPAL_ROOT . "/../vendor/acquia/drupal-recommended-settings/settings/acquia-recommended.settings.php";
/**
* IMPORTANT.
*
* Do not include additional settings here. Instead, add them to settings
* included by `acquia-recommended.settings.php`. See Acquia\'s documentation for more detail.
*
* @link https://docs.acquia.com/
*/
';
$this->assertEquals($content, file_get_contents($this->drupalRoot . '/docroot/sites/default/settings.php'));
// Assert that default.includes.settings.php file exist.
$this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/default/settings/default.includes.settings.php'));
// Assert that default.local.settings.php file exist.
$this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/default/settings/default.local.settings.php'));
// Assert that local.settings.php file exist.
$this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/default/settings/local.settings.php'));
}

public function tearDown(): void {
$this->fileSystem->remove($this->drupalRoot . '/docroot');
$this->fileSystem->remove($this->drupalRoot . '/config');
}

}

0 comments on commit 39c5534

Please sign in to comment.