Open Monograph Press  3.3.0
PublicationTest.php
1 <?php
15 import('lib.pkp.tests.PKPTestCase');
20  protected function setUp() : void {
21  $this->publication = DAORegistry::getDAO('PublicationDAO')->newDataObject();
22  }
26  protected function tearDown() : void {
27  unset($this->publication);
28  }
29  //
30  // Unit tests
31  //
35  public function testPageArray() {
36  $expected = array(array('i', 'ix'), array('6', '11'), array('19'), array('21'));
37  // strip prefix and spaces
38  $this->publication->setData('pages', 'pg. i-ix, 6-11, 19, 21');
39  $pageArray = $this->publication->getPageArray();
40  $this->assertSame($expected,$pageArray);
41  // no spaces
42  $this->publication->setData('pages', 'i-ix,6-11,19,21');
43  $pageArray = $this->publication->getPageArray();
44  $this->assertSame($expected,$pageArray);
45  // double-hyphen
46  $this->publication->setData('pages', 'i--ix,6--11,19,21');
47  $pageArray = $this->publication->getPageArray();
48  $this->assertSame($expected,$pageArray);
49  // single page
50  $expected = array(array('16'));
51  $this->publication->setData('pages', '16');
52  $pageArray = $this->publication->getPageArray();
53  $this->assertSame($expected,$pageArray);
54  // spaces in a range
55  $expected = array(array('16', '20'));
56  $this->publication->setData('pages', '16 - 20');
57  $pageArray = $this->publication->getPageArray();
58  $this->assertSame($expected,$pageArray);
59  // pages are alphanumeric
60  $expected = array(array('a6', 'a12'), array('b43'));
61  $this->publication->setData('pages', 'a6-a12,b43');
62  $pageArray = $this->publication->getPageArray();
63  $this->assertSame($expected,$pageArray);
64  // inconsisent formatting
65  $this->publication->setData('pages', 'pp: a6 -a12, b43');
66  $pageArray = $this->publication->getPageArray();
67  $this->assertSame($expected,$pageArray);
68  $this->publication->setData('pages', ' a6 -a12, b43 ');
69  $pageArray = $this->publication->getPageArray();
70  $this->assertSame($expected,$pageArray);
71  // empty-ish values
72  $expected = array();
73  $this->publication->setData('pages', '');
74  $pageArray = $this->publication->getPageArray();
75  $this->assertSame($expected,$pageArray);
76  $this->publication->setData('pages', ' ');
77  $pageArray = $this->publication->getPageArray();
78  $this->assertSame($expected,$pageArray);
79  $expected = array(array('0'));
80  $this->publication->setData('pages', '0');
81  $pageArray = $this->publication->getPageArray();
82  $this->assertSame($expected,$pageArray);
83  }
84 
88  public function testGetStartingPage() {
89  $expected = 'i';
90  // strip prefix and spaces
91  $this->publication->setData('pages', 'pg. i-ix, 6-11, 19, 21');
92  $startingPage = $this->publication->getStartingPage();
93  $this->assertSame($expected,$startingPage);
94  // no spaces
95  $this->publication->setData('pages', 'i-ix,6-11,19,21');
96  $startingPage = $this->publication->getStartingPage();
97  $this->assertSame($expected,$startingPage);
98  // double-hyphen
99  $this->publication->setData('pages', 'i--ix,6--11,19,21');
100  $startingPage = $this->publication->getStartingPage();
101  $this->assertSame($expected,$startingPage);
102  // single page
103  $expected = '16';
104  $this->publication->setData('pages', '16');
105  $startingPage = $this->publication->getStartingPage();
106  $this->assertSame($expected,$startingPage);
107  // spaces in a range
108  $this->publication->setData('pages', '16 - 20');
109  $startingPage = $this->publication->getStartingPage();
110  $this->assertSame($expected,$startingPage);
111  // pages are alphanumeric
112  $expected = 'a6';
113  $this->publication->setData('pages', 'a6-a12,b43');
114  $startingPage = $this->publication->getStartingPage();
115  $this->assertSame($expected,$startingPage);
116  // inconsisent formatting
117  $this->publication->setData('pages', 'pp: a6 -a12, b43');
118  $startingPage = $this->publication->getStartingPage();
119  $this->assertSame($expected,$startingPage);
120  $this->publication->setData('pages', ' a6 -a12, b43 ');
121  $startingPage = $this->publication->getStartingPage();
122  $this->assertSame($expected,$startingPage);
123  // empty-ish values
124  $expected = '';
125  $this->publication->setData('pages', '');
126  $startingPage = $this->publication->getStartingPage();
127  $this->assertSame($expected,$startingPage);
128  $this->publication->setData('pages', ' ');
129  $startingPage = $this->publication->getStartingPage();
130  $this->assertSame($expected,$startingPage);
131  $expected = '0';
132  $this->publication->setData('pages', '0');
133  $startingPage = $this->publication->getStartingPage();
134  $this->assertSame($expected,$startingPage);
135  }
136 
140  public function testGetEndingPage() {
141  $expected = '21';
142  // strip prefix and spaces
143  $this->publication->setData('pages', 'pg. i-ix, 6-11, 19, 21');
144  $endingPage = $this->publication->getEndingPage();
145  $this->assertSame($expected,$endingPage);
146  // no spaces
147  $this->publication->setData('pages', 'i-ix,6-11,19,21');
148  $endingPage = $this->publication->getEndingPage();
149  $this->assertSame($expected,$endingPage);
150  // double-hyphen
151  $this->publication->setData('pages', 'i--ix,6--11,19,21');
152  $endingPage = $this->publication->getEndingPage();
153  $this->assertSame($expected,$endingPage);
154  // single page
155  $expected = '16';
156  $this->publication->setData('pages', '16');
157  $endingPage = $this->publication->getEndingPage();
158  $this->assertSame($expected,$endingPage);
159  // spaces in a range
160  $expected = '20';
161  $this->publication->setData('pages', '16 - 20');
162  $endingPage = $this->publication->getEndingPage();
163  $this->assertSame($expected,$endingPage);
164  // pages are alphanumeric
165  $expected = 'b43';
166  $this->publication->setData('pages', 'a6-a12,b43');
167  $endingPage = $this->publication->getEndingPage();
168  $this->assertSame($expected,$endingPage);
169  // inconsisent formatting
170  $this->publication->setData('pages', 'pp: a6 -a12, b43');
171  $endingPage = $this->publication->getEndingPage();
172  $this->assertSame($expected,$endingPage);
173  $this->publication->setData('pages', ' a6 -a12, b43 ');
174  $endingPage = $this->publication->getEndingPage();
175  $this->assertSame($expected,$endingPage);
176  // empty-ish values
177  $expected = '';
178  $this->publication->setData('pages', '');
179  $endingPage = $this->publication->getEndingPage();
180  $this->assertSame($expected,$endingPage);
181  $this->publication->setData('pages', ' ');
182  $endingPage = $this->publication->getEndingPage();
183  $this->assertSame($expected,$endingPage);
184  $expected = '0';
185  $this->publication->setData('pages', '0');
186  $endingPage = $this->publication->getEndingPage();
187  $this->assertSame($expected,$endingPage);
188  }
189 
190 }
191 
PublicationTest\testGetStartingPage
testGetStartingPage()
Definition: PublicationTest.php:88
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PublicationTest\setUp
setUp()
Definition: PublicationTest.php:20
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
PublicationTest\testGetEndingPage
testGetEndingPage()
Definition: PublicationTest.php:140
PublicationTest\testPageArray
testPageArray()
Definition: PublicationTest.php:35
PublicationTest
Test class for the Publication class.
Definition: PublicationTest.php:16
PublicationTest\tearDown
tearDown()
Definition: PublicationTest.php:26