@@ -115,6 +115,7 @@ public function test_getSubscribedEvents()
115115 'core.posting_modify_template_vars ' ,
116116 'core.posting_modify_submit_post_before ' ,
117117 'core.posting_modify_submit_post_after ' ,
118+ 'core.mcp_change_poster_after ' ,
118119 ), array_keys (\phpbb \ideas \event \listener::getSubscribedEvents ()));
119120 }
120121
@@ -672,6 +673,57 @@ public function test_submit_idea($mode, $forum_id, $topic_id, $approved, $succes
672673
673674 $ listener ->submit_idea_after ($ event );
674675 }
676+
677+ /**
678+ * Data set for change_idea_author
679+ *
680+ * @return array Array of test data
681+ */
682+ public function change_idea_author_data ()
683+ {
684+ return [
685+ [2 , 1 , 1 , 2 , true ], // Valid: ideas forum, different authors
686+ [1 , 1 , 1 , 2 , false ], // Invalid: not ideas forum
687+ [2 , 1 , 1 , 1 , false ], // Invalid: same author
688+ ];
689+ }
690+
691+ /**
692+ * Test the change_idea_author event
693+ *
694+ * @dataProvider change_idea_author_data
695+ */
696+ public function test_change_idea_author ($ forum_id , $ topic_id , $ old_author_id , $ new_author_id , $ should_update )
697+ {
698+ $ listener = $ this ->get_listener ();
699+
700+ $ event = new \phpbb \event \data ([
701+ 'post_info ' => [
702+ 'forum_id ' => $ forum_id ,
703+ 'topic_id ' => $ topic_id ,
704+ 'poster_id ' => $ old_author_id ,
705+ ],
706+ 'userdata ' => [
707+ 'user_id ' => $ new_author_id ,
708+ ],
709+ ]);
710+
711+ $ idea_data = [
712+ 'idea_id ' => 1 ,
713+ 'idea_author ' => $ old_author_id ,
714+ ];
715+
716+ $ this ->idea ->expects ($ should_update ? self ::once () : self ::never ())
717+ ->method ('get_idea_by_topic_id ' )
718+ ->with ($ topic_id )
719+ ->willReturn ($ idea_data );
720+
721+ $ this ->idea ->expects ($ should_update ? self ::once () : self ::never ())
722+ ->method ('set_author ' )
723+ ->with (1 , $ new_author_id );
724+
725+ $ listener ->change_idea_author ($ event );
726+ }
675727}
676728
677729/**
0 commit comments