Skip to content

Commit 47c48cb

Browse files
author
Debian
committed
add tests
1 parent 6ada597 commit 47c48cb

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/*
3+
* Tests for Disqus_Rest_Api::comment_data_from_post author email logic.
4+
*/
5+
6+
class Test_Disqus_Rest_Api_Comment_Data_From_Post extends WP_UnitTestCase {
7+
protected $disqus_rest_api;
8+
9+
public function set_up() {
10+
parent::set_up();
11+
$this->disqus_rest_api = new Disqus_Rest_Api( null, null );
12+
}
13+
14+
private function call_comment_data_from_post( $post ) {
15+
$class = new ReflectionClass( 'Disqus_Rest_Api' );
16+
$method = $class->getMethod( 'comment_data_from_post' );
17+
$method->setAccessible( true );
18+
return $method->invokeArgs( $this->disqus_rest_api, array( $post ) );
19+
}
20+
21+
public function test_email_from_author_email() {
22+
$post = [
23+
'thread' => [ 'id' => 1, 'identifiers' => [ '1' ] ],
24+
'author' => [ 'email' => '[email protected]', 'name' => 'Foo' ],
25+
'parent' => null,
26+
'ipAddress' => '127.0.0.1',
27+
'raw_message' => 'Test',
28+
'createdAt' => '2020-01-01 00:00:00',
29+
'isApproved' => true,
30+
'isDeleted' => false,
31+
'isSpam' => false,
32+
'id' => 123,
33+
'forum' => get_option( 'disqus_forum_url' ),
34+
];
35+
$data = $this->call_comment_data_from_post( $post );
36+
$this->assertEquals( '[email protected]', $data['comment_author_email'] );
37+
}
38+
39+
public function test_email_from_anonymous_author() {
40+
$post = [
41+
'thread' => [ 'id' => 1, 'identifiers' => [ '1' ] ],
42+
'author' => [ 'isAnonymous' => true, 'name' => 'Anon' ],
43+
'parent' => null,
44+
'ipAddress' => '127.0.0.1',
45+
'raw_message' => 'Test',
46+
'createdAt' => '2020-01-01 00:00:00',
47+
'isApproved' => true,
48+
'isDeleted' => false,
49+
'isSpam' => false,
50+
'id' => 123,
51+
'forum' => get_option( 'disqus_forum_url' ),
52+
];
53+
$data = $this->call_comment_data_from_post( $post );
54+
$this->assertStringStartsWith( 'anonymized-', $data['comment_author_email'] );
55+
$this->assertStringEndsWith( '@disqus.com', $data['comment_author_email'] );
56+
}
57+
58+
public function test_email_from_author_id() {
59+
$post = [
60+
'thread' => [ 'id' => 1, 'identifiers' => [ '1' ] ],
61+
'author' => [ 'id' => 42 ],
62+
'parent' => null,
63+
'ipAddress' => '127.0.0.1',
64+
'raw_message' => 'Test',
65+
'createdAt' => '2020-01-01 00:00:00',
66+
'isApproved' => true,
67+
'isDeleted' => false,
68+
'isSpam' => false,
69+
'id' => 123,
70+
'forum' => get_option( 'disqus_forum_url' ),
71+
];
72+
$data = $this->call_comment_data_from_post( $post );
73+
$this->assertEquals( '[email protected]', $data['comment_author_email'] );
74+
}
75+
76+
public function test_email_when_no_author() {
77+
$post = [
78+
'thread' => [ 'id' => 1, 'identifiers' => [ '1' ] ],
79+
'author' => null,
80+
'parent' => null,
81+
'ipAddress' => '127.0.0.1',
82+
'raw_message' => 'Test',
83+
'createdAt' => '2020-01-01 00:00:00',
84+
'isApproved' => true,
85+
'isDeleted' => false,
86+
'isSpam' => false,
87+
'id' => 123,
88+
'forum' => get_option( 'disqus_forum_url' ),
89+
];
90+
$data = $this->call_comment_data_from_post( $post );
91+
$this->assertStringEndsWith( '@disqus.com', $data['comment_author_email'] );
92+
$this->assertNotEmpty( $data['comment_author_email'] );
93+
}
94+
}

0 commit comments

Comments
 (0)