|
1
|
|
|
<?php |
|
2
|
|
|
class AddCustomFields extends WP_UnitTestCase |
|
3
|
|
|
{ |
|
4
|
|
|
public function setUp() |
|
5
|
|
|
{ |
|
6
|
|
|
parent::setUp(); |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
public function testAddCustomFields() |
|
10
|
|
|
{ |
|
11
|
|
|
$field = array( |
|
12
|
|
|
'listing_type' => 'gd_place', |
|
13
|
|
|
'data_type' => '', |
|
14
|
|
|
'field_type' => 'select', |
|
15
|
|
|
'admin_title' => __( 'Place Type', 'test' ), |
|
16
|
|
|
'admin_desc' => __( 'Select the place type.', 'test' ), |
|
17
|
|
|
'site_title' => __( 'Place Type', 'test' ), |
|
18
|
|
|
'htmlvar_name' => 'test_place_type', |
|
19
|
|
|
'default_value' => '', |
|
20
|
|
|
'option_values' => 'Hotel,Bar,Restaurant,Pub', |
|
21
|
|
|
'is_default' => '1', |
|
22
|
|
|
'is_admin' => '1', |
|
23
|
|
|
'clabels' => __( 'Place Type', 'test' ) |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
$lastid = geodir_custom_field_save( $field ); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertTrue(is_int($lastid)); |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$field2 = array( |
|
32
|
|
|
'listing_type' => 'gd_place', |
|
33
|
|
|
'data_type' => 'VARCHAR', |
|
34
|
|
|
'field_type' => 'url', |
|
35
|
|
|
'admin_title' => __( 'Website Link', 'test' ), |
|
36
|
|
|
'admin_desc' => __( 'Enter the website link.', 'test' ), |
|
37
|
|
|
'site_title' => __( 'Website Link', 'test' ), |
|
38
|
|
|
'htmlvar_name' => 'test_ws_link', |
|
39
|
|
|
'default_value' => '', |
|
40
|
|
|
'option_values' => '', |
|
41
|
|
|
'is_default' => '1', |
|
42
|
|
|
'is_admin' => '1', |
|
43
|
|
|
'clabels' => __( 'Website Link', 'test' ) |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
$lastid2 = geodir_custom_field_save( $field2 ); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertTrue(is_int($lastid2)); |
|
49
|
|
|
|
|
50
|
|
|
//test error |
|
51
|
|
|
$field3 = array( |
|
52
|
|
|
'listing_type' => 'gd_place', |
|
53
|
|
|
'data_type' => '', |
|
54
|
|
|
'field_type' => 'select', |
|
55
|
|
|
'admin_title' => __( 'Place Type', 'test' ), |
|
56
|
|
|
'admin_desc' => __( 'Select the place type.', 'test' ), |
|
57
|
|
|
'site_title' => __( 'Place Type', 'test' ), |
|
58
|
|
|
'htmlvar_name' => 'test_place_type', |
|
59
|
|
|
'default_value' => '', |
|
60
|
|
|
'option_values' => 'Hotel,Bar,Restaurant,Pub', |
|
61
|
|
|
'is_default' => '1', |
|
62
|
|
|
'is_admin' => '1', |
|
63
|
|
|
'clabels' => __( 'Place Type', 'test' ) |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$error = geodir_custom_field_save( $field3 ); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertContains( 'HTML Variable Name should be a unique name', $error ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function tearDown() |
|
72
|
|
|
{ |
|
73
|
|
|
parent::tearDown(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
?> |
|
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.