Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
FOUR-20912: Enhance Test Coverage for Screens Functionality Before Ad…
…ding Cache
  • Loading branch information
rodriquelca committed Nov 25, 2024
commit 54159673042c7463b5e53fef0d97823f3a39c565
93 changes: 83 additions & 10 deletions tests/Feature/Screens/ScreenCompiledManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,33 @@ public function it_clears_process_screens_cache()
}

/**
* Validate a screen key can be created
* Validate that a screen key can be created with various process versions, screen versions, and languages.
*
* @test
*/
public function it_creates_a_screen_key()
public function it_creates_a_screen_key_with_various_versions()
{
// Arrange
$manager = new ScreenCompiledManager();
$processId = '123';
$processVersionId = '1';
$language = 'en';
$processVersionIds = ['1', '2', '3'];
$languages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'zh', 'ja', 'ru', 'ar'];
$screenId = '456';
$screenVersionId = '1';
$screenVersionIds = ['1', '2'];

$expectedKey = 'pid_123_1_en_sid_456_1';
foreach ($processVersionIds as $processVersionId) {
foreach ($screenVersionIds as $screenVersionId) {
foreach ($languages as $language) {
$expectedKey = "pid_{$processId}_{$processVersionId}_{$language}_sid_{$screenId}_{$screenVersionId}";

// Create the screen key
$screenKey = $manager->createKey($processId, $processVersionId, $language, $screenId, $screenVersionId);
// Create the screen key
$screenKey = $manager->createKey($processId, $processVersionId, $language, $screenId, $screenVersionId);

// Assert
$this->assertEquals($expectedKey, $screenKey);
// Assert
$this->assertEquals($expectedKey, $screenKey);
}
}
}
}

/**
Expand All @@ -203,4 +209,71 @@ public function it_gets_the_last_screen_version_id()
// Assert the ID is the expected one
$this->assertEquals($expectedId, $lastId);
}

/**
* Validate storing compiled content with empty content
*
* @test
*/
public function it_stores_empty_compiled_content()
{
// Arrange
$manager = new ScreenCompiledManager();
$screenKey = 'empty_screen_key';
$compiledContent = '';

// Act
$manager->storeCompiledContent($screenKey, $compiledContent);

// Assert
$filename = 'screen_' . $screenKey . '.bin';
$storagePath = $this->storagePath . $filename;

Storage::disk($this->storageDisk)->assertExists($storagePath);
$storedContent = Storage::disk($this->storageDisk)->get($storagePath);
$this->assertEquals(serialize($compiledContent), $storedContent);
}

/**
* Validate exception handling when storage is unavailable
*
* @test
*/
public function it_handles_storage_exceptions()
{
// Arrange
$manager = new ScreenCompiledManager();
$screenKey = 'exception_screen_key';
$compiledContent = ['key' => 'value'];

// Simulate storage exception
Storage::shouldReceive('disk->put')
->andThrow(new \Exception('Storage unavailable'));

// Act & Assert
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Storage unavailable');

$manager->storeCompiledContent($screenKey, $compiledContent);
}

/**
* Validate clearing compiled assets when directory does not exist
*
* @test
*/
public function it_clears_compiled_assets_when_directory_does_not_exist()
{
// Arrange
$manager = new ScreenCompiledManager();

// Ensure directory does not exist
Storage::disk($this->storageDisk)->deleteDirectory($this->storagePath);

// Act
$manager->clearCompiledAssets();

// Assert the directory has been recreated
Storage::disk($this->storageDisk)->assertExists($this->storagePath);
}
}