88use Smartling \Helpers \WordpressFunctionProxyHelper ;
99use Smartling \Replacers \ReplacerFactory ;
1010use Smartling \Settings \SettingsManager ;
11+ use Smartling \Submissions \SubmissionEntity ;
12+ use Smartling \Submissions \SubmissionManager ;
1113
12- class AcfDynamicSupportTest extends TestCase {
14+ class AcfDynamicSupportTest extends TestCase
15+ {
16+ protected function setUp (): void
17+ {
18+ defined ('ARRAY_A ' ) || define ('ARRAY_A ' , 'ARRAY_A ' );
19+ parent ::setUp ();
20+ }
1321
1422 public function testGetReplacerIdForField ()
1523 {
1624 $ x = new class (
1725 new ArrayHelper (),
1826 $ this ->createMock (SettingsManager::class),
1927 $ this ->createMock (SiteHelper::class),
28+ $ this ->createMock (SubmissionManager::class),
2029 $ this ->createMock (WordpressFunctionProxyHelper::class),
2130 ) extends AcfDynamicSupport {
2231 public
@@ -30,4 +39,102 @@ function run(): void
3039 'someAttribute ' ,
3140 ));
3241 }
42+
43+ public function testSyncFieldGroup ()
44+ {
45+ $ sourceBlogId = 1 ;
46+ $ targetBlogId = 7 ;
47+ $ fieldGroupSubmissionTargetId = 11 ;
48+
49+ $ fieldGroupSubmission = $ this ->createMock (SubmissionEntity::class);
50+ $ fieldGroupSubmission ->method ('getContentType ' )->willReturn (AcfDynamicSupport::POST_TYPE_ACF_FIELD_GROUP );
51+ $ fieldGroupSubmission ->method ('getSourceBlogId ' )->willReturn ($ sourceBlogId );
52+ $ fieldGroupSubmission ->method ('getSourceId ' )->willReturn (3 );
53+ $ fieldGroupSubmission ->method ('getTargetBlogId ' )->willReturn ($ targetBlogId );
54+ $ fieldGroupSubmission ->method ('getTargetId ' )->willReturn ($ fieldGroupSubmissionTargetId );
55+
56+ $ pageSourceId = 4052 ;
57+ $ pageTargetId = 12 ;
58+
59+ $ submission4052 = $ this ->createMock (SubmissionEntity::class);
60+ $ submission4052 ->method ('getContentType ' )->willReturn ('post ' );
61+ $ submission4052 ->method ('getSourceBlogId ' )->willReturn ($ sourceBlogId );
62+ $ submission4052 ->method ('getSourceId ' )->willReturn ($ pageSourceId );
63+ $ submission4052 ->method ('getTargetBlogId ' )->willReturn ($ targetBlogId );
64+ $ submission4052 ->method ('getTargetId ' )->willReturn ($ pageTargetId );
65+
66+ $ postSubmissions = [
67+ $ pageSourceId => $ submission4052 ,
68+ ];
69+
70+ $ submissionManager = $ this ->createMock (SubmissionManager::class);
71+ $ submissionManager ->method ('findOne ' )->willReturnCallback (function ($ arguments ) use ($ postSubmissions ) {
72+ return $ postSubmissions [$ arguments [SubmissionEntity::FIELD_SOURCE_ID ]] ?? null ;
73+ });
74+
75+ $ wpProxy = $ this ->createMock (WordpressFunctionProxyHelper::class);
76+ $ wpProxy ->method ('maybe_unserialize ' )->willReturnCallback (function ($ data ) {
77+ return unserialize ($ data );
78+ });
79+ $ source = [
80+ 'location ' => [
81+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'video ' ]],
82+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'blog ' ]],
83+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'bt_event ' ]],
84+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'bt_news ' ]],
85+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'report ' ]],
86+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'webinar ' ]],
87+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'solution-guide ' ]],
88+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'ebook ' ]],
89+ [['param ' => 'post_type ' , 'operator ' => '== ' , 'value ' => 'whitepaper ' ]],
90+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => (string )$ pageSourceId ]],
91+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '690 ' ]],
92+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '2111 ' ]],
93+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '1662 ' ]],
94+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '29 ' ]],
95+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '31 ' ]],
96+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '32 ' ]],
97+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '33 ' ]],
98+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '30 ' ]],
99+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '818 ' ]],
100+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '98 ' ]],
101+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '824 ' ]],
102+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '3387 ' ]],
103+ [['param ' => 'page ' , 'operator ' => '== ' , 'value ' => '798 ' ]],
104+ ],
105+ 'position ' => 'normal ' ,
106+ 'style ' => 'default ' ,
107+ 'label_placement ' => 'top ' ,
108+ 'instruction_placement ' => 'label ' ,
109+ 'hide_on_screen ' => '' ,
110+ 'description ' => '' ,
111+ 'show_in_rest ' => 0 ,
112+ ];
113+
114+ $ expectedContent = $ source ;
115+ $ expectedContent ['location ' ][9 ][0 ]['value ' ] = (string )$ pageTargetId ;
116+
117+ $ wpProxy ->method ('get_post ' )->willReturn ([
118+ 'post_content ' => serialize ($ source ),
119+ ]);
120+ $ wpProxy ->expects ($ this ->once ())->method ('wp_update_post ' )->with ([
121+ 'ID ' => $ fieldGroupSubmissionTargetId ,
122+ 'post_content ' => serialize ($ expectedContent ),
123+ ]);
124+
125+ $ siteHelper = $ this ->createMock (SiteHelper::class);
126+ $ siteHelper ->method ('withBlog ' )->willReturnCallback (function ($ blogId , $ callable ) {
127+ return $ callable ();
128+ });
129+
130+ $ x = new AcfDynamicSupport (
131+ new ArrayHelper (),
132+ $ this ->createMock (SettingsManager::class),
133+ $ siteHelper ,
134+ $ submissionManager ,
135+ $ wpProxy
136+ );
137+
138+ $ x ->syncFieldGroup ($ fieldGroupSubmission );
139+ }
33140}
0 commit comments