@@ -95,11 +95,11 @@ public function test_controller_exception($forum, $user_id, $status_code, $page_
9595 }
9696
9797 /**
98- * Test data for the test_submit_success test
98+ * Test data for the test_post_success test
9999 *
100100 * @return array Array of test data
101101 */
102- public function submit_success_data ()
102+ public function post_success_data ()
103103 {
104104 return array (
105105 array (true ),
@@ -108,27 +108,27 @@ public function submit_success_data()
108108 }
109109
110110 /**
111- * Test submit
111+ * Test post
112112 *
113- * @dataProvider submit_success_data
113+ * @dataProvider post_success_data
114114 */
115- public function test_submit_success ($ is_newly_registered_user )
115+ public function test_post_success ($ is_newly_registered_user )
116116 {
117117 /** @var \phpbb\ideas\controller\post_controller $controller */
118118 $ controller = $ this ->get_controller ('post_controller ' );
119119 $ this ->assertInstanceOf ('phpbb\ideas\controller\post_controller ' , $ controller );
120120
121- $ this ->controller_helper ->expects ($ this ->any ())
121+ $ this ->controller_helper ->expects ($ this ->once ())
122122 ->method ('route ' )
123123 ->will ($ this ->returnValue ('phpbb_ideas_idea_controller ' ));
124124
125- $ this ->request ->expects ($ this ->any ())
126- ->method ('variable ' )
125+ $ this ->request ->expects ($ this ->once ())
126+ ->method ('is_set_post ' )
127127 ->will ($ this ->returnValueMap (array (
128- array ('mode ' , '' , false , \ phpbb \ request \request_interface:: REQUEST , ' submit ' ),
128+ array ('post ' , true ),
129129 )));
130130
131- $ this ->auth ->expects ($ this ->any ())
131+ $ this ->auth ->expects ($ this ->once ())
132132 ->method ('acl_get ' )
133133 ->with ('f_noapprove ' , $ this ->config ['ideas_forum_id ' ])
134134 ->will ($ this ->returnValue (!$ is_newly_registered_user ));
@@ -139,14 +139,55 @@ public function test_submit_success($is_newly_registered_user)
139139 }
140140
141141 // ideas->submit() will return an idea id on successful submit
142- $ this ->ideas ->expects ($ this ->any ())
142+ $ this ->ideas ->expects ($ this ->once ())
143143 ->method ('submit ' )
144144 ->will ($ this ->returnValue (1 ));
145145
146146 $ response = $ controller ->post ();
147147 $ this ->assertInstanceOf ('\Symfony\Component\HttpFoundation\RedirectResponse ' , $ response );
148148 }
149149
150+ /**
151+ * Test preview
152+ */
153+ public function test_preview ()
154+ {
155+ /** @var \phpbb\ideas\controller\post_controller $controller */
156+ $ controller = $ this ->get_controller ('post_controller ' );
157+ $ this ->assertInstanceOf ('phpbb\ideas\controller\post_controller ' , $ controller );
158+
159+ $ this ->request ->expects ($ this ->any ())
160+ ->method ('is_set_post ' )
161+ ->will ($ this ->returnValueMap (array (
162+ array ('post ' , false ),
163+ array ('preview ' , true ),
164+ )));
165+
166+ $ this ->request ->expects ($ this ->atLeastOnce ())
167+ ->method ('variable ' )
168+ ->will ($ this ->returnValueMap (array (
169+ array ('title ' , '' , true , \phpbb \request \request_interface::REQUEST , 'test title ' ),
170+ array ('message ' , '' , true , \phpbb \request \request_interface::REQUEST , 'test message ' ),
171+ )));
172+
173+ $ this ->ideas ->expects ($ this ->never ())
174+ ->method ('submit ' );
175+
176+ $ this ->ideas ->expects ($ this ->once ())
177+ ->method ('preview ' )
178+ ->willReturn ('test message ' );
179+
180+ $ this ->template ->expects ($ this ->at (0 ))
181+ ->method ('assign_vars ' )
182+ ->with (array (
183+ 'S_DISPLAY_PREVIEW ' => true ,
184+ 'PREVIEW_SUBJECT ' => 'test title ' ,
185+ 'PREVIEW_MESSAGE ' => 'test message '
186+ ));
187+
188+ $ controller ->post ();
189+ }
190+
150191 /**
151192 * Test submit errors
152193 */
@@ -156,16 +197,22 @@ public function test_submit_errors()
156197 $ controller = $ this ->get_controller ('post_controller ' );
157198 $ this ->assertInstanceOf ('phpbb\ideas\controller\post_controller ' , $ controller );
158199
159- $ this ->request ->expects ($ this ->any ())
200+ $ this ->request ->expects ($ this ->atLeastOnce ())
201+ ->method ('is_set_post ' )
202+ ->will ($ this ->returnValueMap (array (
203+ array ('post ' , true ),
204+ array ('preview ' , false ),
205+ )));
206+
207+ $ this ->request ->expects ($ this ->atLeastOnce ())
160208 ->method ('variable ' )
161209 ->will ($ this ->returnValueMap (array (
162- array ('mode ' , '' , false , \phpbb \request \request_interface::REQUEST , 'submit ' ),
163210 array ('title ' , '' , true , \phpbb \request \request_interface::REQUEST , 'test title ' ),
164211 array ('message ' , '' , true , \phpbb \request \request_interface::REQUEST , 'test message ' ),
165212 )));
166213
167214 // ideas->submit() will return an array of error messages on submit error
168- $ this ->ideas ->expects ($ this ->any ())
215+ $ this ->ideas ->expects ($ this ->once ())
169216 ->method ('submit ' )
170217 ->will ($ this ->returnValue (array ('error1 ' , 'error2 ' )));
171218
0 commit comments