Skip to content

Commit cf9258d

Browse files
committed
updated tests.
1 parent 66680ea commit cf9258d

File tree

11 files changed

+1618
-8
lines changed

11 files changed

+1618
-8
lines changed

resources/views/http_codes/404.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<h2>404</h2>
22
<p>
3-
The page <?= $route ?> does not exist.
3+
The page <?= $route ?? '' ?> does not exist.
44
</p>

resources/views/http_codes/500.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h2>500</h2>
2+
<p>
3+
Internal Server Error
4+
</p>
5+
<?php if( isset( $error ) && $error ): ?>
6+
<p>
7+
<?= htmlspecialchars( $error ) ?>
8+
</p>
9+
<?php endif; ?>
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<html>
22
<head></head>
3-
<title><?= $Title ?? '' ?></title>
3+
<title><?= $title ?? '' ?></title>
44
<body>
55
<h1>Test Layout</h1>
6-
<?php
7-
require_once( $View );
8-
?>
6+
<?= $content ?? '' ?>
97
</body>
108
</html>

tests/Mvc/Cache/CacheConfigTest.php

Lines changed: 169 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,180 @@ public function testGloballyDisabledButViewEnabled()
174174
'html' => true,
175175
'json' => true
176176
];
177-
177+
178178
$Config = new CacheConfig( $Settings );
179-
179+
180180
// Global cache is disabled
181181
$this->assertFalse( $Config->isEnabled() );
182-
182+
183183
// But view types can still have their settings
184184
$this->assertTrue( $Config->isViewTypeEnabled( 'html' ) );
185185
$this->assertTrue( $Config->isViewTypeEnabled( 'json' ) );
186186
}
187+
188+
/**
189+
* Test Redis configuration defaults
190+
*/
191+
public function testRedisConfigDefaults()
192+
{
193+
$Config = new CacheConfig( [] );
194+
195+
$this->assertEquals( '127.0.0.1', $Config->getRedisHost() );
196+
$this->assertEquals( 6379, $Config->getRedisPort() );
197+
$this->assertEquals( 0, $Config->getRedisDatabase() );
198+
$this->assertEquals( 'neuron_cache_', $Config->getRedisPrefix() );
199+
$this->assertEquals( 2.0, $Config->getRedisTimeout() );
200+
$this->assertNull( $Config->getRedisAuth() );
201+
$this->assertFalse( $Config->getRedisPersistent() );
202+
}
203+
204+
/**
205+
* Test Redis configuration with custom values
206+
*/
207+
public function testRedisConfigCustomValues()
208+
{
209+
$Settings = [
210+
'redis_host' => '192.168.1.100',
211+
'redis_port' => 6380,
212+
'redis_database' => 2,
213+
'redis_prefix' => 'myapp_',
214+
'redis_timeout' => 5.0,
215+
'redis_auth' => 'mypassword',
216+
'redis_persistent' => true
217+
];
218+
219+
$Config = new CacheConfig( $Settings );
220+
221+
$this->assertEquals( '192.168.1.100', $Config->getRedisHost() );
222+
$this->assertEquals( 6380, $Config->getRedisPort() );
223+
$this->assertEquals( 2, $Config->getRedisDatabase() );
224+
$this->assertEquals( 'myapp_', $Config->getRedisPrefix() );
225+
$this->assertEquals( 5.0, $Config->getRedisTimeout() );
226+
$this->assertEquals( 'mypassword', $Config->getRedisAuth() );
227+
$this->assertTrue( $Config->getRedisPersistent() );
228+
}
229+
230+
/**
231+
* Test Redis persistent connection variations
232+
*/
233+
public function testRedisPersistentVariations()
234+
{
235+
// Test with true
236+
$Config1 = new CacheConfig( ['redis_persistent' => true] );
237+
$this->assertTrue( $Config1->getRedisPersistent() );
238+
239+
// Test with 'true' string
240+
$Config2 = new CacheConfig( ['redis_persistent' => 'true'] );
241+
$this->assertTrue( $Config2->getRedisPersistent() );
242+
243+
// Test with '1' string
244+
$Config3 = new CacheConfig( ['redis_persistent' => '1'] );
245+
$this->assertTrue( $Config3->getRedisPersistent() );
246+
247+
// Test with false
248+
$Config4 = new CacheConfig( ['redis_persistent' => false] );
249+
$this->assertFalse( $Config4->getRedisPersistent() );
250+
251+
// Test with '0' string
252+
$Config5 = new CacheConfig( ['redis_persistent' => '0'] );
253+
$this->assertFalse( $Config5->getRedisPersistent() );
254+
}
255+
256+
/**
257+
* Test getRedisConfig returns complete configuration
258+
*/
259+
public function testGetRedisConfig()
260+
{
261+
$Settings = [
262+
'redis_host' => 'redis.example.com',
263+
'redis_port' => 6379,
264+
'redis_database' => 1,
265+
'redis_prefix' => 'test_',
266+
'redis_timeout' => 3.0,
267+
'redis_auth' => 'secret',
268+
'redis_persistent' => true
269+
];
270+
271+
$Config = new CacheConfig( $Settings );
272+
$redisConfig = $Config->getRedisConfig();
273+
274+
$this->assertIsArray( $redisConfig );
275+
$this->assertEquals( 'redis.example.com', $redisConfig['host'] );
276+
$this->assertEquals( 6379, $redisConfig['port'] );
277+
$this->assertEquals( 1, $redisConfig['database'] );
278+
$this->assertEquals( 'test_', $redisConfig['prefix'] );
279+
$this->assertEquals( 3.0, $redisConfig['timeout'] );
280+
$this->assertEquals( 'secret', $redisConfig['auth'] );
281+
$this->assertTrue( $redisConfig['persistent'] );
282+
}
283+
284+
/**
285+
* Test fromSettings with Redis configuration
286+
*/
287+
public function testFromSettingsWithRedisConfig()
288+
{
289+
$Settings = new Memory();
290+
$Settings->set( 'cache', 'enabled', 'true' );
291+
$Settings->set( 'cache', 'storage', 'redis' );
292+
$Settings->set( 'cache', 'redis_host', 'redis-server' );
293+
$Settings->set( 'cache', 'redis_port', '6380' );
294+
$Settings->set( 'cache', 'redis_database', '3' );
295+
$Settings->set( 'cache', 'redis_prefix', 'cache_' );
296+
$Settings->set( 'cache', 'redis_timeout', '4.5' );
297+
$Settings->set( 'cache', 'redis_auth', 'password123' );
298+
$Settings->set( 'cache', 'redis_persistent', 'true' );
299+
300+
$Config = CacheConfig::fromSettings( $Settings );
301+
302+
$this->assertEquals( 'redis', $Config->getStorageType() );
303+
$this->assertEquals( 'redis-server', $Config->getRedisHost() );
304+
$this->assertEquals( 6380, $Config->getRedisPort() );
305+
$this->assertEquals( 3, $Config->getRedisDatabase() );
306+
$this->assertEquals( 'cache_', $Config->getRedisPrefix() );
307+
$this->assertEquals( 4.5, $Config->getRedisTimeout() );
308+
$this->assertEquals( 'password123', $Config->getRedisAuth() );
309+
$this->assertTrue( $Config->getRedisPersistent() );
310+
}
311+
312+
/**
313+
* Test type casting for numeric Redis settings
314+
*/
315+
public function testRedisNumericTypeCasting()
316+
{
317+
$Settings = [
318+
'redis_port' => '6380', // String should be cast to int
319+
'redis_database' => '5', // String should be cast to int
320+
'redis_timeout' => '3.5' // String should be cast to float
321+
];
322+
323+
$Config = new CacheConfig( $Settings );
324+
325+
$this->assertIsInt( $Config->getRedisPort() );
326+
$this->assertEquals( 6380, $Config->getRedisPort() );
327+
328+
$this->assertIsInt( $Config->getRedisDatabase() );
329+
$this->assertEquals( 5, $Config->getRedisDatabase() );
330+
331+
$this->assertIsFloat( $Config->getRedisTimeout() );
332+
$this->assertEquals( 3.5, $Config->getRedisTimeout() );
333+
}
334+
335+
/**
336+
* Test fromSettings with minimal Redis configuration
337+
*/
338+
public function testFromSettingsMinimalRedisConfig()
339+
{
340+
$Settings = new Memory();
341+
$Settings->set( 'cache', 'enabled', 'true' );
342+
$Settings->set( 'cache', 'storage', 'redis' );
343+
// Don't set any Redis-specific parameters
344+
345+
$Config = CacheConfig::fromSettings( $Settings );
346+
347+
// Should use defaults
348+
$this->assertEquals( '127.0.0.1', $Config->getRedisHost() );
349+
$this->assertEquals( 6379, $Config->getRedisPort() );
350+
$this->assertEquals( 0, $Config->getRedisDatabase() );
351+
$this->assertEquals( 'neuron_cache_', $Config->getRedisPrefix() );
352+
}
187353
}

0 commit comments

Comments
 (0)