Test Setup Failed
Pull Request — master (#215)
by Viruthagiri
12:15
created

SendEnquiry   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 114
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
B testSendEnquiry() 0 30 2
B testSendToFriend() 0 32 2
B texstSendToFriendFailure() 0 37 2
A tearDown() 0 4 1
1
<?php
2
class SendEnquiry extends WP_UnitTestCase
3
{
4
    public function setUp()
5
    {
6
        parent::setUp();
7
    }
8
9
    public function testSendEnquiry()
10
    {
11
        $query_args = array(
12
            'post_status' => 'publish',
13
            'post_type' => 'gd_place',
14
            'posts_per_page' => 1,
15
        );
16
17
        $all_posts = new WP_Query( $query_args );
18
        $post_id = null;
19
        while ( $all_posts->have_posts() ) : $all_posts->the_post();
20
            $post_id = get_the_ID();
21
        endwhile;
22
23
        $this->assertTrue(is_int($post_id));
24
25
        $data = array(
26
            'sendact' => 'send_inqury',
27
            'pid' => (string) $post_id,
28
            'inq_name' => 'Test User',
29
            'inq_email' => '[email protected]',
30
            'inq_phone' => 'Test',
31
            'inq_msg' => 'Hi there, I would like to enquire about this place. I would like to ask more info about...',
32
            'Send' => 'Send'
33
        );
34
35
        add_filter('wp_redirect', '__return_false');
36
        geodir_send_inquiry($data);
37
        remove_filter('wp_redirect', '__return_false');
38
    }
39
40
    public function testSendToFriend()
41
    {
42
        $query_args = array(
43
            'post_status' => 'publish',
44
            'post_type' => 'gd_place',
45
            'posts_per_page' => 1,
46
        );
47
48
        $all_posts = new WP_Query( $query_args );
49
        $post_id = null;
50
        while ( $all_posts->have_posts() ) : $all_posts->the_post();
51
            $post_id = get_the_ID();
52
        endwhile;
53
54
        $this->assertTrue(is_int($post_id));
55
56
        $data = array(
57
            'sendact' => 'email_frnd',
58
            'pid' => (string) $post_id,
59
            'yourname' => 'Test User',
60
            'youremail' => '[email protected]',
61
            'frnd_subject' => 'Test',
62
            'frnd_comments' => 'Hi there, This is a comment',
63
            'to_email' => '[email protected]',
64
            'to_name' => 'Test User 2',
65
            'Send' => 'Send'
66
        );
67
68
        add_filter('wp_redirect', '__return_false');
69
        geodir_send_friend($data);
70
        remove_filter('wp_redirect', '__return_false');
71
    }
72
73
    public function texstSendToFriendFailure()
74
    {
75
        $query_args = array(
76
            'post_status' => 'publish',
77
            'post_type' => 'gd_place',
78
            'posts_per_page' => 1,
79
        );
80
81
        $all_posts = new WP_Query( $query_args );
82
        $post_id = null;
83
        while ( $all_posts->have_posts() ) : $all_posts->the_post();
84
            $post_id = get_the_ID();
85
        endwhile;
86
87
        $this->assertTrue(is_int($post_id));
88
89
        $data = array(
90
            'sendact' => 'email_frnd',
91
            'pid' => (string) $post_id,
92
            'yourname' => 'Test User',
93
            'youremail' => '[email protected]',
94
            'frnd_subject' => 'Test',
95
            'frnd_comments' => 'Hi there, This is a comment',
96
            'to_email' => 'Test User 2', //incorrect email
97
            'to_name' => '[email protected]',
98
            'Send' => 'Send'
99
        );
100
101
        add_filter('wp_redirect', '__return_false');
102
        add_filter('wp_mail', 'print_mail');
103
        ob_start();
104
        geodir_send_friend($data);
105
        $output = ob_get_clean();
106
        $this->assertContains( 'Email from GeoDirectory failed to send', $output );
107
        remove_filter('wp_mail', 'print_mail');
108
        remove_filter('wp_redirect', '__return_false');
109
    }
110
111
    public function tearDown()
112
    {
113
        parent::tearDown();
114
    }
115
}
116
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

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.

Loading history...