brightpearl-cli 1.4.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,246 @@
1
+ <?php
2
+ namespace testHelpers\Accounts\AllocatePayments;
3
+
4
+ use Lib_Dto_Accounts_Journal;
5
+ use Lib_Dto_Accounts_AllocatePayment_JournalWithBalance;
6
+ use Lib_Dto_Collection;
7
+
8
+ /**
9
+ * Test data providers for the allocate payments screen
10
+ *
11
+ * @since 10/06/2010
12
+ * @package UnitTests
13
+ * @subpackage TestHelpers
14
+ */
15
+ class JournalEntries
16
+ {
17
+ /**
18
+ * Returns unbalanced journal entries for customer as the DAO would
19
+ * @return array
20
+ */
21
+ public static function journalRowsForCustomer()
22
+ {
23
+ $entries = array(
24
+ JournalEntries::createJournalDto(1, 1, '100000', 'accnt1', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 100', 0, 100, '0000-00-00 00:00:00'),
25
+ JournalEntries::createJournalDto(2, 2, '100000', 'accnt2', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 250', 0, 250, '0000-00-00 00:00:00'),
26
+ JournalEntries::createJournalDto(3, 3, '100000', 'SI-100000', 'SI', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 500, 0, '0000-00-00 00:00:00'),
27
+ JournalEntries::createJournalDto(4, 4, '100001', 'SI-100001', 'SI', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 200, 0, '0000-00-00 00:00:00'),
28
+ JournalEntries::createJournalDto(5, 5, '100002', 'accnt5', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 40', 0, 40, '0000-00-00 00:00:00'),
29
+ JournalEntries::createJournalDto(6, 6, '100002', 'SI-100002', 'SI', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 50, 0, '0000-00-00 00:00:00'),
30
+ JournalEntries::createJournalDto(9, 9, '100004', 'SC-100004', 'SC', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 0, 300, '0000-00-00 00:00:00'),
31
+ JournalEntries::createJournalDto(10, 10, '100005', 'SC-100005', 'SC', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 0, 400, '0000-00-00 00:00:00'),
32
+ JournalEntries::createJournalDto(11, 11, '100005', 'SC-100005', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'payment 1', 100, 0, '0000-00-00 00:00:00'),
33
+ JournalEntries::createJournalDto(12, 12, '100005', 'SC-100005', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'payment 2', 50, 0, '0000-00-00 00:00:00'),
34
+ JournalEntries::createJournalDto(13, 13, '100005', 'SC-100005', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'payment 3', 200, 0, '0000-00-00 00:00:00'),
35
+ JournalEntries::createJournalDto(14, 14, '100006', 'accnt14', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 1 of 1', 20, 0, '0000-00-00 00:00:00'),
36
+ JournalEntries::createJournalDto(15, 15, '100006', 'SC-100006', 'SC', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 0, 30, '0000-00-00 00:00:00'),
37
+ JournalEntries::createJournalDto(18, 18, 'accnt18', 'accnt18', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'loose pay for 45', 0, 45, '0000-00-00 00:00:00'),
38
+ JournalEntries::createJournalDto(19, 19, 'accnt19', 'accnt19', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'loose pay for -65', 65, 0, '0000-00-00 00:00:00'),
39
+ JournalEntries::createJournalDto(20, 20, '100008', 'accnt20', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 1 for 15', 0, 15, '0000-00-00 00:00:00'),
40
+ JournalEntries::createJournalDto(21, 21, '100008', 'accnt21', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 15:42:31', 'pay 2 for 35', 0, 35, '0000-00-00 00:00:00'),
41
+ JournalEntries::createJournalDto(23, 23, '', 'Ovr10000923', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'overpayment', 0, 20, '0000-00-00 00:00:00'),
42
+ JournalEntries::createJournalDto(25, 25, 'OnAccount25', 'OnAccount25', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'overpayment of 80', 0, 30, '0000-00-00 00:00:00'),
43
+ JournalEntries::createJournalDto(47, 47, '100021', 'accnt47', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 1 for 10', 10, 0, '0000-00-00 00:00:00'),
44
+ JournalEntries::createJournalDto(48, 48, '100021', 'accnt48', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 15:42:31', 'pay 2 for 15', 15, 0, '0000-00-00 00:00:00'),
45
+ JournalEntries::createJournalDto(61, 61, 'SI-100011', 'SI-100011', 'SI', '2013-06-10', '2013-07-10', '2013-06-10 14:42:31', 'not paid', 120, 0, '0000-00-00 00:00:00'),
46
+ JournalEntries::createJournalDto(62, 62, 'SC-100012', 'SC-100012', 'SC', '2013-06-10', '2013-07-10', '2013-06-10 14:42:31', 'not paid', 0, 150, '0000-00-00 00:00:00'),
47
+ JournalEntries::createJournalDto(63, 63, 'accnt20', 'accnt20', 'SR', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'dfghj', 0, 45, '0000-00-00 00:00:00'),
48
+ JournalEntries::createJournalDto(64, 64, 'accnt20', 'accnt20', 'SR', '2013-06-17', '0000-00-00', '2013-06-17 14:42:31', 'jnhgf', 25, 0, '0000-00-00 00:00:00'),
49
+ JournalEntries::createJournalDto(64, 64, 'accnt22', 'accnt22', 'SR', '2013-06-11', '0000-00-00', '2013-06-11 14:42:31', 'ytre', 30, 0, '0000-00-00 00:00:00'),
50
+ JournalEntries::createJournalDto(65, 65, 'accnt22', 'accnt23', 'SR', '2013-06-18', '0000-00-00', '2013-06-18 14:42:31', 'mnbv', 0, 5, '0000-00-00 00:00:00'),
51
+ );
52
+
53
+ return JournalEntries::addEntriesToCollection($entries);
54
+ }
55
+
56
+ /**
57
+ * Returns grouped journal entries for customer
58
+ * @return array
59
+ */
60
+ public static function groupedJournalsForCustomer()
61
+ {
62
+ $entries = array(
63
+ JournalEntries::createJournalWithBalanceDto('100000', 'SI-100000', 3, 'SI', 'invoice', '2013-06-10', '2013-06-10', 500, 350, 150),
64
+ JournalEntries::createJournalWithBalanceDto('100001', 'SI-100001', 4, 'SI', 'invoice', '2013-06-10', '2013-06-10', 200, 0, 200),
65
+ JournalEntries::createJournalWithBalanceDto('100002', 'SI-100002', 6, 'SI', 'invoice', '2013-06-10', '2013-06-10', 50, 40, 10),
66
+ JournalEntries::createJournalWithBalanceDto('100004', 'SC-100004', 9, 'SC', 'credit', '2013-06-10', '2013-06-10', -300, 0, -300),
67
+ JournalEntries::createJournalWithBalanceDto('100005', 'SC-100005', 10, 'SC', 'credit', '2013-06-10', '2013-06-10', -400, -350, -50),
68
+ JournalEntries::createJournalWithBalanceDto('100006', 'SC-100006', 15, 'SC', 'credit', '2013-06-10', '2013-06-10', -30, -20, -10),
69
+ JournalEntries::createJournalWithBalanceDto('accnt18', 'accnt18', 18, 'SR', 'credit', '2013-06-10', '0000-00-00', -45, 0, -45),
70
+ JournalEntries::createJournalWithBalanceDto('accnt19', 'accnt19', 19, 'SR', 'invoice', '2013-06-10', '0000-00-00', 65, 0, 65),
71
+ JournalEntries::createJournalWithBalanceDto('100008', 'accnt20', 20, 'SR', 'credit', '2013-06-10', '0000-00-00', -50, 0, -50),
72
+ JournalEntries::createJournalWithBalanceDto('', 'Ovr10000923', 23, 'SR', 'credit', '2013-06-10', '0000-00-00', -20, 0, -20),
73
+ JournalEntries::createJournalWithBalanceDto('OnAccount25', 'OnAccount25', 25, 'SR', 'credit', '2013-06-10', '0000-00-00', -30, 0, -30),
74
+ JournalEntries::createJournalWithBalanceDto('100021', 'accnt47', 47, 'SR', 'invoice', '2013-06-10', '0000-00-00', 25, 0, 25),
75
+ JournalEntries::createJournalWithBalanceDto('SI-100011', 'SI-100011', 61, 'SI', 'invoice', '2013-06-10', '2013-07-10', 120, 0, 120),
76
+ JournalEntries::createJournalWithBalanceDto('SC-100012', 'SC-100012', 62, 'SC', 'credit', '2013-06-10', '2013-07-10', -150, 0, -150),
77
+ JournalEntries::createJournalWithBalanceDto('accnt20', 'accnt20', 63, 'SR', 'credit', '2013-06-10', '0000-00-00', -45, -25, -20),
78
+ JournalEntries::createJournalWithBalanceDto('accnt22', 'accnt22', 64, 'SR', 'invoice', '2013-06-11', '0000-00-00', 30, 5, 25),
79
+ );
80
+
81
+ return JournalEntries::addEntriesToCollection($entries);
82
+ }
83
+
84
+ /**
85
+ * Returns unbalanced journal entries for supplier as the DAO would
86
+ * @return array
87
+ */
88
+ public static function journalRowsForSupplier()
89
+ {
90
+ $entries = array(
91
+ JournalEntries::createJournalDto(26, 26, '100011', 'hgfdsa', 'PI', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 0, 200, '0000-00-00 00:00:00'),
92
+ JournalEntries::createJournalDto(29, 29, '100013', 'sdfghj', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 1 for 100', 100, 0, '0000-00-00 00:00:00'),
93
+ JournalEntries::createJournalDto(30, 30, '100013', 'sdfghj', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 2 for 150', 150, 0, '0000-00-00 00:00:00'),
94
+ JournalEntries::createJournalDto(31, 31, '100013', 'sdfghj', 'PI', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 0, 500, '0000-00-00 00:00:00'),
95
+ JournalEntries::createJournalDto(32, 32, '100013', 'sdfghj', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 3 for 200', 200, 0, '0000-00-00 00:00:00'),
96
+ JournalEntries::createJournalDto(33, 33, '100014', 'hgfds', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'part pay', 55, 0, '0000-00-00 00:00:00'),
97
+ JournalEntries::createJournalDto(34, 34, '100014', 'hgfds', 'PI', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 0, 70, '0000-00-00 00:00:00'),
98
+ JournalEntries::createJournalDto(35, 35, '100015', 'accnt35', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 1 for 35', 35, 0, '0000-00-00 00:00:00'),
99
+ JournalEntries::createJournalDto(36, 36, '100015', 'accnt36', 'PP', '2013-06-11', '0000-00-00', '2013-06-11 16:42:31', 'pay 2 for 30', 30, 0, '0000-00-00 00:00:00'),
100
+ JournalEntries::createJournalDto(37, 37, '', 'Ovr10001637', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'overpaid 90', 30, 0, '0000-00-00 00:00:00'),
101
+ JournalEntries::createJournalDto(40, 40, '100018', 'jhgfdsa', 'PC', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 80, 0, '0000-00-00 00:00:00'),
102
+ JournalEntries::createJournalDto(41, 41, 'OnAccount41', 'OnAccount41', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'overpay 70', 20, 0, '0000-00-00 00:00:00'),
103
+ JournalEntries::createJournalDto(43, 43, 'accnt43', 'accnt43', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'loose pay for 45', 45, 0, '0000-00-00 00:00:00'),
104
+ JournalEntries::createJournalDto(44, 44, 'accnt44', 'accnt44', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'loose pay for -65', 0, 65, '0000-00-00 00:00:00'),
105
+ JournalEntries::createJournalDto(46, 46, '100020', 'bhgvcxz', 'PC', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 200, 0, '0000-00-00 00:00:00'),
106
+ JournalEntries::createJournalDto(49, 49, '100020', 'bhgvcxz', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'kjhgfds', 0, 100, '0000-00-00 00:00:00'),
107
+ JournalEntries::createJournalDto(50, 50, '100020', 'bhgvcxz', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'lmkjnbhgvfcx', 0, 50, '0000-00-00 00:00:00'),
108
+ JournalEntries::createJournalDto(51, 51, '100022', 'fgthj', 'PC', '2013-06-10', '2013-06-10', '2013-06-10 14:42:31', '', 30, 0, '0000-00-00 00:00:00'),
109
+ JournalEntries::createJournalDto(52, 52, '100022', 'fgthj', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'jhgvfcxdsz', 0, 20, '0000-00-00 00:00:00'),
110
+ JournalEntries::createJournalDto(53, 53, '100023', 'accnt53', 'PP', '2013-06-10', '0000-00-00', '2013-06-10 14:42:31', 'pay 15', 0, 15, '0000-00-00 00:00:00'),
111
+ JournalEntries::createJournalDto(54, 54, '100023', 'accnt54', 'PP', '2013-06-12', '0000-00-00', '2013-06-12 11:42:31', 'pay 10', 0, 10, '0000-00-00 00:00:00'),
112
+ JournalEntries::createJournalDto(60, 60, 'Bill-60', '345345345', 'PI', '2013-06-10', '2013-07-10', '2013-06-10 14:42:31', 'not paid', 0, 120, '0000-00-00 00:00:00'),
113
+ JournalEntries::createJournalDto(67, 67, 'Credit-67', 'someCreditnotpaid-12', 'PC', '2013-06-10', '2013-07-10', '2013-06-10 14:42:31', '', 70, 0, '0000-00-00 00:00:00'),
114
+ JournalEntries::createJournalDto(68, 68, 'accnt20', 'accnt20', 'PP', '2013-06-18', '0000-00-00', '2013-06-18 14:42:31', 'dfghj', 45, 0, '0000-00-00 00:00:00'),
115
+ JournalEntries::createJournalDto(69, 69, 'accnt20', 'accnt20', 'PP', '2013-06-18', '0000-00-00', '2013-06-18 16:42:31', 'jnhgf', 0, 25, '0000-00-00 00:00:00'),
116
+ JournalEntries::createJournalDto(70, 70, 'accnt22', 'accnt22', 'PP', '2013-06-16', '0000-00-00', '2013-06-16 14:42:31', 'ytre', 0, 30, '0000-00-00 00:00:00'),
117
+ JournalEntries::createJournalDto(71, 71, 'accnt22', 'accnt71', 'PP', '2013-06-18', '0000-00-00', '2013-06-18 15:42:31', 'mnbv', 5, 0, '0000-00-00 00:00:00'),
118
+ );
119
+
120
+ return JournalEntries::addEntriesToCollection($entries);
121
+ }
122
+
123
+ /**
124
+ * Returns grouped journal entries for supplier
125
+ * @return array
126
+ */
127
+ public static function groupedJournalsForSupplier()
128
+ {
129
+ $entries = array(
130
+ JournalEntries::createJournalWithBalanceDto('100011', 'hgfdsa', 26, 'PI', 'invoice', '2013-06-10', '2013-06-10', 200, 0, 200),
131
+ JournalEntries::createJournalWithBalanceDto('100013', 'sdfghj', 31, 'PI', 'invoice', '2013-06-10', '2013-06-10', 500, 450, 50),
132
+ JournalEntries::createJournalWithBalanceDto('100014', 'hgfds', 34, 'PI', 'invoice', '2013-06-10', '2013-06-10', 70, 55, 15),
133
+ JournalEntries::createJournalWithBalanceDto('100015', 'accnt35', 35, 'PP', 'credit', '2013-06-10', '0000-00-00', -65, 0, -65),
134
+ JournalEntries::createJournalWithBalanceDto('', 'Ovr10001637', 37, 'PP', 'credit', '2013-06-10', '0000-00-00', -30, 0, -30),
135
+ JournalEntries::createJournalWithBalanceDto('100018', 'jhgfdsa', 40, 'PC', 'credit', '2013-06-10', '2013-06-10', -80, 0, -80),
136
+ JournalEntries::createJournalWithBalanceDto('OnAccount41', 'OnAccount41', 41, 'PP', 'credit', '2013-06-10', '0000-00-00', -20, 0, -20),
137
+ JournalEntries::createJournalWithBalanceDto('accnt43', 'accnt43', 43, 'PP', 'credit', '2013-06-10', '0000-00-00', -45, 0, -45),
138
+ JournalEntries::createJournalWithBalanceDto('accnt44', 'accnt44', 44, 'PP', 'invoice', '2013-06-10', '0000-00-00', 65, 0, 65),
139
+ JournalEntries::createJournalWithBalanceDto('100020', 'bhgvcxz', 46, 'PC', 'credit', '2013-06-10', '2013-06-10', -200, -150, -50),
140
+ JournalEntries::createJournalWithBalanceDto('100022', 'fgthj', 51, 'PC', 'credit', '2013-06-10', '2013-06-10', -30, -20, -10),
141
+ JournalEntries::createJournalWithBalanceDto('100023', 'accnt53', 53, 'PP', 'invoice', '2013-06-10', '0000-00-00', 25, 0, 25),
142
+ JournalEntries::createJournalWithBalanceDto('Bill-60', '345345345', 60, 'PI', 'invoice', '2013-06-10', '2013-07-10', 120, 0, 120),
143
+ JournalEntries::createJournalWithBalanceDto('Credit-67', 'someCreditnotpaid-12', 67, 'PC', 'credit', '2013-06-10', '2013-07-10', -70, 0, -70),
144
+ JournalEntries::createJournalWithBalanceDto('accnt20', 'accnt20', 68, 'PP', 'credit', '2013-06-18', '0000-00-00', -45, -25, -20),
145
+ JournalEntries::createJournalWithBalanceDto('accnt22', 'accnt22', 70, 'PP', 'invoice', '2013-06-16', '0000-00-00', 30, 5, 25),
146
+ );
147
+
148
+ return JournalEntries::addEntriesToCollection($entries);
149
+ }
150
+
151
+ /**
152
+ * Returns 110 Rows for testing the 100 row limit in JournalTest
153
+ * @param $invoiceType (Use SI for Customer, PI for Supplier).
154
+ * @return Lib_Dto_Collection
155
+ */
156
+ public static function journalRowsToTestRowLimit($invoiceType)
157
+ {
158
+ $entries = array();
159
+ for ($i = 0; $i < 110; $i++) {
160
+ $entries[] = JournalEntries::createJournalDto($i, $i, '100' . str_pad($i, 3, '0', STR_PAD_LEFT), 'abcdef', $invoiceType, '2000-01-01', '2000-01-01', '2000-01-01 00:00:00', '', 0, 200, '0000-00-00 00:00:00');
161
+ }
162
+ return JournalEntries::addEntriesToCollection($entries);
163
+ }
164
+
165
+ /**
166
+ * Creates a journal DTO
167
+ * @param integer $id
168
+ * @param integer $journalId
169
+ * @param string $transId
170
+ * @param string $invoiceRef
171
+ * @param string $type
172
+ * @param string $date
173
+ * @param string $dateDue
174
+ * @param string $dateEntered
175
+ * @param string $details
176
+ * @param float $debit
177
+ * @param float $credit
178
+ * @param string $reconcileVat
179
+ * @return Lib_Dto_Accounts_Journal
180
+ */
181
+ private static function createJournalDto($id, $journalId, $invoiceRef, $transId, $type, $date, $dateDue, $dateEntered, $details, $debit, $credit, $reconcileVat)
182
+ {
183
+ $entry = new Lib_Dto_Accounts_Journal();
184
+ $entry->setId($id);
185
+ $entry->setJournalId($journalId);
186
+ $entry->setTransId($transId);
187
+ $entry->setInvoiceRef($invoiceRef);
188
+ $entry->setType($type);
189
+ $entry->setDate($date);
190
+ $entry->setDateDue($dateDue);
191
+ $entry->setDateEntered($dateEntered);
192
+ $entry->setDetails($details);
193
+ $entry->setDebit($debit);
194
+ $entry->setCredit($credit);
195
+ $entry->setReconcileVat($reconcileVat);
196
+
197
+ return $entry;
198
+ }
199
+
200
+ /**
201
+ * Creates a journal with balance DTO
202
+ * @param string $transId
203
+ * @param string $invoiceRef
204
+ * @param integer $journalId
205
+ * @param string $type
206
+ * @param string $classification
207
+ * @param string $date
208
+ * @param string $dateDue
209
+ * @param float $total
210
+ * @param float $paidToDate
211
+ * @param float $outstanding
212
+ * @return \Lib_Dto_Accounts_AllocatePayment_JournalWithBalance
213
+ */
214
+ private static function createJournalWithBalanceDto($invoiceRef, $transId, $journalId, $type, $classification, $date, $dateDue, $total, $paidToDate, $outstanding)
215
+ {
216
+ $entry = new Lib_Dto_Accounts_AllocatePayment_JournalWithBalance();
217
+ $entry->setTransId($transId);
218
+ $entry->setInvoiceRef($invoiceRef);
219
+ $entry->setJournalId($journalId);
220
+ $entry->setType($type);
221
+ $entry->setClassification($classification);
222
+ $entry->setDate($date);
223
+ $entry->setDateDue($dateDue);
224
+ $entry->setTotal($total);
225
+ $entry->setPaidToDate($paidToDate);
226
+ $entry->setOutstanding($outstanding);
227
+
228
+ return $entry;
229
+ }
230
+
231
+ /**
232
+ * Adds journal entries to a collection
233
+ * @param array $entries
234
+ * @return Lib_Dto_Collection
235
+ */
236
+ private static function addEntriesToCollection(array $entries)
237
+ {
238
+ $collection = new Lib_Dto_Collection();
239
+
240
+ foreach ($entries as $entry) {
241
+ $collection->addDto($entry);
242
+ }
243
+
244
+ return $collection;
245
+ }
246
+ }
@@ -0,0 +1,101 @@
1
+ <?php
2
+ /**
3
+ * Testing version of PEARL_msg
4
+ *
5
+ * @since 05/07/2010
6
+ * @package UnitTests
7
+ * @subpackage TestHelpers
8
+ */
9
+ class TestHelpers_Message
10
+ implements \Lib_Message_Interface
11
+ {
12
+ /**
13
+ * Stores set messages
14
+ *
15
+ * @var array
16
+ */
17
+ protected $_messages = array();
18
+
19
+ /**
20
+ * Add a message to the stack
21
+ *
22
+ * @param string $message
23
+ * @param string $type
24
+ * @return boolean
25
+ */
26
+ public function addMessage($message, $type = 'message')
27
+ {
28
+ if (!isset($this->_messages[$type])) {
29
+ $this->_messages[$type] = array();
30
+ }
31
+ $this->_messages[$type][] = $message;
32
+ return true;
33
+ }
34
+
35
+ /**
36
+ * Return the msg stack ready for AJAX or an alert()
37
+ *
38
+ * @return string
39
+ */
40
+ public function javaScriptMessageStack()
41
+ {
42
+ /* Not implemented yet */
43
+ }
44
+
45
+ /**
46
+ * Display the stack ready for on screen HTML
47
+ *
48
+ * @param boolean $return Return or echo
49
+ * @return string
50
+ */
51
+ public function showMessageStack($return = false)
52
+ {
53
+ /* Not implemented yet */
54
+ }
55
+
56
+ /**
57
+ * Check for messages on the stack
58
+ *
59
+ * @param string $type
60
+ * @return boolean
61
+ */
62
+ public function hasMessages($type = 'all')
63
+ {
64
+ if ('all' == $type) {
65
+ $count = 0;
66
+ foreach ($this->_messages AS $type => $message) {
67
+ if (count($message) > 0) {
68
+ return true;
69
+ }
70
+ }
71
+ return false;
72
+ }
73
+ if (!isset($this->_messages[$type])) {
74
+ return false;
75
+ }
76
+ return (count($this->_messages[$type]) != 0);
77
+ }
78
+
79
+ /**
80
+ * Additional message for testing
81
+ *
82
+ * @return array
83
+ */
84
+ public function getMessages()
85
+ {
86
+ return $this->_messages;
87
+ }
88
+
89
+
90
+ /**
91
+ * Clear messages
92
+ *
93
+ * @param string $type
94
+ * @throws Exception
95
+ * @return $this *Provides a fluent interface
96
+ */
97
+ public function clearMessages($type = null)
98
+ {
99
+ throw new Exception('Not implemented here');
100
+ }
101
+ }
@@ -0,0 +1,404 @@
1
+ <?php
2
+ /**
3
+ * Test data providers for unit tests
4
+ *
5
+ * @since 17/05/2010
6
+ * @package UnitTests
7
+ * @subpackage TestHelpers
8
+ */
9
+ class TestHelpers_Providers
10
+ {
11
+ /**
12
+ * Provides variables that are 'not string' type
13
+ *
14
+ * @return array Mixed data types
15
+ */
16
+ public static function notString()
17
+ {
18
+ return array(
19
+ array(true),
20
+ array(1),
21
+ array(1.5),
22
+ array(new StdClass()),
23
+ array(null),
24
+ array(array('get', 'up')),
25
+ array(array('get on up')),
26
+ array(-5),
27
+ );
28
+ }
29
+
30
+ /**
31
+ * Provides variables that are 'not string' and 'not null' type
32
+ *
33
+ * @return array Mixed data types
34
+ */
35
+ public static function notStringAndNotNull()
36
+ {
37
+ return array(
38
+ array(true),
39
+ array(1),
40
+ array(1.5),
41
+ array(new StdClass()),
42
+ array(array('get', 'up')),
43
+ array(array('get on up')),
44
+ array(-5),
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Provider of 'not float' type
50
+ *
51
+ * @return array
52
+ */
53
+ public static function notFloat()
54
+ {
55
+ return array(
56
+ array('stay on the scene'),
57
+ array(array('like', 'a', 'sex', 'machine')),
58
+ array(1970),
59
+ array(true),
60
+ array(null),
61
+ array(new StdClass()),
62
+ array(array(5.15)),
63
+ array(array()),
64
+ );
65
+ }
66
+
67
+ /**
68
+ * Provider of 'not positive number'
69
+ *
70
+ * @return array
71
+ */
72
+ public static function notPositiveNumber()
73
+ {
74
+ return array(
75
+ array("Fellas, I'm ready to get up and do my thing"),
76
+ array(array('yeah', 'go', 'ahead!')),
77
+ array(-2.25),
78
+ array(-1970),
79
+ array(true),
80
+ array(null),
81
+ array(new StdClass()),
82
+ array(array(2.25)),
83
+ array(array()),
84
+ array(''),
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Provider of 'not integer' type
90
+ *
91
+ * @return array
92
+ */
93
+ public static function notInteger()
94
+ {
95
+ return array(
96
+ array("Fellas, I'm ready to get up and do my thing"),
97
+ array(array('yeah', 'go', 'ahead!')),
98
+ array(2.25),
99
+ array(true),
100
+ array(null),
101
+ array(new StdClass()),
102
+ array(array(2.25)),
103
+ array(array()),
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Provider of not integer or not object type
109
+ *
110
+ * @return array
111
+ */
112
+ public static function notIntegerOrObject()
113
+ {
114
+ return array(
115
+ array("Fellas, I'm ready to get up and do my thing"),
116
+ array(array('yeah', 'go', 'ahead!')),
117
+ array(2.25),
118
+ array(true),
119
+ array(null),
120
+ array(array(2.25)),
121
+ array(array()),
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Provider of not integer or null
127
+ *
128
+ * @return array
129
+ */
130
+ public static function notIntegerOrNull()
131
+ {
132
+ return array(
133
+ array("Fellas, I'm ready to get up and do my thing"),
134
+ array(array('yeah', 'go', 'ahead!')),
135
+ array(2.25),
136
+ array(true),
137
+ array(new StdClass()),
138
+ array(array(2.25)),
139
+ array(array()),
140
+ );
141
+ }
142
+
143
+ /**
144
+ * Provider of 'not positive integer'
145
+ *
146
+ * @return array
147
+ */
148
+ public static function notPositiveInteger()
149
+ {
150
+ $data = self::notInteger();
151
+ $data[] = array(-1);
152
+ $data[] = array(-368);
153
+ return $data;
154
+ }
155
+
156
+ /**
157
+ * Provider of 'not positive integer or not null'
158
+ *
159
+ * @return array
160
+ */
161
+ public static function notPositiveIntegerOrNull()
162
+ {
163
+ $data = self::notIntegerOrNull();
164
+ $data[] = array(-1);
165
+ $data[] = array(-368);
166
+ return $data;
167
+ }
168
+
169
+ /**
170
+ * Provider of 'not boolean'
171
+ *
172
+ * @return array
173
+ */
174
+ public static function notBoolean()
175
+ {
176
+ return array(
177
+ array('it starts with'),
178
+ array(null),
179
+ array(new stdClass),
180
+ array(array('one', 'thing')),
181
+ array(2.25),
182
+ array(-1),
183
+ array(array()),
184
+ array('NthEnd'),
185
+ );
186
+ }
187
+
188
+ /**
189
+ * Provider of 'not object'
190
+ *
191
+ * @return array
192
+ */
193
+ public static function notObject()
194
+ {
195
+ return array(
196
+ array('it starts with'),
197
+ array(null),
198
+ array(array('one', 'thing')),
199
+ array(2.25),
200
+ array(-1),
201
+ array(array()),
202
+ array('NthEnd'),
203
+ array(false),
204
+ array(25),
205
+ );
206
+ }
207
+
208
+ /**
209
+ * Provider of 'not string or integer' type
210
+ *
211
+ * @return array
212
+ */
213
+ public static function notStringOrInteger()
214
+ {
215
+ return array(
216
+ array(array('Stay on the scene')),
217
+ array(array()),
218
+ array(array('Bobby!', 'Should I take', "'em to the bridge?")),
219
+ array(false),
220
+ array(new StdClass()),
221
+ array(null),
222
+ array(2.25),
223
+ );
224
+ }
225
+
226
+ /**
227
+ * Invalid YYYY-MM-DD string
228
+ *
229
+ * @return array
230
+ */
231
+ public static function badYYYYMMDD()
232
+ {
233
+ return array(
234
+ array('1.21GigaWatts?'),
235
+ array('15/11/1955'),
236
+ array('11/15/1955'),
237
+ array('1955-15-11'),
238
+ array('1955/11/15'),
239
+ array('3000-01-01'),
240
+ array('0000-00-00'),
241
+ array('1234-56-78'),
242
+ );
243
+ }
244
+
245
+ /**
246
+ * Provider of not string or null
247
+ *
248
+ * @return array
249
+ */
250
+ public static function notStringOrNull()
251
+ {
252
+ return array(
253
+ array(true),
254
+ array(1),
255
+ array(1.5),
256
+ array(new StdClass()),
257
+ array(array('hit me', 'with your')),
258
+ array(array('rhythmn stick')),
259
+ array(-5),
260
+ );
261
+ }
262
+
263
+ /**
264
+ * Provider of not populated string
265
+ *
266
+ * @return array
267
+ */
268
+ public static function notPopulatedString()
269
+ {
270
+ $data = self::notString();
271
+ $data[] = array('');
272
+ return $data;
273
+ }
274
+
275
+ /**
276
+ * Provider of 'not array' types
277
+ *
278
+ * @return array
279
+ */
280
+ public static function notArray()
281
+ {
282
+ $data = self::notArrayAndNotNull();
283
+ $data[] = array(null);
284
+ return $data;
285
+ }
286
+
287
+ /**
288
+ * Provider of 'not array' and 'not null' types
289
+ *
290
+ * @return array
291
+ */
292
+ public static function notArrayAndNotNull()
293
+ {
294
+ return array(
295
+ array("I ate his liver with some fava beans and a nice chianti..."),
296
+ array(1),
297
+ array(2.25),
298
+ array(true),
299
+ // array(new StdClass()),
300
+ );
301
+ }
302
+
303
+ /**
304
+ * Provider of 'not populated array' types
305
+ *
306
+ * @return array
307
+ */
308
+ public static function notPopulatedArray()
309
+ {
310
+ $data = self::notArray();
311
+ $data[] = array(array());
312
+ return $data;
313
+ }
314
+
315
+ /**
316
+ * Provider of on-numeric variables
317
+ *
318
+ * @return array
319
+ */
320
+ public static function notNumericVariable()
321
+ {
322
+ return array(
323
+ array("Houston we have a problem"),
324
+ array(true),
325
+ array(null),
326
+ array(new StdClass()),
327
+ array(array()),
328
+ );
329
+ }
330
+
331
+ /**
332
+ * Provider of variables that are not numeric strings
333
+ *
334
+ * @return array
335
+ */
336
+ public static function notNumericString()
337
+ {
338
+ return array(
339
+ array("Houston we have a problem"),
340
+ array(true),
341
+ array(new StdClass()),
342
+ array(array()),
343
+ array(0),
344
+ array(100),
345
+ array(-10),
346
+ array(3.5),
347
+ array("nine"),
348
+ );
349
+ }
350
+
351
+ /**
352
+ * Not integer or float
353
+ *
354
+ * @return string
355
+ */
356
+ public static function notIntegerOrFloat()
357
+ {
358
+ return array(
359
+ array('it starts with'),
360
+ array(null),
361
+ array(new stdClass),
362
+ array(array('one', 'thing')),
363
+ array(array()),
364
+ array('NthEnd'),
365
+ array(true)
366
+ );
367
+ }
368
+
369
+ /**
370
+ * Provider of 'not array' and 'not integer' types
371
+ *
372
+ * @return array
373
+ */
374
+ public static function notArrayOrInteger()
375
+ {
376
+ return array(
377
+ array("I ate his liver with some fava beans and a nice chianti..."),
378
+ array(2.25),
379
+ array(true),
380
+ array(null),
381
+ array(new StdClass()),
382
+ );
383
+ }
384
+
385
+ // /**
386
+ // * Provider of a random single digit (0-9) integer
387
+ // *
388
+ // * @return array
389
+ // */
390
+ // public static function randomSingleDigitInteger()
391
+ // {
392
+ // return rand(0,9);
393
+ // }
394
+ //
395
+ // /**
396
+ // * Provider of a random single digit (1-9) integer
397
+ // *
398
+ // * @return array
399
+ // */
400
+ // public static function randomSingleDigitIntegerNotZero()
401
+ // {
402
+ // return rand(1,9);
403
+ // }
404
+ }