OSDN Git Service

MERGE: リビジョン1873〜1893。skinnable-masterのマージ
[nucleus-jp/nucleus-next.git] / build / testcases / NP_OptionTest.php
1 <?php
2
3 /** 
4   * Plugin for Nucleus CMS (http://plugins.nucleuscms.org/) 
5   * Copyright (C) 2003-2006 The Nucleus Plugins Project
6   *
7   * This program is free software; you can redistribute it and/or
8   * modify it under the terms of the GNU General Public License
9   * as published by the Free Software Foundation; either version 2
10   * of the License, or (at your option) any later version.
11   *
12   * see license.txt for the full license
13   */
14
15 class NP_OptionTest extends NucleusPlugin {
16
17         // name of plugin
18         function getName() {
19                 return 'OptionTest'; 
20         }
21         
22         // author of plugin
23         function getAuthor()  { 
24                 return 'Wouter Demuynck'; 
25         }
26         
27         // an URL to the plugin website
28         // can also be of the form mailto:foor@bar.com
29         function getURL() 
30         {
31                 return 'http://nucleuscms.org/'; 
32         }
33         
34         // version of the plugin
35         function getVersion() {
36                 return '1.0'; 
37         }
38         
39         // a description to be shown on the installed plugins listing
40         function getDescription() { 
41                 return 'Plugin to test blog and member options by plugins';
42         }
43         
44         function getMinNucleusVersion() {
45                 return 220;
46         }
47
48         function install() {
49                 $aErrors = array();
50         
51                 echo '<h1>Creating some options</h1>';
52         
53                 if (!$this->createBlogOption('my option', 'my description', 'text', 'initial value', 'extra'))
54                         array_push($aErrors, 'create blog option failed');
55                         
56                 if (!$this->createBlogOption('my option2', 'my description2', 'yesno', 'no'))
57                         array_push($aErrors, 'create blog option 2 failed');
58                         
59                 if (!$this->createMemberOption('my option3', 'my description3', 'yesno', 'no'))
60                         array_push($aErrors, 'create member option failed');
61                         
62                 if (!$this->createCategoryOption('my option4', 'my description4', 'yesno', 'yes'))
63                         array_push($aErrors, 'create catgeory option failed');
64
65                 echo '<h1>Creating some more options</h1>';
66                 // add some thingies with the same name
67                 $this->createCategoryOption('idem', 'idemd', 'text', 'category');
68                 $this->createOption('idem', 'idemd', 'text', 'global');
69                 $this->createBlogOption('idem', 'idemd', 'text', 'blog');
70                 $this->createMemberOption('idem', 'idemd', 'text', 'member');           
71                 
72                 echo '<h1>Checking options</h1>';               
73                 if ($this->getOption('idem') != 'global') 
74                         array_push($aErrors, 'get should return "global" ' . $this->getOption('idem'));                 
75                 if ($this->getCategoryOption(1, 'idem') != 'category') 
76                         array_push($aErrors, 'get should return "category" ' . $this->getCategoryOption(1, 'idem'));                    
77                 if ($this->getBlogOption(1, 'idem') != 'blog') 
78                         array_push($aErrors, 'get should return "blog" ' . $this->getBlogOption(1, 'idem'));                    
79                 if ($this->getMemberOption(1, 'idem') != 'member') 
80                         array_push($aErrors, 'get should return "member" ' . $this->getMemberOption(1, 'idem'));                        
81                         
82                 echo '<h1>Setting options</h1>';                        
83                 if (!$this->setOption('idem','edit-global'))
84                         array_push($aErrors, 'set option failed');
85                 if (!$this->setCategoryOption(1, 'idem', 'edit-category'))
86                         array_push($aErrors, 'set catgeory option failed');
87                 if (!$this->setBlogOption(1, 'idem', 'edit-blog'))
88                         array_push($aErrors, 'set blog option failed');
89                 if (!$this->setMemberOption(1, 'idem', 'edit-member'))
90                         array_push($aErrors, 'set member option failed');
91
92                 echo '<h1>Checking options</h1>';
93                 if ($this->getOption('idem') != 'edit-global') 
94                         array_push($aErrors, 'get should return "edit-global"');                        
95                 if ($this->getCategoryOption(1, 'idem') != 'edit-category') 
96                         array_push($aErrors, 'get should return "edit-category"');                      
97                 if ($this->getBlogOption(1, 'idem') != 'edit-blog') 
98                         array_push($aErrors, 'get should return "edit-blog"');                  
99                 if ($this->getMemberOption(1, 'idem') != 'edit-member') 
100                         array_push($aErrors, 'get should return "edit-member"');                        
101                         
102                 if (count($aErrors) > 0);
103                         echo '<ul><li>' . implode('</li><li>', $aErrors). '</li></ul>';
104                 
105                 echo '<pre>';
106                 echo "All blog options:\n";
107                 print_r($this->getAllBlogOptions('idem'));
108                 
109                 echo "\nAll category options:\n";
110                 print_r($this->getAllCategoryOptions('idem'));
111
112                 echo "\nAll member options:\n";
113                 print_r($this->getAllMemberOptions('idem'));
114
115                 echo '</pre>';
116                 
117         }
118         
119 }
120 ?>