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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/phpunit/tests/export/snippet-verbatim.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* File summary.
*
* ```setup-blueprint global-setup
* {
* "steps": [
* {
* "step": "writeFile",
* "path": "/wordpress/wp-content/mu-plugins/global-setup.php",
* "data": "<?php\n\\Docs_Global_Registry::register( '\\Docs_Global' );\n"
* }
* ]
* }
* ```
*
* @since 1.0.0
*/

/**
* This is a function docblock.
*
* ```php interactive setup-blueprint=global-setup
* <?php
* require '/wordpress/wp-load.php';
* echo \Docs_Global::greet();
* ```
*
* ```expected-output
* Hello from \Docs_Global
* ```
*
* @since 1.0.0
*/
function snippet_verbatim_func() {}
55 changes: 55 additions & 0 deletions tests/phpunit/tests/export/snippet-verbatim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* A test case for exporting snippet source verbatim.
*/

namespace WP_Parser\Tests;

/**
* Test that snippet and Blueprint source is exported exactly as authored.
*
* Global-name prefix stripping applies to documentation prose and metadata,
* never to executable snippet source or Blueprint definitions.
*/
class Export_Snippet_Verbatim extends Export_UnitTestCase {

/**
* Test that snippet code keeps fully qualified global names.
*/
public function test_snippet_code_is_verbatim() {

$this->assertEquals(
array(
array(
'type' => 'php-code-snippet',
'code' => "<?php\nrequire '/wordpress/wp-load.php';\necho \\Docs_Global::greet();",
'expected_output' => 'Hello from \\Docs_Global',
'blueprint' => 'global-setup',
),
),
$this->export_data['functions'][0]['doc']['code_snippets']
);
}

/**
* Test that Blueprint definitions keep fully qualified global names.
*/
public function test_setup_blueprint_is_verbatim() {

$this->assertEquals(
array(
'global-setup' => array(
'steps' => array(
array(
'step' => 'writeFile',
'path' => '/wordpress/wp-content/mu-plugins/global-setup.php',
'data' => "<?php\n\\Docs_Global_Registry::register( '\\Docs_Global' );\n",
),
),
),
),
$this->export_data['functions'][0]['doc']['setup_blueprints']
);
}
}