clean install

This commit is contained in:
matze committed 2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 files changed
+3555714

No files matched your search

@@ -0,0 +1,5 @@
name: farmOS Test
description: Provides common automated testing code for farmOS.
type: module
package: Testing
core_version_requirement: ^10
@@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\farm_test\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Provides a base class for farmOS functional tests.
*/
class FarmBrowserTestBase extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $profile = 'farm';
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
// Set a global farm_test variable and then delegate to the parent setUp().
// This is a temporary hack to prevent optional default farmOS modules from
// being installed via the profile's hook_install_tasks().
// @see farm_install_modules()
// @todo https://www.drupal.org/project/farm/issues/3183739
$GLOBALS['farm_test'] = TRUE;
parent::setUp();
}
}
@@ -0,0 +1,46 @@
<?php
namespace Drupal\Tests\farm_test\Kernel;
use Drupal\asset\Entity\AssetInterface;
/**
* Trait with helper functions for testing logic related to assets.
*/
trait FarmAssetTestTrait {
/**
* Helper function to assert the correct assets are included in an array.
*
* @param \Drupal\asset\Entity\AssetInterface[] $expected_assets
* The expected assets.
* @param \Drupal\asset\Entity\AssetInterface[] $actual_assets
* The actual assets, optionally keyed by asset ID.
* @param bool $check_keys
* If the actual asset keys should be checked. Defaults to FALSE.
* @param string $message
* An optional message for the assert statement.
*/
protected function assertCorrectAssets(array $expected_assets, array $actual_assets, bool $check_keys = FALSE, string $message = '') {
// Message prefix.
$prefix = empty($message) ? '' : "$message : ";
// Test the asset count.
$this->assertEquals(count($expected_assets), count($actual_assets), $prefix . 'Expected asset count does not match actual asset count.');
// Test that expected assets are included in actual assets array.
$actual_assets_keys = array_keys($actual_assets);
$actual_assets_ids = array_map(function (AssetInterface $asset) {
return $asset->id();
}, $actual_assets);
foreach ($expected_assets as $asset) {
$this->assertTrue(in_array($asset->id(), $actual_assets_ids), $prefix . 'Expected asset is not included in the actual assets.');
if ($check_keys) {
$this->assertTrue(in_array($asset->id(), $actual_assets_keys), $prefix . 'Expected asset ID is not included in the actual assets array.');
}
}
}
}
@@ -0,0 +1,57 @@
<?php
namespace Drupal\Tests\farm_test\Kernel;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
/**
* Trait for testing invalidation of entity cache tags.
*
* During a test use populateEntityTestCache to set a cache value dependent on
* an entity's cache tags. Later in the test use assertEntityTestCache to
* ensure the cache value's existence after cache tags are invalidated.
*/
trait FarmEntityCacheTestTrait {
/**
* Populate a cache value that is dependent on an entity's cache tags.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to cache data for.
* @param string $data
* The data to cache. Defaults to a simple string.
*/
protected function populateEntityTestCache(EntityInterface $entity, string $data = 'data') {
\Drupal::cache()->set($this->getEntityCacheId($entity), $data, Cache::PERMANENT, $entity->getCacheTags());
}
/**
* Assert that a cache value dependent on an entity's cache tags exists.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity cache to check.
* @param bool $cache_hit
* Boolean indicating if the cache lookup should result in a cache hit.
*/
protected function assertEntityTestCache(EntityInterface $entity, bool $cache_hit) {
$cache_result = \Drupal::cache()->get($this->getEntityCacheId($entity));
$this->assertEquals($cache_hit, (bool) $cache_result);
}
/**
* Helper method to build the entity test cache ID.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to cache data for.
*
* @return string
* The entity's test cache ID.
*/
protected function getEntityCacheId(EntityInterface $entity): string {
$entity_type = $entity->getEntityTypeId();
$entity_id = $entity->id();
return "farm_entity_cache_test:$entity_type:$entity_id";
}
}