Skip to content

Commit

Permalink
Run all tests from Template System on zip packaged plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
eliot-akira committed Nov 21, 2024
1 parent 3f1fb4b commit 6bceafd
Showing 1 changed file with 12 additions and 51 deletions.
63 changes: 12 additions & 51 deletions tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, is, ok, run } from "testra";
import { getServer } from "../vendor/tangible/template-system/framework/env";
import { test, is, ok, run } from 'testra'
import { getServer } from '../vendor/tangible/template-system/framework/env'

async function ensurePlugin({ wpx }) {
return wpx/* php */ `
Expand All @@ -22,7 +22,7 @@ if ( !get_option('site_init_done') ) {
}
return true;
`;
`
}

/**
Expand All @@ -39,61 +39,22 @@ export default run(async () => {
setSiteTemplate,
resetSiteTemplate,
} = await getServer({
phpVersion: process.env.PHP_VERSION || "7.4",
phpVersion: process.env.PHP_VERSION || '7.4',
mappings: process.env.TEST_ARCHIVE
? {
"wp-content/plugins/tangible-loops-and-logic":
"../publish/tangible-loops-and-logic",
'wp-content/plugins/tangible-loops-and-logic':
'../publish/tangible-loops-and-logic',
}
: {},
reset: true,
});
})

let result: any;
let result: any

test('Plugin - Activate', async () => {
let result = await ensurePlugin({ wpx });
is(true, result, "activate plugin");
let result = await ensurePlugin({ wpx })
is(true, result, 'activate plugin')
})

// Framework
await import("../vendor/tangible/template-system/framework/tests/index.ts");

test("Template system - Basic", async () => {
// console.log(await wpx/* php */`return scandir(ABSPATH . 'wp-content/plugins');`)

result = await wpx`return function_exists('tangible_template_system');`;
is(true, result, "tangible_template_system() exists");

result = await wpx`return function_exists('tangible_template');`;
is(true, result, "tangible_template() exists");

let template = `Hello, world.`;
result = await wpx`return tangible_template('${template}');`;
is(template, result, "tangible_template(string) runs");

/**
* Create a post and get it
* @see https://developer.wordpress.org/reference/functions/wp_insert_post/
*/

const postTitle = "Test 123";
result = await wpx/* php */ `
return wp_insert_post([
'post_type' => 'post',
'post_status' => 'publish',
'post_title' => '${postTitle}',
'post_content' => '',
'post_excerpt' => '',
]);`;

is("number", typeof result, "create post returns ID");

template = `<Loop type=post id=${result}><Field title /></Loop>`;
result = await wpx`return tangible_template('${template}');`;

is(postTitle, result, "get test post");
});

// await import('./loop/index.ts')
});
await import(`../vendor/tangible/template-system/tests/index.ts`)
})

0 comments on commit 6bceafd

Please sign in to comment.