This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
test-basic.php
1637 lines (1457 loc) · 89.3 KB
/
test-basic.php
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
class BasicTest extends SimpleFields_TestCase {
/*
setUpBeforeClass
tearDownAfterClass
setUp
tearDown
*/
public static $post_id_for_manual_tests;
function testSetupCorrectly() {
$this->assertTrue( class_exists("simple_fields"), "Simple Fields class must exist" );
$this->assertTrue( isset( $GLOBALS['sf']), "Global variable must be set" );
}
function testCache() {
// cache namespace key must be numeric
$this->assertTrue( is_numeric( self::$sf->ns_key ) );
$old_ns = self::$sf->ns_key;
// clear caches and check that key is increased
self::$sf->clear_caches();
$this->assertTrue( is_numeric( self::$sf->ns_key ) );
$this->assertTrue( self::$sf->ns_key > $old_ns );
// sf_d( self::$sf->ns_key );
// check that cache stores and gets things correctly
$key = 'simple_fields_unittest_' . self::$sf->ns_key . '_cache_test';
$group = "simple_fields";
$val = rand_str();
$this->assertFalse( wp_cache_get( $key, $group), "Cached value must not exist" );
wp_cache_set($key , $val, $group );
$cached_val = wp_cache_get( $key, $group);
$this->assertEquals( $cached_val, $val, "Value from cache must be same as orginal value" );
// clear caches again and make sure values not in cache anymore
self::$sf->clear_caches();
$cached_val = wp_cache_get( $key, $group);
$this->assertNotEquals( $cached_val, $val, "Value from cache must no be same as orginal value" );
$this->assertFalse( $cached_val , "Cached value must not exist" );
}
function testDefaultValues() {
// check that all configs are empty
$this->assertEquals( self::$sf->get_post_connectors(), array() );
$this->assertEquals( self::$sf->get_post_type_defaults(), array(0 => null) );
$this->assertEquals( self::$sf->get_field_groups(), array() );
}
/*
Check if we can get settings from old installation/unit testing
*/
// Test output of debug function
function testDebug()
{
$expected = <<<EOD
<pre class='sf_box_debug'>
Var is string with length 36: this is simple fields debug function
</pre>
EOD;
$this->expectOutputString($expected);
sf_d("this is simple fields debug function");
}
// Test output of debug function
function testDebug2()
{
$expected = <<<EOD
<pre class='sf_box_debug'>
<b>With headline:</b>
Var is string with length 36: this is simple fields debug function
</pre>
EOD;
$this->expectOutputString($expected);
sf_d("this is simple fields debug function", "With headline");
}
function insertDataForManualAddedFields() {
global $wpdb;
// Create post that has manually added simple fields
// First we create the post, then we add the custom fields
// post_name=post-with-fields
// post_content=I am a post with fields attached.
// post_title=Post with fields
$post_id = $this->factory->post->create(array(
"post_title" => "Post with fields"
));
self::$post_id_for_manual_tests = $post_id;
// Insert options for Simple Fields
// Nothing here is for specific posts
$query = <<<EOT
INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`)
VALUES ('simple_fields_options', 'a:4:{i:0;b:0;s:10:\"debug_type\";i:1;s:23:\"phpunittest_save_option\";s:15:\"new saved value\";s:31:\"phpunittest_save_another_option\";s:13:\"another value\";}', 'yes')
EOT;
$wpdb->query($query);
$query = <<<EOT
INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`)
VALUES
('simple_fields_groups', 'a:3:{i:1;a:9:{s:2:\"id\";i:1;s:3:\"key\";s:20:\"field_group_manually\";s:4:\"slug\";s:20:\"field_group_manually\";s:4:\"name\";s:26:\"Manually added field group\";s:11:\"description\";s:50:\"A group that is added manually from within the GUI\";s:10:\"repeatable\";b:1;s:6:\"fields\";a:14:{i:1;a:11:{s:4:\"name\";s:10:\"Text field\";s:11:\"description\";s:12:\"A text field\";s:4:\"slug\";s:10:\"field_text\";s:4:\"type\";s:4:\"text\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:1:\"1\";s:7:\"deleted\";s:1:\"0\";}i:2;a:11:{s:4:\"name\";s:14:\"Field textarea\";s:11:\"description\";s:16:\"A texteara field\";s:4:\"slug\";s:14:\"field_textarea\";s:4:\"type\";s:8:\"textarea\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:1:\"2\";s:7:\"deleted\";s:1:\"0\";}i:3;a:11:{s:4:\"name\";s:19:\"Field textarea HTML\";s:11:\"description\";s:41:\"A textarea field with HTML-editor enabled\";s:4:\"slug\";s:19:\"field_textarea_html\";s:4:\"type\";s:8:\"textarea\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:2:{s:11:\"size_height\";s:7:\"default\";s:15:\"use_html_editor\";s:1:\"1\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:1:\"3\";s:7:\"deleted\";s:1:\"0\";}i:4;a:11:{s:4:\"name\";s:14:\"FIeld checkbox\";s:11:\"description\";s:16:\"A checkbox field\";s:4:\"slug\";s:14:\"field_checkbox\";s:4:\"type\";s:8:\"checkbox\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:1:\"4\";s:7:\"deleted\";s:1:\"0\";}i:5;a:12:{s:4:\"name\";s:19:\"Field radioibuttons\";s:11:\"description\";s:20:\"A radiobuttons field\";s:4:\"slug\";s:18:\"field_radiobuttons\";s:4:\"type\";s:12:\"radiobuttons\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_radiobuttons_options\";a:4:{s:17:\"radiobutton_num_2\";a:2:{s:5:\"value\";s:13:\"Radiobutton 1\";s:7:\"deleted\";s:1:\"0\";}s:17:\"radiobutton_num_3\";a:2:{s:5:\"value\";s:13:\"Radiobutton 2\";s:7:\"deleted\";s:1:\"0\";}s:22:\"checked_by_default_num\";s:17:\"radiobutton_num_3\";s:17:\"radiobutton_num_4\";a:2:{s:5:\"value\";s:13:\"Radiobutton 3\";s:7:\"deleted\";s:1:\"0\";}}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:1:\"5\";s:7:\"deleted\";s:1:\"0\";}i:6;a:11:{s:4:\"name\";s:14:\"Field dropdown\";s:11:\"description\";s:16:\"A dropdown field\";s:4:\"slug\";s:14:\"field_dropdown\";s:4:\"type\";s:8:\"dropdown\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:4:{s:15:\"enable_multiple\";s:1:\"0\";s:14:\"dropdown_num_2\";a:2:{s:5:\"value\";s:10:\"Dropdown 1\";s:7:\"deleted\";s:1:\"0\";}s:14:\"dropdown_num_3\";a:2:{s:5:\"value\";s:10:\"Dropdown 2\";s:7:\"deleted\";s:1:\"0\";}s:14:\"dropdown_num_4\";a:2:{s:5:\"value\";s:10:\"Dropdown 3\";s:7:\"deleted\";s:1:\"0\";}}s:2:\"id\";s:1:\"6\";s:7:\"deleted\";s:1:\"0\";}i:7;a:11:{s:4:\"name\";s:10:\"Field file\";s:11:\"description\";s:12:\"A file field\";s:4:\"slug\";s:10:\"field_file\";s:4:\"type\";s:4:\"file\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:1:\"7\";s:7:\"deleted\";s:1:\"0\";}i:8;a:11:{s:4:\"name\";s:10:\"Field post\";s:11:\"description\";s:12:\"A post field\";s:4:\"slug\";s:10:\"field_post\";s:4:\"type\";s:4:\"post\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:2:{i:0;s:4:\"post\";i:1;s:4:\"page\";}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:1:\"8\";s:7:\"deleted\";s:1:\"0\";}i:9;a:12:{s:4:\"name\";s:14:\"Field taxonomy\";s:11:\"description\";s:16:\"A taxonomy field\";s:4:\"slug\";s:14:\"field_taxonomy\";s:4:\"type\";s:8:\"taxonomy\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_taxonomy_options\";a:1:{s:18:\"enabled_taxonomies\";a:2:{i:0;s:8:\"category\";i:1;s:8:\"post_tag\";}}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:1:\"9\";s:7:\"deleted\";s:1:\"0\";}i:10;a:11:{s:4:\"name\";s:19:\"Field Taxonomy Term\";s:11:\"description\";s:21:\"A taxonomy term field\";s:4:\"slug\";s:19:\"field_taxonomy_term\";s:4:\"type\";s:12:\"taxonomyterm\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:2:{s:16:\"enabled_taxonomy\";s:8:\"category\";s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:2:\"10\";s:7:\"deleted\";s:1:\"0\";}i:11;a:11:{s:4:\"name\";s:11:\"Field Color\";s:11:\"description\";s:13:\"A color field\";s:4:\"slug\";s:11:\"field_color\";s:4:\"type\";s:5:\"color\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";%%THING1%%;s:7:\"deleted\";s:1:\"0\";}i:12;a:11:{s:4:\"name\";s:10:\"Field Date\";s:11:\"description\";s:12:\"A date field\";s:4:\"slug\";s:10:\"field_date\";s:4:\"type\";s:4:\"date\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:2:\"12\";s:7:\"deleted\";s:1:\"0\";}i:13;a:11:{s:4:\"name\";s:10:\"Field user\";s:11:\"description\";s:12:\"A user field\";s:4:\"slug\";s:10:\"field_user\";s:4:\"type\";s:4:\"user\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:4:\"date\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:2:\"13\";s:7:\"deleted\";s:1:\"0\";}i:14;a:11:{s:4:\"name\";s:19:\"Field date picker 2\";s:11:\"description\";s:21:\"A date picker 2 field\";s:4:\"slug\";s:19:\"field_date_picker_2\";s:4:\"type\";s:7:\"date_v2\";s:7:\"options\";a:2:{s:7:\"divider\";a:1:{s:10:\"appearance\";s:4:\"line\";}s:7:\"date_v2\";a:3:{s:7:\"show_as\";s:8:\"datetime\";s:4:\"show\";s:6:\"always\";s:12:\"default_date\";s:7:\"no_date\";}}s:21:\"type_textarea_options\";a:1:{s:11:\"size_height\";s:7:\"default\";}s:17:\"type_post_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:21:\"type_dropdown_options\";a:1:{s:15:\"enable_multiple\";s:1:\"0\";}s:2:\"id\";s:2:\"14\";s:7:\"deleted\";s:1:\"0\";}}s:7:\"deleted\";b:0;s:12:\"fields_count\";i:13;}i:2;a:9:{s:2:\"id\";i:2;s:3:\"key\";s:22:\"my_new_field_group_old\";s:4:\"slug\";s:22:\"my_new_field_group_old\";s:4:\"name\";s:16:\"Test field group\";s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:6:\"fields\";a:1:{i:0;a:9:{s:4:\"name\";s:16:\"A new text field\";s:4:\"slug\";s:16:\"my_new_textfield\";s:11:\"description\";s:36:\"Enter some text in my new text field\";s:4:\"type\";s:4:\"text\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:0;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:2;s:4:\"name\";s:16:\"Test field group\";s:4:\"slug\";i:2;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:1;}}}s:7:\"deleted\";b:0;s:12:\"fields_count\";i:1;}i:3;a:9:{s:2:\"id\";i:3;s:3:\"key\";s:29:\"my_new_field_group_all_fields\";s:4:\"slug\";s:29:\"my_new_field_group_all_fields\";s:4:\"name\";s:32:\"Test field group with all fields\";s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:6:\"fields\";a:12:{i:0;a:9:{s:4:\"name\";s:24:\"A new field of type text\";s:4:\"slug\";s:19:\"slug_fieldtype_text\";s:11:\"description\";s:34:\"Description for field of type text\";s:4:\"type\";s:4:\"text\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:0;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:1;a:9:{s:4:\"name\";s:28:\"A new field of type textarea\";s:4:\"slug\";s:23:\"slug_fieldtype_textarea\";s:11:\"description\";s:38:\"Description for field of type textarea\";s:4:\"type\";s:8:\"textarea\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:1;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:2;a:9:{s:4:\"name\";s:28:\"A new field of type checkbox\";s:4:\"slug\";s:23:\"slug_fieldtype_checkbox\";s:11:\"description\";s:38:\"Description for field of type checkbox\";s:4:\"type\";s:8:\"checkbox\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:2;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:3;a:9:{s:4:\"name\";s:31:\"A new field of type radiobutton\";s:4:\"slug\";s:26:\"slug_fieldtype_radiobutton\";s:11:\"description\";s:41:\"Description for field of type radiobutton\";s:4:\"type\";s:11:\"radiobutton\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:3;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:4;a:9:{s:4:\"name\";s:28:\"A new field of type dropdown\";s:4:\"slug\";s:23:\"slug_fieldtype_dropdown\";s:11:\"description\";s:38:\"Description for field of type dropdown\";s:4:\"type\";s:8:\"dropdown\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:4;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:5;a:9:{s:4:\"name\";s:24:\"A new field of type file\";s:4:\"slug\";s:19:\"slug_fieldtype_file\";s:11:\"description\";s:34:\"Description for field of type file\";s:4:\"type\";s:4:\"file\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:5;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:6;a:9:{s:4:\"name\";s:24:\"A new field of type post\";s:4:\"slug\";s:19:\"slug_fieldtype_post\";s:11:\"description\";s:34:\"Description for field of type post\";s:4:\"type\";s:4:\"post\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:6;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:7;a:9:{s:4:\"name\";s:28:\"A new field of type taxonomy\";s:4:\"slug\";s:23:\"slug_fieldtype_taxonomy\";s:11:\"description\";s:38:\"Description for field of type taxonomy\";s:4:\"type\";s:8:\"taxonomy\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:7;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:8;a:9:{s:4:\"name\";s:32:\"A new field of type taxonomyterm\";s:4:\"slug\";s:27:\"slug_fieldtype_taxonomyterm\";s:11:\"description\";s:42:\"Description for field of type taxonomyterm\";s:4:\"type\";s:12:\"taxonomyterm\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:8;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:9;a:9:{s:4:\"name\";s:25:\"A new field of type color\";s:4:\"slug\";s:20:\"slug_fieldtype_color\";s:11:\"description\";s:35:\"Description for field of type color\";s:4:\"type\";s:5:\"color\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:9;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:10;a:9:{s:4:\"name\";s:24:\"A new field of type date\";s:4:\"slug\";s:19:\"slug_fieldtype_date\";s:11:\"description\";s:34:\"Description for field of type date\";s:4:\"type\";s:4:\"date\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:10;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}i:11;a:9:{s:4:\"name\";s:24:\"A new field of type user\";s:4:\"slug\";s:19:\"slug_fieldtype_user\";s:11:\"description\";s:34:\"Description for field of type user\";s:4:\"type\";s:4:\"user\";s:17:\"type_post_options\";a:2:{s:18:\"enabled_post_types\";a:0:{}s:20:\"additional_arguments\";s:0:\"\";}s:25:\"type_taxonomyterm_options\";a:1:{s:20:\"additional_arguments\";s:0:\"\";}s:2:\"id\";i:11;s:7:\"deleted\";i:0;s:11:\"field_group\";a:6:{s:2:\"id\";i:3;s:4:\"name\";s:32:\"Test field group with all fields\";s:4:\"slug\";i:3;s:11:\"description\";s:22:\"Test field description\";s:10:\"repeatable\";i:1;s:12:\"fields_count\";i:12;}}}s:7:\"deleted\";b:0;s:12:\"fields_count\";i:12;}}', 'yes')
EOT;
#'s:2:\"11\"';
$stringlen = strlen($post_id);
#echo "len: $stringlen";
#echo "postid: $post_id";
// replace %%THING1%% with string length and val of previosly inserted post
$query = str_replace('%%THING1%%', 's:' . $stringlen . ':\"' . $post_id . '\"', $query);
#$query = str_replace('%%THING1%%', 's:2:\"11\"', $query);
#echo $query;
$wpdb->query($query);
$query = <<<EOT
INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`)
VALUES
('simple_fields_post_connectors', 'a:1:{i:1;a:9:{s:2:\"id\";i:1;s:3:\"key\";s:23:\"post_connector_manually\";s:4:\"slug\";s:23:\"post_connector_manually\";s:4:\"name\";s:29:\"Manually added post connector\";s:12:\"field_groups\";a:1:{i:1;a:5:{s:2:\"id\";s:1:\"1\";s:4:\"name\";s:26:\"Manually added field group\";s:7:\"deleted\";s:1:\"0\";s:7:\"context\";s:6:\"normal\";s:8:\"priority\";s:4:\"high\";}}s:10:\"post_types\";a:2:{i:0;s:4:\"post\";i:1;s:4:\"page\";}s:7:\"deleted\";b:0;s:11:\"hide_editor\";b:0;s:18:\"field_groups_count\";i:1;}}', 'yes')
EOT;
$wpdb->query($query);
#sf_d( $this->factory->post->create_many( 5 ) );exit;
#$post_id = 11;
$query = <<<EOT
INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
VALUES
($post_id, '_simple_fields_selected_connector', '1'),
($post_id, '_simple_fields_been_saved', '1'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_14_numInSet_0', '2013-01-31 09:30'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_13_numInSet_0', '1'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_13_numInSet_1', '1'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_12_numInSet_1', '15/10/2012'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_12_numInSet_0', '12/10/2012'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_11_numInSet_0', 'FF3C26'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_11_numInSet_1', '8B33FF'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_10_numInSet_1', ''),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_10_numInSet_0', 'a:1:{i:0;s:1:\"1\";}'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_9_numInSet_1', 'category'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_9_numInSet_0', 'post_tag'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_8_numInSet_1', '5'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_8_numInSet_0', '$post_id'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_7_numInSet_1', '17'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_6_numInSet_1', 'dropdown_num_2'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_7_numInSet_0', '14'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_3_numInSet_0', '<p>Text entered in the TinyMCE-editor.</p>\n'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_3_numInSet_1', '<p>Tiny editors are great!</p>\n<p>You can style the content and insert images and stuff. Groovy! Funky!</p>\n<h2>A list</h2>\n<ul>\n<li>List item 1</li>\n<li>List item 2</li>\n</ul>\n<h2>And images can be inserted</h2>\n<p><a href=\"http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg\"><img class=\"alignnone wp-image-14\" title=\"product-cat-2\" src=\"http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg\" alt=\"\" width=\"368\" height=\"277\" /></a></p>\n'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_6_numInSet_0', 'dropdown_num_3'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_5_numInSet_1', 'radiobutton_num_2'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_4_numInSet_1', ''),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_5_numInSet_0', 'radiobutton_num_4'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_4_numInSet_0', '1'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_1', 'text in textfield 2<span>yes it is</span>'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0', 'Text entered in the textarea'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_1', 'Textera with more funky text in it.\r\n\r\n<h2>Headline</h2>\r\n<ul>\r\n <li>Item 1</li>\r\n <li>Item 2</li>\r\n</ul>\r\n'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_added_numInSet_0', '1'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0', 'Text entered in the text field'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_added_numInSet_1', '1'),
($post_id, '_simple_fields_fieldGroupID_1_fieldID_14_numInSet_1', '2012-12-10 18:00');
EOT;
$wpdb->query($query);
// Posts to test different connectors with
$sql = "INSERT INTO `$wpdb->posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`)
VALUES
(24, 1, '2012-10-11 11:07:42', '2012-10-11 11:07:42', '', 'Post with no connector', '', 'publish', 'open', 'open', '', 'post-with-not-connector', '', '', '2012-10-11 11:08:41', '2012-10-11 11:08:41', '', 0, 'http://unit-test.simple-fields.com/wordpress/?p=24', 0, 'post', '', 0),
(26, 1, '2012-10-11 11:08:04', '2012-10-11 11:08:04', '', 'Post with inherit connector', '', 'publish', 'open', 'open', '', 'post-with-inherit-connector', '', '', '2012-10-11 11:08:29', '2012-10-11 11:08:29', '', 0, 'http://unit-test.simple-fields.com/wordpress/?p=26', 0, 'post', '', 0),
(32, 1, '2012-10-11 11:39:31', '2012-10-11 11:39:31', '', 'Page with fields', '', 'publish', 'open', 'open', '', 'page-with-fields', '', '', '2012-10-11 11:39:31', '2012-10-11 11:39:31', '', 0, 'http://unit-test.simple-fields.com/wordpress/?page_id=32', 0, 'page', '', 0),
(34, 1, '2012-10-11 11:39:43', '2012-10-11 11:39:43', '', 'Page with inherit connector (has parent with fields)', '', 'publish', 'open', 'open', '', 'page-with-inherit-connector', '', '', '2012-10-11 11:40:30', '2012-10-11 11:40:30', '', 32, 'http://unit-test.simple-fields.com/wordpress/?page_id=34', 0, 'page', '', 0),
(36, 1, '2012-10-11 11:39:59', '2012-10-11 11:39:59', '', 'Post with no connector (has parent with fields)', '', 'publish', 'open', 'open', '', 'post-with-no-connector', '', '', '2012-10-11 11:40:10', '2012-10-11 11:40:10', '', 32, 'http://unit-test.simple-fields.com/wordpress/?page_id=36', 0, 'page', '', 0);
";
$wpdb->query($sql);
// post_with_no_connector
$sql = "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
VALUES
(24, '_edit_lock', '1349955446:1'),
(24, '_simple_fields_selected_connector', '__none__'),
(24, '_edit_last', '1');";
$wpdb->query($sql);
// post_with_inherit_connector
$sql = "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
VALUES
(26, '_edit_last', '1'),
(26, '_edit_lock', '1349953596:1'),
(26, '_simple_fields_selected_connector', '__inherit__');";
$wpdb->query($sql);
// page_with_fields
$sql = "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
VALUES
(32, '_edit_last', '1'),
(32, '_edit_lock', '1357241403:1'),
(32, '_simple_fields_selected_connector', '1'),
(32, '_wp_page_template', 'default');";
$wpdb->query($sql);
// page_with_no_connector
$sql = "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
VALUES
(36, '_edit_last', '1'),
(36, '_edit_lock', '1349957025:1'),
(36, '_simple_fields_selected_connector', '__none__'),
(36, '_wp_page_template', 'default');";
$wpdb->query($sql);
// page_with_inherit_connector
$sql = "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
VALUES
(34, '_edit_last', '1'),
(34, '_edit_lock', '1349955934:1'),
(34, '_simple_fields_selected_connector', '__inherit__'),
(34, '_wp_page_template', 'default');";
$wpdb->query($sql);
return $post_id;
}
// insert and test manually added fields
function testManuallyAddedFields() {
$this->insertDataForManualAddedFields();
$post_id = self::$post_id_for_manual_tests;
// test single/first values
$this->assertEquals("Text entered in the text field", simple_fields_value("field_text", $post_id));
$this->assertEquals("Text entered in the textarea", simple_fields_value("field_textarea", $post_id));
$this->assertEquals("<p>Text entered in the TinyMCE-editor.</p>\n", simple_fields_value("field_textarea_html", $post_id));
$this->assertEquals("1", simple_fields_value("field_checkbox", $post_id));
$this->assertEquals("radiobutton_num_4", simple_fields_value("field_radiobuttons", $post_id));
$this->assertEquals("dropdown_num_3", simple_fields_value("field_dropdown", $post_id));
$this->assertEquals(14, simple_fields_value("field_file", $post_id));
$this->assertEquals($post_id, simple_fields_value("field_post", $post_id));
$this->assertEquals("post_tag", simple_fields_value("field_taxonomy", $post_id));
$this->assertEquals(array(0 => 1), simple_fields_value("field_taxonomy_term", $post_id));
$this->assertEquals("FF3C26", simple_fields_value("field_color", $post_id));
$this->assertEquals("12/10/2012", simple_fields_value("field_date", $post_id));
$this->assertEquals(1, simple_fields_value("field_user", $post_id));
// test that wp_post object can be passed
$post_dapost = get_post($post_id);
$this->assertEquals("Text entered in the text field", simple_fields_value("field_text", $post_dapost));
// test repeatable/all values
#var_dump( simple_fields_values("field_text") );
#exit;
#print_r($allvals);
$val = array(
0 => "Text entered in the text field",
1 => "text in textfield 2<span>yes it is</span>"
);
$this->assertEquals($val, simple_fields_values("field_text", $post_id));
$val = array(
0 => "Text entered in the textarea",
1 => "Textera with more funky text in it.\r\n\r\n<h2>Headline</h2>\r\n<ul>\r\n <li>Item 1</li>\r\n <li>Item 2</li>\r\n</ul>\r\n");
$get_vals = simple_fields_values("field_textarea", $post_id);
$this->assertEquals($val, $get_vals);
$val = array(
0 => "<p>Text entered in the TinyMCE-editor.</p>\n",
1 => "<p>Tiny editors are great!</p>\n<p>You can style the content and insert images and stuff. Groovy! Funky!</p>\n<h2>A list</h2>\n<ul>\n<li>List item 1</li>\n<li>List item 2</li>\n</ul>\n<h2>And images can be inserted</h2>\n<p><a href=\"http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg\"><img class=\"alignnone wp-image-14\" title=\"product-cat-2\" src=\"http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg\" alt=\"\" width=\"368\" height=\"277\" /></a></p>\n");
$get_vals = simple_fields_values("field_textarea_html", $post_id);
$this->assertEquals($val[1], $get_vals[1]);
$val = array(
0 => 1,
1 => ""
);
$this->assertEquals($val, simple_fields_values("field_checkbox", $post_id));
$val = array(
0 => "radiobutton_num_4",
1 => "radiobutton_num_2"
);
$this->assertEquals($val, simple_fields_values("field_radiobuttons", $post_id));
$val = array(
0 => "dropdown_num_3",
1 => "dropdown_num_2"
);
$this->assertEquals($val, simple_fields_values("field_dropdown", $post_id));
$val = array(
0 => 14,
1 => 17
);
$this->assertEquals($val, simple_fields_values("field_file", $post_id));
$val = array(
0 => $post_id,
1 => 5
);
$this->assertEquals($val, simple_fields_values("field_post", $post_id));
$val = array(
0 => "post_tag",
1 => "category"
);
$this->assertEquals($val, simple_fields_values("field_taxonomy", $post_id));
$val = array(
0 => array(0 => 1),
1 => ""
);
$this->assertEquals($val, simple_fields_values("field_taxonomy_term", $post_id));
$val = array(
0 => "FF3C26",
1 => "8B33FF"
);
$this->assertEquals($val, simple_fields_values("field_color", $post_id));
$val = array(
0 => "12/10/2012",
1 => "15/10/2012"
);
$this->assertEquals($val, simple_fields_values("field_date", $post_id));
$val = array(
0 => "1",
1 => "1"
);
$this->assertEquals($val, simple_fields_values("field_user", $post_id));
// date & time picker 2
$val = array(
0 => array(
"type" => "datetime",
"date_unixtime" => "1359624600",
"ISO_8601" => "2013-01-31 09:30",
"RFC_2822" => "Thu, 31 Jan 2013 09:30:00 +0000",
"Y-m-d" => "2013-01-31",
"Y-m-d H:i" => "2013-01-31 09:30",
"date_format" => "January 31, 2013",
"date_time_format" => "January 31, 2013 9:30 am"
),
1 => array(
"type" => "datetime",
"date_unixtime" => "1355162400",
"ISO_8601" => "2012-12-10 18:00",
"RFC_2822" => "Mon, 10 Dec 2012 18:00:00 +0000",
"Y-m-d" => "2012-12-10",
"Y-m-d H:i" => "2012-12-10 18:00",
"date_format" => "December 10, 2012",
"date_time_format" => "December 10, 2012 6:00 pm",
)
);
$this->assertEquals($val, simple_fields_values("field_date_picker_2", $post_id));
}
function testManuallyAddedFieldsExtendedReturn()
{
$this->insertDataForManualAddedFields();
$post_id = self::$post_id_for_manual_tests;
// test single/first values
$vals = simple_fields_value("field_radiobuttons", $post_id, "extended_return=1");
$vals_expected = array(
"selected_value" => "Radiobutton 3",
"selected_radiobutton" => array(
"value" => "Radiobutton 3",
"key" => "radiobutton_num_4",
"is_selected" => 1
),
"radiobuttons" => array(
array(
"value" => "Radiobutton 1",
"key" => "radiobutton_num_2",
"is_selected" => ""
),
array(
"value" => "Radiobutton 2",
"key" => "radiobutton_num_3",
"is_selected" => ""
),
array(
"value" => "Radiobutton 3",
"key" => "radiobutton_num_4",
"is_selected" => 1
)
)
);
$this->assertEquals($vals_expected, $vals);
$vals = simple_fields_value("field_dropdown", $post_id, "extended_return=1");
$vals_expected = array(
'selected_value' => 'Dropdown 2',
'selected_option' => array(
'value' => 'Dropdown 2',
'key' => 'dropdown_num_3',
'is_selected' => true
),
'options' => array(
0 => array(
'value' => 'Dropdown 1',
'key' => 'dropdown_num_2',
'is_selected' => false
),
1 => array(
'value' => 'Dropdown 2',
'key' => 'dropdown_num_3',
'is_selected' => true
),
2 => array(
'value' => 'Dropdown 3',
'key' => 'dropdown_num_4',
'is_selected' => false
)
)
);
$this->assertEquals($vals_expected, $vals);
// check just keys for now, should check more of course
$vals = simple_fields_value("field_file", $post_id, "extended_return=1");
#echo var_export($vals);
$attachment_id = 14;
$vals_expected = array(
'id' => 14,
'is_image' => false,
'url' => false,
'mime' => false,
'link' => array(
'full' => 'Missing Attachment',
'thumbnail' => 'Missing Attachment',
'medium' => 'Missing Attachment',
'large' => 'Missing Attachment',
'post-thumbnail' => 'Missing Attachment',
// + 'post-thumbnail-full-width' => 'Missing Attachment'
),
'image' => array(
'full' => '',
'thumbnail' => '',
'medium' => '',
'large' => '',
'post-thumbnail' => '',
// + 'post-thumbnail-full-width' => ''
),
'image_src' => array(
'full' => false,
'thumbnail' => false,
'medium' => false,
'large' => false,
'post-thumbnail' => false,
// 'post-thumbnail-full-width' => false
),
'metadata' => false,
"post" => null
);
#var_dump($vals);
// Test file field with file that does not exist
// Expect empty array
$vals_expected = array();
$this->assertEquals($vals_expected, $vals);
// test with a real attachment
// @todo: how to test attachments?
// Upload attachment. code from
// https://github.com/kurtpayne/wordpress-unit-tests/blob/master/tests/post/attachments.php#L19
$base_64_image = "R0lGODdhAAQAA+MAAMzMzJaWlre3t5ycnMXFxbGxsaOjo76+vqqqqgAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAQAAwAE/hDISau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru987//AoHBILBqPyKRyyWw6n9CodEqtWq/YrHbL7Xq/4LB4TC6bz+i0es1uu9/wuHxOr9vv+Lx+z+/7/4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAMKHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3Mixo8eP/iBDihxJsqTJkyhTqlzJsqXLlzBjypxJs6bNmzhz6tzJs6fPn0CDCh1KtKjRo0iTKl3KtKnTp1CjSp1KtarVq1izat3KtavXr2DDih1LtqzZs2jTql3Ltq3bt3Djyp1Lt67du3jz6t3Lt6/fv4ADCx5MuLDhw4gTK17MuLHjx5AjS55MubLly5gza97MubPnz6BDix5NurTp06hTq17NurXr17Bjy55Nu7bt27hz697Nu7fv38CDCx9OvLjx48iTK1/OvLnz59CjS59Ovbr169iza9/Ovbv37+DDix9Pvrz58+jTq1/Pvr379/Djy59Pv779+/jz69/Pv7///wAG/ijggAQWaOCBCCao4IIMNujggxBGKOGEFFZo4YUYZqjhhhx26OGHIIYo4ogklmjiiSimqOKKLLbo4oswxijjjDTWaOONOOao44489ujjj0AGKeSQRBZp5JFIJqnkkkw26eSTUEYp5ZRUVmnllVhmqeWWXHbp5ZdghinmmGSWaeaZaKap5ppstunmm3DGKeecdNZp55145qnnnnz26eefgAYq6KCEFmrooYgmquiijDbq6KOQRirppJRWaumlmGaq6aacdurpp6CGKuqopJZq6qmopqrqqqy26uqrsMYq66y01mrrrbjmquuuvPbq66/ABivssMQWa+yxyCar7LLM/jbr7LPQRivttNRWa+212Gar7bbcduvtt+CGK+645JZr7rnopqvuuuy26+678MYr77z01mvvvfjmq+++/Pbr778AByzwwAQXbPDBCCes8MIMN+zwwxBHLPHEFFds8cUYZ6zxxhx37PHHIIcs8sgkl2zyySinrPLKLLfs8sswxyzzzDTXbPPNOOes88489+zzz0AHLfTQRBdt9NFIJ6300kw37ZQAAwQg9dRUV2311VhnXfUAAjjNSdRahy322Ft7vQnZaKedtdmaqO3222x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7lXN7lXv7lYB7mYj7mZF7mZn7maJ7mar7mbN7mbv7mcB7ncj7ndF7ndn7neJ7ner7nfN7nfv7ngB7ogj7ohF7ohn7oiJ7oir7ojN7ojv7okB7pkj7pIZRe6ZZ+6Zie6Zq+6Zze6Z7+6aAe6qI+6qRe6qZ+6p0eAQA7";
$upload = wp_upload_bits("testimage_1.gif", null, base64_decode($base_64_image));
$type = '';
if ( !empty($upload['type']) ) {
$type = $upload['type'];
} else {
$mime = wp_check_filetype( $upload['file'] );
if ($mime)
$type = $mime['type'];
}
$attachment = array(
'post_title' => basename( $upload['file'] ),
'post_content' => '',
'post_type' => 'attachment',
'post_parent' => $parent_post_id,
'post_mime_type' => $type,
'guid' => $upload[ 'url' ],
);
// Save the data
$id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id );
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
// file is uploaded, add it to post/simple fields-fields
simple_fields_set_value($post_id, "field_file", 0, null, $id);
// get field that was added just now
// big array is returned, but at least check the basics
$vals_returned = simple_fields_value("field_file", $post_id, "extended_return=1");
$this->assertArrayHasKey('id', $vals_returned);
$this->assertEquals($vals_returned["id"], $id);
$this->assertArrayHasKey('is_image', $vals_returned);
$this->assertEquals($vals_returned["is_image"], true);
$this->assertArrayHasKey('mime', $vals_returned);
$this->assertEquals($vals_returned["mime"], "image/gif");
$this->assertArrayHasKey('link', $vals_returned);
$this->assertNotEmpty($vals_returned["link"]);
$this->assertArrayHasKey('url', $vals_returned);
$this->assertNotEmpty($vals_returned["url"]);
$this->assertArrayHasKey('image', $vals_returned);
$this->assertNotEmpty($vals_returned["image"]);
$this->assertArrayHasKey('image_src', $vals_returned);
$this->assertNotEmpty($vals_returned["image_src"]);
$this->assertArrayHasKey('metadata', $vals_returned);
$this->assertNotEmpty($vals_returned["metadata"]);
$this->assertArrayHasKey('post', $vals_returned);
$this->assertNotEmpty($vals_returned["post"]);
$vals = simple_fields_value("field_post", $post_id, "extended_return=1");
$vals_expected = array(
'id' => $post_id,
'title' => 'Post with fields',
'permalink' => get_permalink($post_id),
'post' => get_post($post_id)
);
$this->assertEquals($vals_expected, $vals);
$vals = simple_fields_value("field_taxonomy", $post_id, "extended_return=1");
$vals_expected = array(
'name' => 'post_tag',
'singular_name' => 'Tag',
'plural_name' => 'Tags',
"taxonomy" => get_taxonomy("post_tag")
);
$this->assertEquals($vals_expected, $vals);
$vals = simple_fields_value("field_taxonomy_term", $post_id, "extended_return=1");
$vals_expected = array(
"terms" => array(
0 => array(
"name" => "Uncategorized",
"slug" => "uncategorized",
"id" => 1,
"term" => get_term_by("id", 1, "category")
)
)
);
$this->assertEquals($vals_expected, $vals);
$vals = simple_fields_value("field_date", $post_id, "extended_return=1");
$vals_expected = array (
'saved_value' => '12/10/2012',
'timestamp' => 1350000000,
'date_format' => 'October 12, 2012',
'date_format_i18n' => 'October 12, 2012'
);
$this->assertEquals($vals_expected, $vals);
$vals = simple_fields_value("field_user", $post_id, "extended_return=1");
$vals_expected = array (
'id' => 1,
'first_name' => '',
'last_name' => '',
'user_login' => 'admin',
'user_email' => 'admin@example.org',
'user_nicename' => 'admin', 'display_name' => 'admin',
'user' => get_user_by("id", 1)
);
$this->assertEquals($vals_expected, $vals);
}
public function testPostConnectors() {
// testa connectors
// sätt connectors manuellt på några poster
// testa därefter om det är rätt stuff
$this->insertDataForManualAddedFields();
$post_id = self::$post_id_for_manual_tests;
$post_with_fields = $post_id;
$saved_connector_to_use = get_post_meta($post_with_fields, "_simple_fields_selected_connector", true);
$this->assertEquals(1, $saved_connector_to_use);
$this->assertEquals(1, self::$sf->get_selected_connector_for_post($post_with_fields));
$post_with_no_connector = 24;
$saved_connector_to_use = get_post_meta($post_with_no_connector, "_simple_fields_selected_connector", true);
$this->assertEquals("__none__", $saved_connector_to_use);
$this->assertEquals("__none__", self::$sf->get_selected_connector_for_post($post_with_no_connector));
$post_with_inherit_connector = 26;
$saved_connector_to_use = get_post_meta($post_with_inherit_connector, "_simple_fields_selected_connector", true);
$this->assertEquals("__inherit__", $saved_connector_to_use);
$this->assertEquals("__inherit__", self::$sf->get_selected_connector_for_post($post_with_inherit_connector));
// pages
$page_with_fields = 32;
$saved_connector_to_use = get_post_meta($page_with_fields, "_simple_fields_selected_connector", true);
$this->assertEquals(1, $saved_connector_to_use);
$this->assertEquals(1, self::$sf->get_selected_connector_for_post($page_with_fields));
$this->assertEquals("post_connector_manually", simple_fields_connector($page_with_fields));
$page_with_no_connector = 36;
$saved_connector_to_use = get_post_meta($page_with_no_connector, "_simple_fields_selected_connector", true);
$this->assertEquals("__none__", $saved_connector_to_use);
$this->assertEquals("__none__", self::$sf->get_selected_connector_for_post($page_with_no_connector));
$this->assertEmpty(simple_fields_connector($page_with_no_connector));
// page is a child of a page with fields, so it will use the connector of the parent
$page_with_inherit_connector = 34;
$saved_connector_to_use = get_post_meta($page_with_inherit_connector, "_simple_fields_selected_connector", true);
$this->assertEquals("__inherit__", $saved_connector_to_use);
$this->assertEquals(1, self::$sf->get_selected_connector_for_post($page_with_inherit_connector));
$this->assertEquals("post_connector_manually", simple_fields_connector($page_with_inherit_connector));
$arr = array(
0 => 'post',
1 => 'page'
);
$this->assertEquals( $arr, self::$sf->get_post_connector_attached_types() );
// formated output from var_export using http://beta.phpformatter.com/
$arr = array(
'id' => 1,
'key' => 'post_connector_manually',
'slug' => 'post_connector_manually',
'name' => 'Manually added post connector',
'field_groups' => array(
1 => array(
'id' => '1',
'name' => 'Manually added field group',
'deleted' => '0',
'context' => 'normal',
'priority' => 'high'
)
),
'post_types' => array(
0 => 'post',
1 => 'page'
),
'deleted' => false,
'hide_editor' => false,
'field_groups_count' => 1
);
$this->assertEquals($arr, self::$sf->get_connector_by_id(1));
$arr = array(
1 => array(
'id' => 1,
'key' => 'post_connector_manually',
'slug' => 'post_connector_manually',
'name' => 'Manually added post connector',
'field_groups' => array(
1 => array(
'id' => '1',
'name' => 'Manually added field group',
'deleted' => '0',
'context' => 'normal',
'priority' => 'high'
)
),
'post_types' => array(
0 => 'post',
1 => 'page'
),
'deleted' => false,
'hide_editor' => false,
'field_groups_count' => 1
)
);
$this->assertEquals($arr, self::$sf->get_post_connectors() );
}
public function testSaveGetOptions() {
self::$sf->save_options(array(
"phpunittest_save_option" => "new saved value"
));
$options = self::$sf->get_options();
$this->assertArrayHasKey("phpunittest_save_option", $options);
self::$sf->save_options(array(
"phpunittest_save_option" => "new saved value",
"phpunittest_save_another_option" => "another value",
));
$options = self::$sf->get_options();
$this->assertArrayHasKey("phpunittest_save_option", $options);
$this->assertArrayHasKey("phpunittest_save_another_option", $options);
$this->assertEquals($options["phpunittest_save_another_option"], "another value");
}
/**
* test simple_fields_get_all_fields_and_values_for_post() that gets all values for a post
* simple_fields_get_all_fields_and_values_for_post
*/
public function testGetAllForPost() {
$post_id = $this->insertDataForManualAddedFields();
$all_vals = simple_fields_get_all_fields_and_values_for_post($post_id);
// this test feels a bit to much, should check sub keys-stuff instead of all
$vals = array(
'id' => 1,
'key' => 'post_connector_manually',
'slug' => 'post_connector_manually',
'name' => 'Manually added post connector',
'field_groups' => array(
1 => array(
'id' => 1,
'name' => 'Manually added field group',
'deleted' => false,
'context' => 'normal',
'priority' => 'high',
'key' => 'field_group_manually',
'slug' => 'field_group_manually',
'description' => 'A group that is added manually from within the GUI',
'repeatable' => true,
'fields' => array(
1 => array(
'name' => 'Text field',
'description' => 'A text field',
'slug' => 'field_text',
'type' => 'text',
'options' => array(
'fieldExample' => array(
'myTextOption' => 'No value entered yet',
'mapsTextarea' => 'Enter some cool text here please!',
'funkyDropdown' => ''
),
'minimalexample' => array(
'textDefaultName' => ''
)
),
'type_post_options' => array(
'additional_arguments' => ''
),
'type_taxonomyterm_options' => array(
'additional_arguments' => ''
),
'id' => '1',
'deleted' => '0',
'saved_values' => array(
0 => 'Text entered in the text field',
1 => 'text in textfield 2<span>yes it is</span>'
),
'meta_keys' => array(
0 => '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0',
1 => '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_1'
)
),
2 => array(
'name' => 'Field textarea',
'description' => 'A texteara field',
'slug' => 'field_textarea',
'type' => 'textarea',
'options' => array(
'fieldExample' => array(
'myTextOption' => 'No value entered yet',
'mapsTextarea' => 'Enter some cool text here please!',
'funkyDropdown' => ''
),
'minimalexample' => array(
'textDefaultName' => ''
)
),
'type_post_options' => array(
'additional_arguments' => ''
),
'type_taxonomyterm_options' => array(
'additional_arguments' => ''
),
'id' => '2',
'deleted' => '0',
'saved_values' => array(
0 => 'Text entered in the textarea',
1 => 'Textera with more funky text in it. <h2>Headline</h2> <ul> <li>Item 1</li> <li>Item 2</li> </ul> '
),
'meta_keys' => array(
0 => '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0',
1 => '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_1'
)
),
3 => array(
'name' => 'Field textarea HTML',
'description' => 'A textarea field with HTML-editor enabled',
'slug' => 'field_textarea_html',
'type' => 'textarea',
'options' => array(
'fieldExample' => array(
'myTextOption' => 'No value entered yet',
'mapsTextarea' => 'Enter some cool text here please!',
'funkyDropdown' => ''
),
'minimalexample' => array(
'textDefaultName' => ''
)
),
'type_textarea_options' => array(
'use_html_editor' => '1'
),
'type_post_options' => array(
'additional_arguments' => ''
),
'type_taxonomyterm_options' => array(
'additional_arguments' => ''
),
'id' => '3',
'deleted' => '0',
'saved_values' => array(
0 => '<p>Text entered in the TinyMCE-editor.</p> ',
1 => '<p>Tiny editors are great!</p> <p>You can style the content and insert images and stuff. Groovy! Funky!</p> <h2>A list</h2> <ul> <li>List item 1</li> <li>List item 2</li> </ul> <h2>And images can be inserted</h2> <p><a href="http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg"><img class="alignnone wp-image-14" title="product-cat-2" src="http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg" alt="" width="368" height="277" /></a></p> '
),
'meta_keys' => array(
0 => '_simple_fields_fieldGroupID_1_fieldID_3_numInSet_0',
1 => '_simple_fields_fieldGroupID_1_fieldID_3_numInSet_1'
)
),
4 => array(
'name' => 'FIeld checkbox',
'description' => 'A checkbox field',
'slug' => 'field_checkbox',
'type' => 'checkbox',
'options' => array(
'fieldExample' => array(
'myTextOption' => 'No value entered yet',
'mapsTextarea' => 'Enter some cool text here please!',
'funkyDropdown' => ''
),
'minimalexample' => array(
'textDefaultName' => ''
)
),
'type_post_options' => array(
'additional_arguments' => ''
),
'type_taxonomyterm_options' => array(
'additional_arguments' => ''
),
'id' => '4',
'deleted' => '0',
'saved_values' => array(
0 => '1',
1 => ''
),
'meta_keys' => array(
0 => '_simple_fields_fieldGroupID_1_fieldID_4_numInSet_0',
1 => '_simple_fields_fieldGroupID_1_fieldID_4_numInSet_1'
)
),
5 => array(
'name' => 'Field radioibuttons',
'description' => 'A radiobuttons field',
'slug' => 'field_radiobuttons',
'type' => 'radiobuttons',
'options' => array(
'fieldExample' => array(
'myTextOption' => 'No value entered yet',
'mapsTextarea' => 'Enter some cool text here please!',
'funkyDropdown' => ''
),
'minimalexample' => array(
'textDefaultName' => ''
)
),
'type_post_options' => array(
'additional_arguments' => ''
),
'type_taxonomyterm_options' => array(
'additional_arguments' => ''
),
'type_radiobuttons_options' => array(
'radiobutton_num_2' => array(
'value' => 'Radiobutton 1',
'deleted' => '0'
),
'radiobutton_num_3' => array(
'value' => 'Radiobutton 2',
'deleted' => '0'
),
'checked_by_default_num' => 'radiobutton_num_3',
'radiobutton_num_4' => array(
'value' => 'Radiobutton 3',
'deleted' => '0'
)
),
'id' => '5',
'deleted' => '0',
'saved_values' => array(
0 => 'radiobutton_num_4',
1 => 'radiobutton_num_2'
),
'meta_keys' => array(
0 => '_simple_fields_fieldGroupID_1_fieldID_5_numInSet_0',
1 => '_simple_fields_fieldGroupID_1_fieldID_5_numInSet_1'
)
),
6 => array(
'name' => 'Field dropdown',
'description' => 'A dropdown field',
'slug' => 'field_dropdown',
'type' => 'dropdown',
'options' => array(
'fieldExample' => array(
'myTextOption' => 'No value entered yet',
'mapsTextarea' => 'Enter some cool text here please!',
'funkyDropdown' => ''
),
'minimalexample' => array(
'textDefaultName' => ''
)
),
'type_post_options' => array(
'additional_arguments' => ''
),
'type_taxonomyterm_options' => array(
'additional_arguments' => ''
),
'type_dropdown_options' => array(
'dropdown_num_2' => array(
'value' => 'Dropdown 1',
'deleted' => '0'
),
'dropdown_num_3' => array(
'value' => 'Dropdown 2',
'deleted' => '0'
),
'dropdown_num_4' => array(
'value' => 'Dropdown 3',
'deleted' => '0'
)
),
'id' => '6',
'deleted' => '0',
'saved_values' => array(
0 => 'dropdown_num_3',
1 => 'dropdown_num_2'
),
'meta_keys' => array(
0 => '_simple_fields_fieldGroupID_1_fieldID_6_numInSet_0',
1 => '_simple_fields_fieldGroupID_1_fieldID_6_numInSet_1'
)
),
7 => array(
'name' => 'Field file',
'description' => 'A file field',
'slug' => 'field_file',
'type' => 'file',
'options' => array(
'fieldExample' => array(
'myTextOption' => 'No value entered yet',
'mapsTextarea' => 'Enter some cool text here please!',
'funkyDropdown' => ''
),
'minimalexample' => array(
'textDefaultName' => ''
)
),
'type_post_options' => array(
'additional_arguments' => ''