diff --git a/tests/cache_config_test.php b/tests/cache_config_test.php index 4c3c54a..0fff704 100644 --- a/tests/cache_config_test.php +++ b/tests/cache_config_test.php @@ -76,7 +76,12 @@ public function test_generate_store_instance_config() { $method->setAccessible(true); // Read in the fixtures file for data. - include(__DIR__ . '/fixtures/stores_data.php'); + if (defined('TEST_CACHESTORE_REDIS_TESTSERVERS') + && class_exists('cachestore_redis') && \cachestore_redis::are_requirements_met()) { + include(__DIR__ . '/fixtures/stores_data_redis.php'); + } else { + include(__DIR__ . '/fixtures/stores_data.php'); + } // First test with 1 store. $this->assertEquals($storeone['expected'], $method->invoke($config, $storeone['input'])); diff --git a/tests/fixtures/stores_data_redis.php b/tests/fixtures/stores_data_redis.php new file mode 100644 index 0000000..d2917a6 --- /dev/null +++ b/tests/fixtures/stores_data_redis.php @@ -0,0 +1,303 @@ +. + +defined('MOODLE_INTERNAL') || die(); + +$storeone = array ( + 'input' => array ( + 'filetest' => array ( + 'type' => 'file', + 'config' => array ( + 'path' => '/tmp/hardcode', + 'autocreate' => 1 + ) + ) + ), + 'expected' => array ( + 'filetest' => + array ( + 'name' => 'filetest', + 'plugin' => 'file', + 'configuration' => + array ( + 'path' => '/tmp/hardcode', + 'autocreate' => 1, + ), + 'features' => 30, + 'modes' => 3, + 'mappingsonly' => false, + 'class' => 'cachestore_file', + 'default' => false, + 'lock' => 'cachelock_file_default', + ), + 'default_application' => + array ( + 'name' => 'default_application', + 'plugin' => 'redis', + 'configuration' => + array ( + 'server' => '127.0.0.1', + 'prefix' => 'phpu_', + ), + 'features' => 26, + 'modes' => 3, + 'default' => true, + 'class' => 'cachestore_file', + 'lock' => 'cachelock_file_default', + ), + 'default_session' => + array ( + 'name' => 'default_session', + 'plugin' => 'session', + 'configuration' => + array ( + ), + 'features' => 14, + 'modes' => 2, + 'default' => true, + 'class' => 'cachestore_session', + 'lock' => 'cachelock_file_default', + ), + 'default_request' => + array ( + 'name' => 'default_request', + 'plugin' => 'static', + 'configuration' => + array ( + ), + 'features' => 31, + 'modes' => 4, + 'default' => true, + 'class' => 'cachestore_static', + 'lock' => 'cachelock_file_default', + ) + ) +); + +$storetwo = array ( + 'input' => array ( + 'filetest' => array ( + 'type' => 'file', + 'config' => array ( + 'path' => '/tmp/hardcode', + 'autocreate' => 1 + ) + ), + 'filetest2' => array ( + 'type' => 'file', + 'config' => array ( + 'path' => '/tmp/hardcode2', + 'autocreate' => 1 + ) + ) + ), + 'expected' => array ( + 'filetest' => + array ( + 'name' => 'filetest', + 'plugin' => 'file', + 'configuration' => + array ( + 'path' => '/tmp/hardcode', + 'autocreate' => 1, + ), + 'features' => 30, + 'modes' => 3, + 'mappingsonly' => false, + 'class' => 'cachestore_file', + 'default' => false, + 'lock' => 'cachelock_file_default', + ), + 'filetest2' => + array ( + 'name' => 'filetest2', + 'plugin' => 'file', + 'configuration' => + array ( + 'path' => '/tmp/hardcode2', + 'autocreate' => 1, + ), + 'features' => 30, + 'modes' => 3, + 'mappingsonly' => false, + 'class' => 'cachestore_file', + 'default' => false, + 'lock' => 'cachelock_file_default', + ), + 'default_application' => + array ( + 'name' => 'default_application', + 'plugin' => 'redis', + 'configuration' => + array ( + 'server' => '127.0.0.1', + 'prefix' => 'phpu_', + ), + 'features' => 26, + 'modes' => 3, + 'default' => true, + 'class' => 'cachestore_file', + 'lock' => 'cachelock_file_default', + ), + 'default_session' => + array ( + 'name' => 'default_session', + 'plugin' => 'session', + 'configuration' => + array ( + ), + 'features' => 14, + 'modes' => 2, + 'default' => true, + 'class' => 'cachestore_session', + 'lock' => 'cachelock_file_default', + ), + 'default_request' => + array ( + 'name' => 'default_request', + 'plugin' => 'static', + 'configuration' => + array ( + ), + 'features' => 31, + 'modes' => 4, + 'default' => true, + 'class' => 'cachestore_static', + 'lock' => 'cachelock_file_default', + ) + ) +); + +$storezero = array ( + 'input' => array ( + ), + 'expected' => array ( + 'default_application' => + array ( + 'name' => 'default_application', + 'plugin' => 'redis', + 'configuration' => + array ( + 'server' => '127.0.0.1', + 'prefix' => 'phpu_', + ), + 'features' => 26, + 'modes' => 3, + 'default' => true, + 'class' => 'cachestore_file', + 'lock' => 'cachelock_file_default', + ), + 'default_session' => + array ( + 'name' => 'default_session', + 'plugin' => 'session', + 'configuration' => + array ( + ), + 'features' => 14, + 'modes' => 2, + 'default' => true, + 'class' => 'cachestore_session', + 'lock' => 'cachelock_file_default', + ), + 'default_request' => + array ( + 'name' => 'default_request', + 'plugin' => 'static', + 'configuration' => + array ( + ), + 'features' => 31, + 'modes' => 4, + 'default' => true, + 'class' => 'cachestore_static', + 'lock' => 'cachelock_file_default', + ) + ) +); + +$storebadtype = array ( + 'input' => array ( + 'apcutest' => array ( + 'type' => 'faketype', + 'config' => array ( + 'prefix' => 'test' + ) + ) + ) +); + +$storemissingfield = array ( + 'input' => array ( + 'apcutest' => array ( + 'type' => 'faketype', + ) + ) +); + +$storereqsnotmet = array ( + 'input' => array ( + 'apcutest' => array ( + 'type' => 'apcu', + 'config' => array ( + 'prefix' => 'test_', + ) + ) + ), + 'expected' => array ( + 'default_application' => + array ( + 'name' => 'default_application', + 'plugin' => 'redis', + 'configuration' => + array ( + 'server' => '127.0.0.1', + 'prefix' => 'phpu_', + ), + 'features' => 26, + 'modes' => 3, + 'default' => true, + 'class' => 'cachestore_file', + 'lock' => 'cachelock_file_default', + ), + 'default_session' => + array ( + 'name' => 'default_session', + 'plugin' => 'session', + 'configuration' => + array ( + ), + 'features' => 14, + 'modes' => 2, + 'default' => true, + 'class' => 'cachestore_session', + 'lock' => 'cachelock_file_default', + ), + 'default_request' => + array ( + 'name' => 'default_request', + 'plugin' => 'static', + 'configuration' => + array ( + ), + 'features' => 31, + 'modes' => 4, + 'default' => true, + 'class' => 'cachestore_static', + 'lock' => 'cachelock_file_default', + ) + ) +); \ No newline at end of file