allows('catalog')->andReturn(DiviFixtures::catalog()); $modules->allows('builderVersion')->andReturn('5.2.1'); return $modules; } public static function designReader(): DesignSystemReader { $design = Mockery::mock(DesignSystemReader::class); $design->allows('read')->andReturn(DiviFixtures::designSystem()); return $design; } /** * $design is the reader the writer gets too (one instance, like the live wiring); without * $registry the composition uses DynamicContentMap's default (VariableRef's built-in map in * unit tests, where Divi's classes are missing). */ public static function composition( DesignSystemReader $design, bool $unfiltered = false, ?DynamicContentMap $registry = null ): DiviComposition { return new DiviComposition( self::modules(), $design, ComposeFixture::sanitizer($unfiltered), ComposeFixture::media(), $registry ?? new DynamicContentMap() ); } /** * A DiviSaver whose save() appends the content to $saved, puts it on the post and reports * revision 811. Each call first takes the next entry of $failures and throws it, if any. * * @param list $saved * @param list $failures */ public static function saver(array &$saved, array &$failures = []): DiviSaver { $saver = Mockery::mock(DiviSaver::class); $saver->allows('save')->andReturnUsing(static function (WP_Post $post, string $content) use (&$saved, &$failures): array { $failure = array_shift($failures); if ($failure !== null) { throw $failure; } $saved[] = $content; $post->post_content = $content; return ['revision_id' => 811, 'warnings' => []]; }); return $saver; } /** A ChangeLog that accepts records (log ids from 4711). */ public static function log(): FakeChangeLog { return new FakeChangeLog(4711); } /** * The writer over the page of DiviFixtures::givenPost(), saving into $saved (see saver()). * * @param list $saved * @param list $failures */ public static function writer( array &$saved, array &$failures = [], bool $unfiltered = false, ?DiviPageLoader $loader = null, ?GlobalEdits $globals = null, ?ThemeBuilderEdits $themeBuilder = null, ?SimilarSections $similar = null ): DiviWriter { $design = self::designReader(); return new DiviWriter( $loader ?? new DiviPageLoader(DiviFixtures::schema()), self::saver($saved, $failures), self::log(), $design, self::composition($design, $unfiltered), $globals, $themeBuilder, $similar ); } }