-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Proposal
The module currently has no automated tests. Adding tests would improve code quality, prevent regressions, and make the module more suitable for Drupal.org contribution.
Test Coverage Needed
1. Unit Tests (Mocked Dependencies)
File: tests/src/Unit/ContentIntelCollectorTest.php
testGetEntityTypesReturnsContentEntities()testGetBundlesForEntityType()testGetFieldsReturnsFieldDefinitions()testLoadEntityReturnsNullForNonExistent()testExtractFieldValueHandlesEntityReference()testExtractFieldValueHandlesImageField()testExtractFieldValueHandlesTextField()testExtractFieldValueHandlesLinkField()testExtractFieldValueHandlesDatetimeField()
2. Kernel Tests (Real Drupal Bootstrap)
File: tests/src/Kernel/ContentIntelCollectorTest.php
testListEntitiesWithPagination()testListEntitiesWithBundleFilter()testCollectIntelIntegration()testPluginDiscovery()testPluginApplicability()
3. Functional Tests (Drush Commands)
File: tests/src/Functional/DrushCommandsTest.php
testCiTypesCommand()testCiBundlesCommand()testCiFieldsCommand()testCiListCommand()testCiEntityCommand()testCiBatchCommand()
Minimum Viable Test Suite
Priority order:
- Kernel test for
collectIntel()- Tests the main feature - Unit test for field extraction - Tests edge cases in data transformation
- Kernel test for plugins - Ensures plugin system works correctly
Example Test Structure
namespace Drupal\Tests\content_intel\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
class ContentIntelCollectorTest extends KernelTestBase {
protected static $modules = ['content_intel', 'node', 'field', 'user', 'system'];
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('user');
NodeType::create(['type' => 'article', 'name' => 'Article'])->save();
}
public function testCollectIntelReturnsExpectedStructure(): void {
$node = Node::create([
'type' => 'article',
'title' => 'Test Article',
]);
$node->save();
$collector = \Drupal::service('content_intel.collector');
$intel = $collector->collectIntel($node);
$this->assertArrayHasKey('entity', $intel);
$this->assertArrayHasKey('fields', $intel);
$this->assertArrayHasKey('intel', $intel);
$this->assertEquals('article', $intel['entity']['bundle']);
}
}Involved Components
tests/src/Unit/(NEW directory)tests/src/Kernel/(NEW directory)tests/src/Functional/(NEW directory)phpunit.xml.dist(NEW - PHPUnit configuration)
Metadata
Metadata
Assignees
Labels
No labels