source: trunk/tests/VersionTest.php

Last change on this file was 720, checked in by anonymous, 4 years ago

Update CSS reset with inspiration from https://github.com/hankchizljaw/modern-css-reset

File size: 6.6 KB
RevLine 
[1]1<?php
2/**
[362]3 * The Strangecode Codebase - a general application development framework for PHP
4 * For details visit the project site: <http://trac.strangecode.com/codebase/>
[396]5 * Copyright 2001-2012 Strangecode, LLC
[695]6 *
[362]7 * This file is part of The Strangecode Codebase.
[42]8 *
[362]9 * The Strangecode Codebase is free software: you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your option)
12 * any later version.
[695]13 *
[362]14 * The Strangecode Codebase is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details.
[695]18 *
[362]19 * You should have received a copy of the GNU General Public License along with
20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/**
24 * PHPUnit test case for codebase/lib/Version.inc.php
25 *
[42]26 * The method skeletons below need to be filled in with
27 * real data so that the tests will run correctly. Replace
28 * all EXPECTED_VAL and PARAM strings with real data.
29 *
[1]30 * Created with PHPUnit_Skeleton on 2005-08-09
31 */
32
[468]33class VersionTest extends PHPUnit_Framework_TestCase {
34
[137]35    var $Version;
[1]36    var $Auth_SQL;
37
38    function setUp()
[695]39    {
[1]40        require dirname(__FILE__) . '/_config.inc.php';
[137]41        require_once '../lib/Version.inc.php';
[1]42
43        require_once '../lib/Auth_SQL.inc.php';
[468]44        $this->Auth_SQL = new Auth_SQL('testauth');
[1]45        $this->Auth_SQL->setParam(array(
46            'db_table'          => 'test_user_tbl',
47            'db_primary_key'    => 'user_id',
48            'db_login_table'    => 'test_login_tbl',
49            'login_url'         => '/login.php',
50            'blocking'          => true
51        ));
52
53        // Use fresh user table.
54        $this->Auth_SQL->initDB(true);
[42]55
[1]56        // Insert test data.
[136]57        $db =& DB::getInstance();
58        $db->query("
[1]59            INSERT INTO test_user_tbl (
60                username,
61                userpass,
62                first_name,
63                last_name,
[357]64                email
[1]65            ) VALUES (
66                'testuser',
67                md5('testpass'),
68                'John',
69                'Doe',
[357]70                'john@example.com'
[1]71            )
72        ");
[42]73
[1]74        $this->Auth_SQL->login('testuser', 'testpass');
[42]75
[137]76        $this->Version =& Version::getInstance($this->Auth_SQL);
77        $this->Version->setParam(array('db_table' => 'test_version_tbl'));
[1]78
79        // Use fresh version table.
[137]80        $this->Version->initDB(true);
[1]81    }
82
83    function tearDown()
84    {
[479]85        $db =& DB::getInstance();
[695]86
[137]87        unset($this->Version);
[1]88        unset($this->Auth_SQL);
[136]89        $db->query("DROP TABLE IF EXISTS test_user_tbl");
90        $db->query("DROP TABLE IF EXISTS test_login_tbl");
91        $db->query("DROP TABLE IF EXISTS test_version_tbl");
[1]92    }
93
94    function test_getinstance()
95    {
[137]96        $result = Version::getinstance($this->Auth_SQL);
[695]97        $this->assertTrue($result && $result instanceof Version);
[1]98    }
99
100    function test_setparam()
101    {
[137]102        $this->Version->setparam(array('var'=>'val'));
[1]103    }
104
105    function test_getparam()
106    {
[137]107        $this->Version->getparam('var');
[1]108    }
109
110    function test_create()
111    {
[137]112        $result = $this->Version->create('test_user_tbl', 'user_id', '1', 'Test User', 'First version of user');
[720]113        $this->assertSame('1', $result);
[1]114    }
115
116    function test_restore()
117    {
[137]118        $current = $this->Version->getCurrent('test_user_tbl', 'user_id', '1');
119        $version_id = $this->Version->create('test_user_tbl', 'user_id', '1', 'Test User', 'First version of user');
120        $versioned = $this->Version->getData($version_id);
121        $result = $this->Version->restore($version_id);
122        $restored = $this->Version->getCurrent('test_user_tbl', 'user_id', '1');
[1]123        $this->assertTrue(is_array($result), 'Restore did not return array.');
124        $this->assertTrue($current === $versioned && $versioned === $restored, 'Restored version does not match original.');
125    }
126
127    function test_deleteold()
128    {
129        // Creat 3 test versions.
[137]130        $this->Version->create('test_user_tbl', 'user_id', '1', 'Test 1', '1 version of user');
131        $this->Version->create('test_user_tbl', 'user_id', '1', 'Test 2', '2 version of user');
132        $this->Version->create('test_user_tbl', 'user_id', '1', 'Test 3', '3 version of user');
[1]133
[137]134        $a = $this->Version->getList('test_user_tbl', 'user_id', '1');
[1]135
[137]136        $this->Version->deleteold('test_user_tbl', 'user_id', '1');
137        $b = $this->Version->getList('test_user_tbl', 'user_id', '1');
[1]138
[137]139        $this->Version->setparam(array('max_qty'=>2));
140        $this->Version->setparam(array('min_qty'=>1));
141        $this->Version->setparam(array('min_days'=>0));
142        $this->Version->deleteold('test_user_tbl', 'user_id', '1');
143        $c = $this->Version->getList('test_user_tbl', 'user_id', '1');
[1]144
[137]145        $this->Version->setparam(array('max_qty'=>0));
146        $this->Version->setparam(array('min_qty'=>0));
147        $this->Version->setparam(array('min_days'=>0));
148        $this->Version->deleteold('test_user_tbl', 'user_id', '1');
149        $d = $this->Version->getList('test_user_tbl', 'user_id', '1');
[1]150
151        $this->assertTrue(sizeof($a) == 3, 'A is wrong');
152        $this->assertTrue(sizeof($b) == 3, 'B is wrong');
153        $this->assertTrue(sizeof($c) == 1, 'C is wrong');
154        $this->assertTrue(sizeof($d) == 0, 'D is wrong');
155    }
156
157    function test_getlist()
158    {
[137]159        $this->Version->create('test_user_tbl', 'user_id', '1', 'Test 1', '1 version of user');
160        $this->Version->create('test_user_tbl', 'user_id', '1', 'Test 2', '2 version of user');
161        $this->Version->create('test_user_tbl', 'user_id', '1', 'Test 3', '3 version of user');
162        $result = $this->Version->getList('test_user_tbl', 'user_id', '1');
[1]163        $this->assertTrue(is_array($result) && !empty($result));
164    }
165
166    function test_getverson()
167    {
[137]168        $version_id = $this->Version->create('test_user_tbl', 'user_id', '1', 'Test User', 'First version of user');
169        $result = $this->Version->getverson($version_id);
[1]170        $this->assertTrue(is_array($result) && !empty($result));
171    }
172
173    function test_getdata()
174    {
[137]175        $version_id = $this->Version->create('test_user_tbl', 'user_id', '1', 'Test User', 'First version of user');
176        $result = $this->Version->getdata($version_id);
[1]177        $this->assertTrue(is_array($result) && !empty($result));
178    }
179
180    function test_getcurrent()
181    {
[137]182        $result = $this->Version->getCurrent('test_user_tbl', 'user_id', '1');
[1]183        $this->assertTrue(is_array($result) && !empty($result));
184    }
185
186}
Note: See TracBrowser for help on using the repository browser.