Skip to content

Commit a259e71

Browse files
authored
Merge pull request #1138 from xwp/tests/editor-connector
Editor connector test implemented
2 parents abfee72 + ad38231 commit a259e71

File tree

2 files changed

+104
-15
lines changed

2 files changed

+104
-15
lines changed

composer.lock

Lines changed: 16 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
namespace WP_Stream;
3+
4+
class Test_WP_Stream_Connector_Editor extends WP_StreamTestCase {
5+
public function setUp() {
6+
parent::setUp();
7+
8+
$this->plugin->connectors->unload_connectors();
9+
10+
$this->mock = $this->getMockBuilder( Connector_Editor::class )
11+
->setMethods( array( 'log' ) )
12+
->getMock();
13+
14+
$this->mock->register();
15+
}
16+
17+
public function tearDown() {
18+
parent::tearDown();
19+
}
20+
21+
public function test_log_changes() {
22+
$theme = wp_get_theme( 'twentytwenty' );
23+
$plugin = get_plugins()['hello.php'];
24+
25+
$this->mock->expects( $this->exactly( 2 ) )
26+
->method( 'log' )
27+
->withConsecutive(
28+
array(
29+
$this->equalTo(
30+
_x(
31+
'"%1$s" in "%2$s" updated',
32+
'1: File name, 2: Theme/plugin name',
33+
'stream'
34+
)
35+
),
36+
$this->equalTo(
37+
array(
38+
'file' => 'style.css',
39+
'theme_name' => $theme->get( 'Name' ),
40+
'theme_slug' => 'twentytwenty',
41+
'file_path' => $theme->get_files( 'css' )['style.css'],
42+
)
43+
),
44+
$this->equalTo( null ),
45+
$this->equalTo( 'themes' ),
46+
$this->equalTo( 'updated' ),
47+
),
48+
array(
49+
$this->equalTo(
50+
_x(
51+
'"%1$s" in "%2$s" updated',
52+
'1: File name, 2: Theme/plugin name',
53+
'stream'
54+
)
55+
),
56+
$this->equalTo(
57+
array(
58+
'file' => 'hello.php',
59+
'plugin_name' => $plugin['Name'],
60+
'plugin_slug' => 'hello.php',
61+
'file_path' => WP_PLUGIN_DIR . '/hello.php',
62+
)
63+
),
64+
$this->equalTo( null ),
65+
$this->equalTo( 'plugins' ),
66+
$this->equalTo( 'updated' ),
67+
)
68+
);
69+
70+
// Update theme file.
71+
$_SERVER['REQUEST_METHOD'] = 'POST';
72+
$_POST['action'] = 'update';
73+
$_POST['theme'] = 'twentytwenty';
74+
do_action( 'load-theme-editor.php' );
75+
76+
\file_put_contents( $theme->get_files( 'css' )['style.css'], "\r\n", FILE_APPEND );
77+
apply_filters( 'wp_redirect', 'theme-editor.php' );
78+
79+
// Update plugin file
80+
$_POST['plugin'] = 'hello.php';
81+
$_POST['file'] = 'hello.php';
82+
unset( $_POST['theme'] );
83+
do_action( 'load-plugin-editor.php' );
84+
85+
\file_put_contents( WP_PLUGIN_DIR . '/hello.php', "\r\n", FILE_APPEND );
86+
apply_filters( 'wp_redirect', 'plugin-editor.php' );
87+
}
88+
}

0 commit comments

Comments
 (0)