W3TCGeneric_AdminActions_Test

The W3 Total Cache W3TC Generic AdminActions Test class.

Defined (1)

The class is defined in the following location(s).

/Generic_AdminActions_Test.php  
  1. class Generic_AdminActions_Test { 
  2.  
  3. private $_config = null; 
  4.  
  5. /** 
  6. * Current page 
  7. * @var null|string 
  8. */ 
  9. private $_page = null; 
  10.  
  11. function __construct() { 
  12. $this->_config = Dispatcher::config(); 
  13.  
  14. $this->_page = Util_Admin::get_current_page(); 
  15.  
  16.  
  17. /** 
  18. * Test memcached 
  19. * @return void 
  20. */ 
  21. function w3tc_test_memcached() { 
  22. $servers = Util_Request::get_array( 'servers' ); 
  23.  
  24. $this->respond_test_result( $this->is_memcache_available( $servers ) ); 
  25.  
  26. /** 
  27. * Test memcached 
  28. * @return void 
  29. */ 
  30. function w3tc_test_redis() { 
  31. $servers = Util_Request::get_array( 'servers' ); 
  32.  
  33. if ( count( $servers ) <= 0 ) 
  34. $success = false; 
  35. else { 
  36. $success = true; 
  37.  
  38. foreach ( $servers as $server ) { 
  39. @$cache = Cache::instance( 'redis', array( 
  40. 'servers' => $server,  
  41. 'persistent' => false 
  42. ) ); 
  43. if ( is_null( $cache ) ) 
  44. $success = false; 
  45.  
  46. $test_string = sprintf( 'test_' . md5( time() ) ); 
  47. $test_value = array( 'content' => $test_string ); 
  48. $cache->set( $test_string, $test_value, 60 ); 
  49. $test_value = $cache->get( $test_string ); 
  50. if ( $test_value['content'] != $test_string ) 
  51. $success = false; 
  52.  
  53. $this->respond_test_result( $success ); 
  54.  
  55. private function respond_test_result( $success ) { 
  56. if ( $success ) { 
  57. $response = array( 
  58. 'result' => true,  
  59. 'error' => __( 'Test passed.', 'w3-total-cache' ) 
  60. ); 
  61. } else { 
  62. $response = array( 
  63. 'result' => false,  
  64. 'error' => __( 'Test failed.', 'w3-total-cache' ) 
  65. ); 
  66.  
  67. echo json_encode( $response ); 
  68. exit(); 
  69.  
  70. /** 
  71. * Test minifier action 
  72. * @return void 
  73. */ 
  74. function w3tc_test_minifier() { 
  75. $engine = Util_Request::get_string( 'engine' ); 
  76. $path_java = Util_Request::get_string( 'path_java' ); 
  77. $path_jar = Util_Request::get_string( 'path_jar' ); 
  78.  
  79. $result = false; 
  80. $error = ''; 
  81.  
  82. if ( $engine != 'googleccjs' ) { 
  83. if ( !$path_java ) 
  84. $error = __( 'Empty JAVA executable path.', 'w3-total-cache' ); 
  85. elseif ( !$path_jar ) 
  86. $error = __( 'Empty JAR file path.', 'w3-total-cache' ); 
  87.  
  88. if ( empty( $error ) ) { 
  89. switch ( $engine ) { 
  90. case 'yuijs': 
  91. \Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir(); 
  92. \Minify_YUICompressor::$javaExecutable = $path_java; 
  93. \Minify_YUICompressor::$jarFile = $path_jar; 
  94.  
  95. $result = \Minify_YUICompressor::testJs( $error ); 
  96. break; 
  97.  
  98. case 'yuicss': 
  99. \Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir(); 
  100. \Minify_YUICompressor::$javaExecutable = $path_java; 
  101. \Minify_YUICompressor::$jarFile = $path_jar; 
  102.  
  103. $result = \Minify_YUICompressor::testCss( $error ); 
  104. break; 
  105.  
  106. case 'ccjs': 
  107. \Minify_ClosureCompiler::$tempDir = Util_File::create_tmp_dir(); 
  108. \Minify_ClosureCompiler::$javaExecutable = $path_java; 
  109. \Minify_ClosureCompiler::$jarFile = $path_jar; 
  110.  
  111. $result = \Minify_ClosureCompiler::test( $error ); 
  112. break; 
  113.  
  114. case 'googleccjs': 
  115.  
  116. $result = \Minify_JS_ClosureCompiler::test( $error ); 
  117. break; 
  118.  
  119. default: 
  120. $error = __( 'Invalid engine.', 'w3-total-cache' ); 
  121. break; 
  122.  
  123. $response = array( 
  124. 'result' => $result,  
  125. 'error' => $error 
  126. ); 
  127.  
  128. echo json_encode( $response ); 
  129.  
  130. /** 
  131. * Check if memcache is available 
  132. * @param array $servers 
  133. * @return boolean 
  134. */ 
  135. private function is_memcache_available( $servers ) { 
  136. if ( count( $servers ) <= 0 ) 
  137. return false; 
  138.  
  139. foreach ( $servers as $server ) { 
  140. @$memcached = Cache::instance( 'memcached', array( 
  141. 'servers' => $server,  
  142. 'persistent' => false 
  143. ) ); 
  144. if ( is_null( $memcached ) ) 
  145. return false; 
  146.  
  147. $test_string = sprintf( 'test_' . md5( time() ) ); 
  148. $test_value = array( 'content' => $test_string ); 
  149. $memcached->set( $test_string, $test_value, 60 ); 
  150. $test_value = $memcached->get( $test_string ); 
  151. if ( $test_value['content'] != $test_string ) 
  152. return false; 
  153.  
  154. return true; 
  155.  
  156. /** 
  157. * Self test action 
  158. */ 
  159. function w3tc_test_self() { 
  160. include W3TC_INC_LIGHTBOX_DIR . '/self_test.php'; 
  161.  
  162. /** 
  163. * Minify recommendations action 
  164. * @return void 
  165. */ 
  166. function w3tc_test_minify_recommendations() { 
  167. $options_minify = new Minify_Page(); 
  168. $options_minify->recommendations(); 
  169.  
  170.  
  171. /** 
  172. * Page Speed results action 
  173. * @return void 
  174. */ 
  175. function w3tc_test_pagespeed_results() { 
  176. $title = 'Google Page Speed'; 
  177.  
  178. $config = Dispatcher::config(); 
  179. $key = $config->get_string( 'widget.pagespeed.key' ); 
  180. $w3_pagespeed = new PageSpeed_Api( $key ); 
  181.  
  182. $results = $w3_pagespeed->analyze( get_home_url() ); 
  183. include W3TC_INC_POPUP_DIR . '/pagespeed_results.php';