public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / test / test.cms_user_tag_operations.php
100644 92 lines (81 sloc) 2.683 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
class TestCmsUserTagOperations extends UnitTestCase
{
  function __construct()
  {
    parent::__construct();
  }
  
  function setUp()
  {
    CmsCache::clear();
    $cms_db_prefix = CMS_DB_PREFIX;
    cms_db()->Execute("DELETE FROM {$cms_db_prefix}userplugins WHERE userplugin_name = ?", array('TestTag'));
  }
  
  function tearDown()
  {
    $this->setUp();
  }
  
  function create_user_tag()
  {
    return CmsUserTagOperations::set_user_tag('TestTag', "return \$params[0];\n");
  }
  
  function select_count()
  {
    return cms_orm('CmsUserTag')->find_count_by_name('TestTag');
  }
  
  function test_create_user_tag()
  {
    $this->assertTrue($this->create_user_tag());
    $this->assertEqual($this->select_count(), 1);
  }
  
  function test_no_duplicates()
  {
    $this->assertTrue($this->create_user_tag());
    $this->assertEqual($this->select_count(), 1);
    $this->assertTrue($this->create_user_tag());
    $this->assertEqual($this->select_count(), 1);
  }
  
  function test_delete_tag()
  {
    $this->assertTrue($this->create_user_tag());
    $this->assertEqual($this->select_count(), 1);
    $this->assertTrue(CmsUserTagOperations::remove_user_tag('TestTag'));
    $this->assertEqual($this->select_count(), 0);
  }
  
  function test_call_tag()
  {
    $this->assertTrue($this->create_user_tag());
    $this->assertEqual($this->select_count(), 1);
    $params = array('TestValue');
    $this->assertEqual(CmsUserTagOperations::call_user_tag('TestTag', $params), 'TestValue');
  }
  
  function test_call_tag_from_orm()
  {
    $this->assertTrue($this->create_user_tag());
    $this->assertEqual($this->select_count(), 1);
    $user_tag = cms_orm('CmsUserTag')->find_by_name('TestTag');
    $this->assertNotNull($user_tag);
    $params = array('TestValue');
    $this->assertEqual($user_tag->call($params), 'TestValue');
  }
}
 
# vim:ts=4 sw=4 noet
?>