Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor connector test implemented #1138

Merged
merged 1 commit into from
Jan 12, 2021
Merged
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
31 changes: 16 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions tests/tests/connectors/test-class-connector-editor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
namespace WP_Stream;

class Test_WP_Stream_Connector_Editor extends WP_StreamTestCase {
public function setUp() {
parent::setUp();

$this->plugin->connectors->unload_connectors();

$this->mock = $this->getMockBuilder( Connector_Editor::class )
->setMethods( array( 'log' ) )
->getMock();

$this->mock->register();
}

public function tearDown() {
parent::tearDown();
}

public function test_log_changes() {
$theme = wp_get_theme( 'twentytwenty' );
$plugin = get_plugins()['hello.php'];

$this->mock->expects( $this->exactly( 2 ) )
->method( 'log' )
->withConsecutive(
array(
$this->equalTo(
_x(
'"%1$s" in "%2$s" updated',
'1: File name, 2: Theme/plugin name',
'stream'
)
),
$this->equalTo(
array(
'file' => 'style.css',
'theme_name' => $theme->get( 'Name' ),
'theme_slug' => 'twentytwenty',
'file_path' => $theme->get_files( 'css' )['style.css'],
)
),
$this->equalTo( null ),
$this->equalTo( 'themes' ),
$this->equalTo( 'updated' ),
),
array(
$this->equalTo(
_x(
'"%1$s" in "%2$s" updated',
'1: File name, 2: Theme/plugin name',
'stream'
)
),
$this->equalTo(
array(
'file' => 'hello.php',
'plugin_name' => $plugin['Name'],
'plugin_slug' => 'hello.php',
'file_path' => WP_PLUGIN_DIR . '/hello.php',
)
),
$this->equalTo( null ),
$this->equalTo( 'plugins' ),
$this->equalTo( 'updated' ),
)
);

// Update theme file.
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['action'] = 'update';
$_POST['theme'] = 'twentytwenty';
do_action( 'load-theme-editor.php' );

\file_put_contents( $theme->get_files( 'css' )['style.css'], "\r\n", FILE_APPEND );
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a nice hack to trigger the right actions and filters 👍

apply_filters( 'wp_redirect', 'theme-editor.php' );

// Update plugin file
$_POST['plugin'] = 'hello.php';
$_POST['file'] = 'hello.php';
unset( $_POST['theme'] );
do_action( 'load-plugin-editor.php' );

\file_put_contents( WP_PLUGIN_DIR . '/hello.php', "\r\n", FILE_APPEND );
apply_filters( 'wp_redirect', 'plugin-editor.php' );
}
}