3 // Copyright (c) 2013 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite
\test
;
18 use hoplite
\views
as views
;
20 require_once HOPLITE_ROOT
. '/views/pdo_cache_backend.php';
22 class PDOCacheBackendTest
extends \PHPUnit_Framework_TestCase
27 public function setUp()
29 $this->db
= new \
PDO('sqlite::memory:');
31 CREATE TABLE test_template_cache (
32 filename string PRIMARY KEY,
38 $this->cache
= new views\
PDOCacheBackend(
39 $this->db
, 'test_template_cache', 'filename', 'data', 'mtime');
42 private function _GetCount()
44 $stmt = $this->db
->Query("SELECT COUNT(*) AS count FROM test_template_cache");
45 return $stmt->FetchObject()->count
;
48 public function testCacheMiss()
50 $this->assertNull($this->cache
->GetTemplateDataForName('test', 100));
51 $this->db
->Exec("INSERT INTO test_template_cache (filename, data, mtime) VALUES ('test', 'hello world', 100)");
52 $this->assertEquals('hello world', $this->cache
->GetTemplateDataForName('test', 100));
53 $this->assertEquals(1, $this->_GetCount());
55 $this->assertNull($this->cache
->GetTemplateDataForName('test', 200));
56 $this->assertEquals(0, $this->_GetCount());
59 public function testCacheStore()
61 $this->cache
->StoreCompiledTemplate('name', 400, 'abcdefgh');
62 $this->assertEquals(1, $this->_GetCount());
64 $this->assertEquals('abcdefgh', $this->cache
->GetTemplateDataForName('name', 400));
65 $this->assertEquals(1, $this->_GetCount());
67 $this->assertNull($this->cache
->GetTemplateDataForName('name', 500));