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
Prev Previous commit
Add a negative test, when the storage fails. Something
  • Loading branch information
rodriquelca committed Nov 26, 2024
commit 6b971b3fd7377cd7e9d2ba288c7f667d050b0c1a
55 changes: 55 additions & 0 deletions tests/Feature/Screens/ScreenCompiledManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature;

use Illuminate\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use ProcessMaker\Managers\ScreenCompiledManager;
Expand Down Expand Up @@ -276,4 +277,58 @@ public function it_clears_compiled_assets_when_directory_does_not_exist()
// Assert the directory has been recreated
Storage::disk($this->storageDisk)->assertExists($this->storagePath);
}

/**
* Validate that storing compiled content fails with invalid data
*
* @test
*/
public function it_fails_with_invalid_screen_key()
{
// Arrange
$manager = new ScreenCompiledManager();

// Test cases with invalid screen keys
$invalidKeys = [
'', // Empty string
null, // Null value
str_repeat('a', 1000), // Extremely long key
'../../malicious/path', // Path traversal attempt
'special@#$%chars', // Special characters
];

foreach ($invalidKeys as $invalidKey) {
try {
$manager->storeCompiledContent($invalidKey, ['test' => 'content']);
$this->fail('Expected exception was not thrown for key: ' . (string) $invalidKey);
} catch (\TypeError|\Exception $e) {
// Assert that an exception was thrown
$this->assertTrue(true);
}
}
}

/**
* Test handling of storage limit scenarios when storing compiled screen content
*
* @test
*/
public function it_handles_storage_limit_scenarios()
{
// Arrange
$manager = new ScreenCompiledManager();
$screenKey = $manager->createKey('1', '1', 'en', '1', '1');
$compiledContent = ['test' => 'content'];

// Simulate storage limit reached by throwing a specific exception
Storage::shouldReceive('disk->put')
->andThrow(new \Exception('Storage limit reached'));

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

// Attempt to store compiled content, expecting an exception
$manager->storeCompiledContent($screenKey, $compiledContent);
}
}