@@ -66,6 +66,23 @@ function set_siteurl($site_url) {
6666 $ statement ->execute ();
6767}
6868
69+ function clear_settings () {
70+ $ db = new mysqli (getenv ('HOST_IP ' ), 'root ' , getenv ('MYSQL_ROOT_PASSWORD ' ), getenv ('WORDPRESS_DATABASE ' ));
71+ $ statement = $ db ->prepare ("DELETE FROM wp_options WHERE option_name LIKE 'tinypng_%' " );
72+ $ statement ->execute ();
73+ $ statement = $ db ->prepare ("DELETE FROM wp_usermeta WHERE meta_key LIKE 'tinypng_%' " );
74+ $ statement ->execute ();
75+ }
76+
77+ function clear_uploads () {
78+ $ db = new mysqli (getenv ('HOST_IP ' ), 'root ' , getenv ('MYSQL_ROOT_PASSWORD ' ), getenv ('WORDPRESS_DATABASE ' ));
79+ $ statement = $ db ->prepare ("DELETE wp_postmeta FROM wp_postmeta JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id WHERE wp_posts.post_type = 'attachment' " );
80+ $ statement ->execute ();
81+ $ statement = $ db ->prepare ("DELETE FROM wp_posts WHERE wp_posts.post_type = 'attachment' " );
82+ $ statement ->execute ();
83+ shell_exec ('docker exec -it wordpress ' . getenv ('WORDPRESS_VERSION ' ) . ' rm -rf wp-content/uploads ' );
84+ }
85+
6986function is_wordpress_setup () {
7087 $ db = new mysqli (getenv ('HOST_IP ' ), 'root ' , getenv ('MYSQL_ROOT_PASSWORD ' ));
7188 if ($ result = $ db ->query ("SELECT * FROM information_schema.tables WHERE table_schema = ' " . getenv ('WORDPRESS_DATABASE ' ) . "' " )) {
@@ -100,20 +117,6 @@ function setup_wordpress_site($driver) {
100117 }
101118}
102119
103- function clear_uploads ($ driver ) {
104- media_bulk_action ($ driver , 'delete ' );
105- }
106-
107- function media_bulk_action ($ driver , $ action ) {
108- $ driver ->get (wordpress ('/wp-admin/upload.php?mode=list ' ));
109- $ checkboxes = $ driver ->findElements (WebDriverBy::cssSelector ('th input[type="checkbox"] ' ));
110- if (count ($ checkboxes ) > 0 ) {
111- $ checkboxes [0 ]->click ();
112- $ driver ->findElement (WebDriverBy::cssSelector ('select[name="action"] option[value=" ' . $ action . '"] ' ))->click ();
113- $ driver ->findElement (WebDriverBy::cssSelector ('div.actions input[value="Apply"] ' ))->click ();
114- }
115- }
116-
117120function login ($ driver ) {
118121 $ driver ->get (wordpress ('/wp-login.php ' ));
119122 $ driver ->findElement (WebDriverBy::tagName ('body ' ))->click ();
@@ -142,9 +145,15 @@ function activate_plugin($driver) {
142145 }
143146}
144147
145- register_shutdown_function ('restore_wordpress ' );
148+ function close_webdriver () {
149+ RemoteWebDriver::createBySessionId ($ GLOBALS ['global_session_id ' ], $ GLOBALS ['global_webdriver_host ' ])->close ();
150+ }
146151
147- $ global_phantom_host = 'http://127.0.0.1:4444/wd/hub ' ;
148- $ global_driver = RemoteWebDriver::create ($ global_phantom_host , DesiredCapabilities::firefox ());
152+ $ global_webdriver_host = 'http://127.0.0.1:4444/wd/hub ' ;
153+ $ global_driver = RemoteWebDriver::create ($ global_webdriver_host , DesiredCapabilities::firefox ());
149154$ global_session_id = $ global_driver ->getSessionID ();
155+
156+ register_shutdown_function ('close_webdriver ' );
157+ register_shutdown_function ('restore_wordpress ' );
158+
150159configure_wordpress_for_testing ($ global_driver );
0 commit comments