MDL-40555 cache: implemented unit tests for default search functionality
authorSam Hemelryk <sam@moodle.com>
Tue, 9 Jul 2013 00:18:45 +0000 (12:18 +1200)
committerFred <fmcell@gmail.com>
Tue, 16 Jul 2013 00:29:17 +0000 (08:29 +0800)
cache/tests/cache_test.php
cache/tests/fixtures/lib.php

index 5293eec..6553583 100644 (file)
@@ -1374,4 +1374,54 @@ class cache_phpunit_tests extends advanced_testcase {
             $this->assertContains('Identifier required for cache has not been provided', $ex->getMessage());
         }
     }
+
+    /**
+     * Test that the default stores all support searching.
+     */
+    public function test_defaults_support_searching() {
+        $instance = cache_config_phpunittest::instance(true);
+        $instance->phpunit_add_definition('phpunit/search1', array(
+            'mode' => cache_store::MODE_APPLICATION,
+            'component' => 'phpunit',
+            'area' => 'search1',
+            'requiresearchable' => true
+        ));
+        $instance->phpunit_add_definition('phpunit/search2', array(
+            'mode' => cache_store::MODE_SESSION,
+            'component' => 'phpunit',
+            'area' => 'search2',
+            'requiresearchable' => true
+        ));
+        $instance->phpunit_add_definition('phpunit/search3', array(
+            'mode' => cache_store::MODE_REQUEST,
+            'component' => 'phpunit',
+            'area' => 'search3',
+            'requiresearchable' => true
+        ));
+        $factory = cache_factory::instance();
+
+        // Test application cache is searchable.
+        $definition = $factory->create_definition('phpunit', 'search1');
+        $this->assertInstanceOf('cache_definition', $definition);
+        $this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE);
+        $cache = $factory->create_cache($definition);
+        $this->assertInstanceOf('cache_application', $cache);
+        $this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());
+
+        // Test session cache is searchable.
+        $definition = $factory->create_definition('phpunit', 'search2');
+        $this->assertInstanceOf('cache_definition', $definition);
+        $this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE);
+        $cache = $factory->create_cache($definition);
+        $this->assertInstanceOf('cache_session', $cache);
+        $this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());
+
+        // Test request cache is searchable.
+        $definition = $factory->create_definition('phpunit', 'search3');
+        $this->assertInstanceOf('cache_definition', $definition);
+        $this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE);
+        $cache = $factory->create_cache($definition);
+        $this->assertInstanceOf('cache_request', $cache);
+        $this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());
+    }
 }
index bdb2291..f03a66c 100644 (file)
@@ -226,6 +226,13 @@ class cache_phpunit_application extends cache_application {
         return get_class($this->get_store());
     }
 
+    /**
+     * Returns all the interfaces the cache store implements.
+     * @return array
+     */
+    public function phpunit_get_store_implements() {
+        return class_implements($this->get_store());
+    }
 }
 
 /**
@@ -245,6 +252,14 @@ class cache_phpunit_session extends cache_session {
     public function phpunit_get_store_class() {
         return get_class($this->get_store());
     }
+
+    /**
+     * Returns all the interfaces the cache store implements.
+     * @return array
+     */
+    public function phpunit_get_store_implements() {
+        return class_implements($this->get_store());
+    }
 }
 
 /**
@@ -264,6 +279,14 @@ class cache_phpunit_request extends cache_request {
     public function phpunit_get_store_class() {
         return get_class($this->get_store());
     }
+
+    /**
+     * Returns all the interfaces the cache store implements.
+     * @return array
+     */
+    public function phpunit_get_store_implements() {
+        return class_implements($this->get_store());
+    }
 }
 
 /**