7, 'post_type' => 'page', 'post_status' => 'draft', 'post_title' => 'Start', 'post_content' => $content], $fields )); Functions\when('get_post')->justReturn($post); Functions\when('current_user_can')->justReturn(true); Functions\when('get_permalink')->justReturn('https://kunde.test/?page_id=7'); Functions\when('add_query_arg')->alias(static fn (string $key, string $value, string $url): string => $url . '&' . $key . '=' . $value); return $post; } public static function schema(bool $diviEnabled = true): ContentSchema { $schema = Mockery::mock(ContentSchema::class); $schema->allows('isManaged')->andReturn(true); $schema->allows('diviEnabled')->andReturn($diviEnabled); return $schema; } public function testLoadsTreeIndexAndTreeRev(): void { $content = self::fixture('synthetic-basic.html'); self::givenPost($content); $page = (new DiviPageLoader(self::schema()))->load(7, true); self::assertInstanceOf(DiviPage::class, $page); self::assertSame(substr(hash('sha256', $content), 0, 12), $page->treeRev()); self::assertSame('divi/button', $page->index->find('s0.r0.c1.m2')?->name()); self::assertTrue($page->isDiviLayout()); self::assertSame('https://kunde.test/?page_id=7&et_fb=1', $page->editUrl()); self::assertNull((new DiviPageLoader(self::schema()))->writable($page)); } public function testRefusesDivi4Content(): void { self::givenPost(self::fixture('divi4-shortcodes.html')); $result = (new DiviPageLoader(self::schema()))->load(7, false); self::assertInstanceOf(WP_Error::class, $result); self::assertSame('lit_unsupported', $result->get_error_code()); self::assertStringContainsString('Divi-4', $result->get_error_message()); } public function testRefusesMalformedMarkupAndLogsIt(): void { self::givenPost(''); // error_log() is a PHP internal and cannot be stubbed; redirect it to a temp file instead. $log = (string) tempnam(sys_get_temp_dir(), 'lit-log'); $previous = ini_set('error_log', $log); try { $result = (new DiviPageLoader(self::schema()))->load(7, false); } finally { ini_set('error_log', (string) $previous); } self::assertSame('lit_unsupported', $result->get_error_code()); self::assertStringContainsString('kein gültiges Block-Markup', $result->get_error_message()); self::assertStringContainsString('divi parse of post 7 failed', (string) file_get_contents($log)); unlink($log); } public function testTrashedEntriesCanBeReadButNotWritten(): void { self::givenPost(self::fixture('synthetic-basic.html'), ['post_status' => 'trash']); $loader = new DiviPageLoader(self::schema()); self::assertInstanceOf(DiviPage::class, $loader->load(7, false)); self::assertSame('lit_validation_failed', $loader->load(7, true)->get_error_code()); } public function testWritableChecks(): void { $loader = new DiviPageLoader(self::schema(false)); self::givenPost(''); $empty = $loader->load(7, true); self::assertSame('lit_unsupported', $loader->writable($empty)->get_error_code()); $loader = new DiviPageLoader(self::schema()); self::givenPost("\n
Gutenberg
\n"); $gutenberg = $loader->load(7, true); self::assertFalse($gutenberg->isDiviLayout()); self::assertStringContainsString('kein Divi-Layout', $loader->writable($gutenberg)->get_error_message()); self::givenPost('', ['post_status' => 'future', 'post_date_gmt' => '2020-01-01 00:00:00']); $missed = $loader->load(7, true); self::assertTrue($missed->isDiviLayout()); self::assertSame('lit_validation_failed', $loader->writable($missed)->get_error_code()); } }