Enhance article import functionality: Add author selection and preserve attribution during imports; update metadata version to 1.1.2.
This commit is contained in:
1 parent
41e623d5d1
commit
c56ae0ced2
5 files changed
+73
-15
No files matched your search
@@ -93,6 +93,7 @@ $pages = new Pages(); $categories = new TestIndex(); $tags = new TestIndex(); $s
|
||||
$site = new class { public function sortBy() { return 'date'; } public function uriFilters($unused = null) { return ''; } };
|
||||
$L = new class { public function g($s) { return $s; } public function getunicodeChars() { return []; } public function currentLanguage() { return 'en'; } };
|
||||
Session::set('username', 'admin');
|
||||
$users = new class { public function keys() { return ['admin', 'spleenftw']; } public function exists($name) { return in_array($name, $this->keys(), true); } };
|
||||
$plugin = new TestPlugin();
|
||||
$plugin->init();
|
||||
try {
|
||||
@@ -213,6 +214,36 @@ try {
|
||||
$plan['created'] = time() - 1801; Session::set('bluditGithubImport', $plan);
|
||||
rejects(function () use ($plugin, $plan) { $plugin->invoke('confirmImport', $plan['confirmation']); }, 'expired');
|
||||
|
||||
// New pages must use the chosen author despite createPage() forcing the session user.
|
||||
$plugin->fixture('author-new', document('author-new', 'body'));
|
||||
$plugin->requests = [];
|
||||
$plugin->invoke('previewImport', 'author-new', true, 'spleenftw'); $plan = Session::get('bluditGithubImport');
|
||||
check($plan['args']['username'] === 'spleenftw' && strpos($plugin->form(), '>Author</dt><dd>spleenftw') !== false, 'Preview selected author');
|
||||
$plugin->invoke('confirmImport', $plan['confirmation']);
|
||||
check((new Page('author-new'))->username() === 'spleenftw', 'New import uses selected author');
|
||||
check(Session::get('username') === 'admin', 'Do not impersonate the selected author');
|
||||
check(count(array_filter($plugin->requests, function ($r) { return $r[0] !== 'GET'; })) === 0, 'Author adjustment must not trigger exports');
|
||||
$exported = $plugin->invoke('buildMarkdown', new Page('author-new'), 'author-new', 'body');
|
||||
check(BluditGithubImport::document($exported, 'author-new')['meta']['author'] === 'spleenftw', 'Export the actual author');
|
||||
|
||||
// Repair an existing admin-authored page without changing its UUID or body intent.
|
||||
$plugin->fixture('article', document('article', 'corrected article'));
|
||||
$oldUuid = (new Page('article'))->uuid();
|
||||
$plugin->invoke('previewImport', 'article', true, 'spleenftw'); $plan = Session::get('bluditGithubImport');
|
||||
$plugin->invoke('confirmImport', $plan['confirmation']);
|
||||
check((new Page('article'))->username() === 'spleenftw' && (new Page('article'))->uuid() === $oldUuid, 'Update existing author in place');
|
||||
$plugin->invoke('previewImport', 'article', true); $plan = Session::get('bluditGithubImport');
|
||||
check($plan['args']['username'] === 'spleenftw', 'Legacy documents without author preserve existing author');
|
||||
$plugin->fixture('author-meta', document('author-meta', 'body', "author: spleenftw\n"));
|
||||
$plugin->invoke('previewImport', 'author-meta', true); $plan = Session::get('bluditGithubImport');
|
||||
$plugin->invoke('confirmImport', $plan['confirmation']);
|
||||
check((new Page('author-meta'))->username() === 'spleenftw', 'Repository author survives creation');
|
||||
$plugin->fixture('author-bad', document('author-bad', 'body', "author: unknown\n"));
|
||||
rejects(function () use ($plugin) { $plugin->invoke('previewImport', 'author-bad', true); }, 'author does not exist');
|
||||
$plugin->invoke('previewImport', 'author-bad', true, 'spleenftw');
|
||||
check(Session::get('bluditGithubImport')['args']['username'] === 'spleenftw', 'A valid explicit selection overrides an unavailable repository author');
|
||||
echo "PASS: selected/repository authors on create and update, author export, no impersonation or export loop\n";
|
||||
|
||||
// Optional end-to-end fixture using an actual exported article directory.
|
||||
if (($articleDir = getenv('BLOG_ARTICLE_DIR'))) {
|
||||
$slug = basename(rtrim($articleDir, '/'));
|
||||
|
||||
Reference in new issue
Block a user