1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @group api |
5
|
|
|
*/ |
6
|
|
|
class Writing_On_GitHub_Persist_Client_Test extends Writing_On_GitHub_Base_Client_Test { |
7
|
|
|
|
8
|
|
|
public function setUp() { |
|
|
|
|
9
|
|
|
parent::setUp(); |
10
|
|
|
|
11
|
|
|
$this->persist = new Writing_On_GitHub_Persist_Client( $this->app ); |
|
|
|
|
12
|
|
|
// $this->commit |
13
|
|
|
// ->shouldReceive( 'tree' ) |
14
|
|
|
// ->andReturn( $this->tree ); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function test_should_delete_file() { |
18
|
|
|
// $this->tree->shouldReceive(); |
19
|
|
|
|
20
|
|
|
$this->set_delete_contents( true, '_posts_test.md' ); |
21
|
|
|
$this->persist->delete_file( '_posts_test.md', 'mysha', 'this is message for delete file' ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
// public function test_should_not_add_commit_if_no_change() { |
25
|
|
|
// $this->tree |
26
|
|
|
// ->shouldReceive( 'is_changed' ) |
27
|
|
|
// ->once() |
28
|
|
|
// ->andReturn( false ); |
29
|
|
|
|
30
|
|
|
// $this->assertWPError( $error = $this->persist->commit( $this->commit ) ); |
31
|
|
|
// $this->assertSame( 'no_commit', $error->get_error_code() ); |
32
|
|
|
// } |
33
|
|
|
|
34
|
|
|
// public function test_should_fail_if_create_tree_fails() { |
35
|
|
|
// $this->tree |
36
|
|
|
// ->shouldReceive( 'is_changed' ) |
37
|
|
|
// ->once() |
38
|
|
|
// ->andReturn( true ); |
39
|
|
|
// $this->tree |
40
|
|
|
// ->shouldReceive( 'to_body' ) |
41
|
|
|
// ->once() |
42
|
|
|
// ->andReturn( |
43
|
|
|
// array( |
44
|
|
|
// 'tree' => array( |
45
|
|
|
// array( |
46
|
|
|
// 'path' => '_posts/2015-10-23-new-post.md', |
47
|
|
|
// 'type' => 'blob', |
48
|
|
|
// 'content' => 'Post content 1', |
49
|
|
|
// 'mode' => '100644', |
50
|
|
|
// ) |
51
|
|
|
// ) |
52
|
|
|
// ) |
53
|
|
|
// ); |
54
|
|
|
// $this->set_post_trees( false ); |
55
|
|
|
|
56
|
|
|
// $this->assertWPError( $error = $this->persist->commit( $this->commit ) ); |
57
|
|
|
// $this->assertSame( '404_not_found', $error->get_error_code() ); |
58
|
|
|
// } |
59
|
|
|
|
60
|
|
|
// public function test_should_fail_if_create_commit_fails() { |
61
|
|
|
// $this->tree |
62
|
|
|
// ->shouldReceive( 'is_changed' ) |
63
|
|
|
// ->once() |
64
|
|
|
// ->andReturn( true ); |
65
|
|
|
// $this->tree |
66
|
|
|
// ->shouldReceive( 'to_body' ) |
67
|
|
|
// ->once() |
68
|
|
|
// ->andReturn( |
69
|
|
|
// array( |
70
|
|
|
// 'tree' => array( |
71
|
|
|
// array( |
72
|
|
|
// 'path' => '_posts/2015-10-23-new-post.md', |
73
|
|
|
// 'type' => 'blob', |
74
|
|
|
// 'content' => 'Post content 1', |
75
|
|
|
// 'mode' => '100644', |
76
|
|
|
// ) |
77
|
|
|
// ) |
78
|
|
|
// ) |
79
|
|
|
// ); |
80
|
|
|
// $this->tree |
81
|
|
|
// ->shouldReceive( 'set_sha' ) |
82
|
|
|
// ->once() |
83
|
|
|
// ->with( 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8' ); |
84
|
|
|
// $this->commit |
85
|
|
|
// ->shouldReceive( 'to_body' ) |
86
|
|
|
// ->once() |
87
|
|
|
// ->andReturn( array( |
88
|
|
|
// 'tree' => 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8', |
89
|
|
|
// 'message' => 'Commit message', |
90
|
|
|
// 'parents' => array( 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8' ) |
91
|
|
|
// ) ); |
92
|
|
|
// $this->set_post_trees( true ); |
93
|
|
|
// $this->set_post_commits( false ); |
94
|
|
|
|
95
|
|
|
// $this->assertWPError( $error = $this->persist->commit( $this->commit ) ); |
96
|
|
|
// $this->assertSame( '404_not_found', $error->get_error_code() ); |
97
|
|
|
// } |
98
|
|
|
|
99
|
|
|
// public function test_should_fail_if_update_master_fails() { |
100
|
|
|
// $this->tree |
101
|
|
|
// ->shouldReceive( 'is_changed' ) |
102
|
|
|
// ->once() |
103
|
|
|
// ->andReturn( true ); |
104
|
|
|
// $this->tree |
105
|
|
|
// ->shouldReceive( 'to_body' ) |
106
|
|
|
// ->once() |
107
|
|
|
// ->andReturn( |
108
|
|
|
// array( |
109
|
|
|
// 'tree' => array( |
110
|
|
|
// array( |
111
|
|
|
// 'path' => '_posts/2015-10-23-new-post.md', |
112
|
|
|
// 'type' => 'blob', |
113
|
|
|
// 'content' => 'Post content 1', |
114
|
|
|
// 'mode' => '100644', |
115
|
|
|
// ) |
116
|
|
|
// ) |
117
|
|
|
// ) |
118
|
|
|
// ); |
119
|
|
|
// $this->tree |
120
|
|
|
// ->shouldReceive( 'set_sha' ) |
121
|
|
|
// ->once() |
122
|
|
|
// ->with( 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8' ); |
123
|
|
|
// $this->commit |
124
|
|
|
// ->shouldReceive( 'to_body' ) |
125
|
|
|
// ->once() |
126
|
|
|
// ->andReturn( array( |
127
|
|
|
// 'tree' => 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8', |
128
|
|
|
// 'message' => 'Commit message', |
129
|
|
|
// 'parents' => array( 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8' ) |
130
|
|
|
// ) ); |
131
|
|
|
// $this->set_post_trees( true ); |
132
|
|
|
// $this->set_post_commits( true ); |
133
|
|
|
// $this->set_patch_refs_heads_master( false ); |
134
|
|
|
|
135
|
|
|
// $this->assertWPError( $error = $this->persist->commit( $this->commit ) ); |
136
|
|
|
// $this->assertSame( '404_not_found', $error->get_error_code() ); |
137
|
|
|
// } |
138
|
|
|
|
139
|
|
|
// public function test_should_create_anonymous_commit() { |
140
|
|
|
// $this->tree |
141
|
|
|
// ->shouldReceive( 'is_changed' ) |
142
|
|
|
// ->once() |
143
|
|
|
// ->andReturn( true ); |
144
|
|
|
// $this->tree |
145
|
|
|
// ->shouldReceive( 'to_body' ) |
146
|
|
|
// ->once() |
147
|
|
|
// ->andReturn( |
148
|
|
|
// array( |
149
|
|
|
// 'tree' => array( |
150
|
|
|
// array( |
151
|
|
|
// 'path' => '_posts/2015-10-23-new-post.md', |
152
|
|
|
// 'type' => 'blob', |
153
|
|
|
// 'content' => 'Post content 1', |
154
|
|
|
// 'mode' => '100644', |
155
|
|
|
// ) |
156
|
|
|
// ) |
157
|
|
|
// ) |
158
|
|
|
// ); |
159
|
|
|
// $this->tree |
160
|
|
|
// ->shouldReceive( 'set_sha' ) |
161
|
|
|
// ->once() |
162
|
|
|
// ->with( 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8' ); |
163
|
|
|
// $this->commit |
164
|
|
|
// ->shouldReceive( 'to_body' ) |
165
|
|
|
// ->once() |
166
|
|
|
// ->andReturn( array( |
167
|
|
|
// 'tree' => 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8', |
168
|
|
|
// 'message' => 'Commit message', |
169
|
|
|
// 'parents' => array( 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8' ) |
170
|
|
|
// ) ); |
171
|
|
|
// $this->set_post_trees( true ); |
172
|
|
|
// $this->set_post_commits( true ); |
173
|
|
|
// $this->set_patch_refs_heads_master( true ); |
174
|
|
|
|
175
|
|
|
// $this->assertTrue( $this->persist->commit( $this->commit ) ); |
176
|
|
|
// } |
177
|
|
|
|
178
|
|
|
// public function test_should_create_authored_commit() { |
179
|
|
|
// $this->tree |
180
|
|
|
// ->shouldReceive( 'is_changed' ) |
181
|
|
|
// ->once() |
182
|
|
|
// ->andReturn( true ); |
183
|
|
|
// $this->tree |
184
|
|
|
// ->shouldReceive( 'to_body' ) |
185
|
|
|
// ->once() |
186
|
|
|
// ->andReturn( |
187
|
|
|
// array( |
188
|
|
|
// 'tree' => array( |
189
|
|
|
// array( |
190
|
|
|
// 'path' => '_posts/2015-10-23-new-post.md', |
191
|
|
|
// 'type' => 'blob', |
192
|
|
|
// 'content' => 'Post content 1', |
193
|
|
|
// 'mode' => '100644', |
194
|
|
|
// ) |
195
|
|
|
// ) |
196
|
|
|
// ) |
197
|
|
|
// ); |
198
|
|
|
// $this->tree |
199
|
|
|
// ->shouldReceive( 'set_sha' ) |
200
|
|
|
// ->once() |
201
|
|
|
// ->with( 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8' ); |
202
|
|
|
// $this->commit |
203
|
|
|
// ->shouldReceive( 'to_body' ) |
204
|
|
|
// ->once() |
205
|
|
|
// ->andReturn( array( |
206
|
|
|
// 'tree' => 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8', |
207
|
|
|
// 'message' => 'Commit message', |
208
|
|
|
// 'parents' => array( 'c0d2cb90b51826096c826b61a0e74d2c973d7ad8' ) |
209
|
|
|
// ) ); |
210
|
|
|
// $this->set_post_trees( true ); |
211
|
|
|
// update_option( '_wogh_export_user_id', $this->factory->user->create( array( |
212
|
|
|
// 'display_name' => 'James DiGioia', |
213
|
|
|
// 'user_email' => '[email protected]', |
214
|
|
|
// ) ) ); |
215
|
|
|
// $this->set_post_commits( true, false ); |
216
|
|
|
// $this->set_patch_refs_heads_master( true ); |
217
|
|
|
|
218
|
|
|
// $this->assertTrue( $this->persist->commit( $this->commit ) ); |
219
|
|
|
// } |
220
|
|
|
} |
221
|
|
|
|