1
+ <?php
2
+
3
+ class EMTTest {
4
+
5
+ public $ list = array ();
6
+ private $ info = array ();
7
+ private $ _class = false ;
8
+ public $ results = array ();
9
+ private $ count = 0 ;
10
+ public $ double_test = false ;
11
+
12
+ public $ grid = "A " ;
13
+ public $ grtitle = "Неклассифицированные " ;
14
+
15
+
16
+ protected function _dotest ($ test , $ layout )
17
+ {
18
+ $ typograph = new $ this ->_class ;
19
+ $ typograph ->set_tag_layout ($ layout );
20
+ $ ok = true ;
21
+ if (isset ($ test ['safetags ' ])) {
22
+ $ safetags = array ();
23
+ if (is_string ($ test ['safetags ' ])) $ safetags = array ($ test ['safetags ' ]);
24
+ else $ safetags = $ test ['safetags ' ];
25
+ foreach ($ safetags as $ st ) {
26
+ $ typograph ->add_safe_tag ($ st );
27
+ }
28
+ }
29
+ if (isset ($ test ['params ' ]) && is_array ($ test ['params ' ])) $ typograph ->setup ($ test ['params ' ]);
30
+
31
+ /*
32
+ if(isset($test['params']['map']) || isset($test['params']['maps']))
33
+ {
34
+ if(isset($test['params']['map']))
35
+ {
36
+ $ret['map'] = $test['params']['map'];
37
+ $ret['disable'] = $test['params']['map_disable'];
38
+ $ret['strict'] = $test['params']['map_strict'];
39
+ $test['params']['maps'] = array($ret);
40
+ }
41
+ if(is_array($test['params']['maps']))
42
+ {
43
+ foreach($test['params']['maps'] as $map)
44
+ {
45
+ $typograph->set_enable_map
46
+ ($map['map'],
47
+ isset($map['disable']) ? $map['disable'] : false,
48
+ isset($map['strict']) ? $map['strict'] : false
49
+ );
50
+ }
51
+ }
52
+ } else {
53
+ //if(isset($test['params']['ctl']))
54
+ if(isset($test['params']['no_paragraph']) && $test['params']['no_paragraph'])
55
+ {
56
+ $typograph->get_tret('Etc')->disable_rule('paragraphs');
57
+ }
58
+ }*/
59
+ $ typograph ->set_text ($ test ['text ' ]);
60
+ return $ typograph ->apply ();
61
+ }
62
+
63
+
64
+ protected function dotest ($ test )
65
+ {
66
+ $ result = $ this ->_dotest ($ test , 1 ); // STYLE
67
+ $ ret ['result ' ] = $ result ;
68
+
69
+ if ($ test ['result_classes ' ])
70
+ {
71
+ $ result = $ this ->_dotest ($ test , 2 ); // CLASSES
72
+ $ ret ['result_classes ' ] = $ result ;
73
+ }
74
+
75
+ $ ret ['error ' ] = false ;
76
+ if ($ ret ['result ' ] !== $ test ['result ' ]) $ ret ['error ' ] = true ;
77
+ if ($ test ['result_classes ' ]) if ($ ret ['result_classes ' ] !== $ test ['result_classes ' ]) $ ret ['error ' ] = true ;
78
+
79
+ if (!$ ret ['error ' ])
80
+ {
81
+ // повторное типографирование оттипографированного текста
82
+ if ($ this ->double_test )
83
+ {
84
+ $ test ['text ' ] = $ ret ['result ' ];
85
+ $ ret ['result_second ' ] = $ this ->_dotest ($ test , 1 ); // STYLE
86
+ if ($ test ['result_classes ' ])
87
+ {
88
+ $ test ['text ' ] = $ ret ['result_classes ' ];
89
+ $ ret ['result_classes_second ' ] = $ this ->_dotest ($ test , 2 ); // CLASSES
90
+ }
91
+
92
+ // повторное тестирование
93
+ if ($ ret ['result_second ' ] !== $ test ['result ' ]) $ ret ['error ' ] = true ;
94
+ if ($ test ['result_classes ' ]) if ($ ret ['result_classes_second ' ] !== $ test ['result_classes ' ]) $ ret ['error ' ] = true ;
95
+ }
96
+
97
+
98
+ }
99
+
100
+
101
+ return $ ret ;
102
+ }
103
+
104
+ /**
105
+ * Установить имя типографа класс
106
+ *
107
+ * @param string $class
108
+ */
109
+ public function set_typoclass ($ class )
110
+ {
111
+ $ this ->_class = $ class ;
112
+ }
113
+
114
+ /**
115
+ * Установить группу тестов
116
+ *
117
+ * @param string $id
118
+ * @param string $title
119
+ */
120
+ public function set_group ($ id , $ title )
121
+ {
122
+ $ this ->grid = $ id ;
123
+ $ this ->grtitle = $ title ;
124
+ }
125
+
126
+
127
+ /**
128
+ * Добавить тест
129
+ *
130
+ * @param string $text - тестируемый тест
131
+ * @param string $result - результат, который должен получится
132
+ * @param string $id - Идентификатор теста или название теста, если массив, то оба
133
+ * @param array/null $params - параметра (то что надо отключить/включить) и прочее, информация о тесте
134
+ */
135
+ public function add_test ($ text , $ result , $ result_classes = null , $ id = null , $ params = null , $ safetags = null )
136
+ {
137
+ $ arr = array (
138
+ 'text ' => $ text ,
139
+ 'result ' => $ result ,
140
+ 'result_classes ' => $ result_classes ,
141
+ );
142
+ if ($ params ) $ arr ['params ' ] = $ params ;
143
+ if ($ safetags ) $ arr ['safetags ' ] = $ safetags ;
144
+ if ($ id )
145
+ {
146
+ if (is_array ($ id ))
147
+ {
148
+ if (isset ($ id ['title ' ])) $ arr ['title ' ] = $ id ['title ' ];
149
+ if (isset ($ id ['id ' ])) $ arr ['id ' ] = $ id ['id ' ];
150
+ }
151
+ if (is_string ($ id )) $ arr ['title ' ] = $ id ;
152
+ }
153
+ $ arr ['grid ' ] = $ this ->grid ;
154
+ $ arr ['grtitle ' ] = $ this ->grtitle ;
155
+ $ this ->list [$ this ->count ] = $ arr ;
156
+ $ this ->count ++;
157
+ }
158
+
159
+
160
+
161
+ /**
162
+ * Получить информацию об тесте
163
+ *
164
+ *
165
+ * @param int $num
166
+ * @return array
167
+ * 'text' - входной текст
168
+ * 'result' - то, что должно получится
169
+ * 'params' - переданые параметры
170
+ */
171
+ public function get_test_info ($ num )
172
+ {
173
+ if ($ num >= $ this ->count ) return false ;
174
+ return $ this ->list [$ num ];
175
+ }
176
+
177
+ /**
178
+ * Получить количество тестов
179
+ *
180
+ * @return int
181
+ */
182
+ public function get_test_count ()
183
+ {
184
+ return $ this ->count ;
185
+ }
186
+
187
+
188
+ /**
189
+ * Протестировать типограф
190
+ *
191
+ * @return unknown
192
+ */
193
+ public function testit ()
194
+ {
195
+ if (count ($ this ->list )==0 ) return true ;
196
+ $ this ->info = array ();
197
+ $ this ->results = array ();
198
+ if (!$ this ->_class ) {
199
+ $ this ->results ['error ' ] = "Не задан класс типографа " ;
200
+ return false ;
201
+ }
202
+ $ this ->results ['raw ' ] = array ();
203
+ $ this ->results ['errors ' ] = array ();
204
+ $ num = 0 ;
205
+ $ num2 = 0 ;
206
+ $ prevgr = "A " ;
207
+ foreach ($ this ->list as $ test )
208
+ {
209
+ if ($ test ['grid ' ]!=$ prevgr ) $ num2 =0 ;
210
+ $ prevgr = $ test ['grid ' ];
211
+ $ num ++;
212
+ $ num2 ++;
213
+ $ ret = $ this ->dotest ($ test );
214
+ $ test ['grnum ' ] = $ num2 ;
215
+ $ this ->results ['raw ' ][$ num ] = $ ret ;
216
+ if ($ ret ['error ' ])
217
+ {
218
+ $ this ->results ['errors ' ][] = array (
219
+ 'num ' => $ num ,
220
+ );
221
+ }
222
+ $ this ->on_tested ($ num , $ test , $ ret );
223
+ }
224
+ if (count ($ this ->results ['errors ' ])>0 ) return false ;
225
+ return true ;
226
+ }
227
+
228
+ /**
229
+ * То случается при обработке
230
+ *
231
+ * @param ште $num
232
+ * @param array $test
233
+ * @param array $ret
234
+ */
235
+ public function on_tested ($ num , $ test , $ ret )
236
+ {
237
+
238
+ }
239
+
240
+ }
241
+
242
+
243
+ ?>
0 commit comments