Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/playground/blueprints/src/lib/steps/site-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ export const setSiteOptions: StepHandler<SetSiteOptionsStep> = async (
code: `<?php
include ${phpVar(docroot)} . '/wp-load.php';
$site_options = ${phpVar(options)};
$flush_rewrite_rules = (
is_array($site_options) &&
array_key_exists('permalink_structure', $site_options)
) || (
is_object($site_options) &&
property_exists($site_options, 'permalink_structure')
);
foreach($site_options as $name => $value) {
update_option($name, $value);
}
if ($flush_rewrite_rules) {
flush_rewrite_rules(false);
}
echo "Success";
`,
});
Expand Down
37 changes: 37 additions & 0 deletions packages/playground/blueprints/src/tests/steps/site-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,41 @@ describe('Blueprint step setSiteOptions()', () => {
});
expect(response.text).toBe('My test site!');
});

it('should flush rewrite rules when setting permalink_structure', async () => {
await php.run({
code: `<?php
require '/wordpress/wp-load.php';
delete_option('rewrite_rules');
`,
});
const missingRules = await php.run({
code: `<?php
require '/wordpress/wp-load.php';
echo json_encode(get_option('rewrite_rules'));
`,
});
Comment on lines +48 to +59

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0a65ff4: the test now reads get_option("rewrite_rules") after delete_option() and asserts it is false before running setSiteOptions().

expect(missingRules.json).toBe(false);

await setSiteOptions(php, {
options: {
permalink_structure: '/%postname%/',
},
});

const response = await php.run({
code: `<?php
require '/wordpress/wp-load.php';
$rewrite_rules = get_option('rewrite_rules');
echo json_encode([
'permalink_structure' => get_option('permalink_structure'),
'has_rewrite_rules' => is_array($rewrite_rules) && count($rewrite_rules) > 0,
]);
`,
});
expect(response.json).toEqual({
permalink_structure: '/%postname%/',
has_rewrite_rules: true,
});
});
});
Loading