Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Discover tests in wp-tests directory of all active plugins.

  • Loading branch information...
commit 2e42960710a9de9d05ad0932a9feb6f624f515fa 1 parent df94b1c
authored
2  init.php
@@ -38,3 +38,5 @@
38 38
 
39 39
 require WP_TESTS_PATH . '/lib/testcase.php';
40 40
 require WP_TESTS_PATH . '/lib/exceptions.php';
  41
+
  42
+wp_test_load_plugin_tests();
54  lib/functions.php
... ...
@@ -1,21 +1,61 @@
1 1
 <?php
2 2
 
3 3
 function wptest_install_plugins($plugins) {
4  
-	
5 4
 	foreach($plugins as $plugin) {
6 5
 		activate_plugin($plugin);
7 6
 	}
8 7
 }
9 8
 
10 9
 
11  
-function wptest_load_plugin_tests() {
12  
-
13  
-}
14  
-
15  
-function wptest_load_muplugin_tests() {
16  
-
  10
+function wp_test_load_plugin_tests() {
  11
+	$plugins = wp_get_active_and_valid_plugins();
  12
+	if(is_multisite()) {
  13
+		$plugins = array_merge($plugins, wp_get_active_network_plugins());
  14
+	}
  15
+	foreach($plugins as $plugin) {
  16
+		$dirname = dirname($plugin);
  17
+		if($dirname != WP_PLUGIN_DIR) {
  18
+			wp_test_load_tests($dirname);
  19
+		}
  20
+	}	
17 21
 }
18 22
 
  23
+/**
  24
+ * Load theme tests.
  25
+ **/
19 26
 function wptest_load_theme_tests() {
  27
+	// unfinished, obviously.
  28
+}
20 29
 
  30
+/**
  31
+ * Load scripts that should contain test cases from a directory inside of $dir
  32
+ * @todo support an array of possible test directories
  33
+ *
  34
+ * @param string $dir
  35
+ * @param string $test_dir
  36
+ **/
  37
+function wp_test_load_tests( $dir, $test_dirs = array('wp-tests'), $starts_with = 'test_') { 
  38
+	if(!is_dir($dir) || $dir[0] == '.') return false;
  39
+	
  40
+	foreach($test_dirs as $test_dir) {
  41
+		if($test_dir[0] == '.') continue;
  42
+
  43
+		$tests_path = realpath(rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $test_dir);		
  44
+		
  45
+		if($dh = opendir($tests_path)) {
  46
+
  47
+			// read through the test directory looking for tests
  48
+			while (($file = readdir($dh)) !== false) {
  49
+				$path = realpath($tests_path . DIRECTORY_SEPARATOR . $file);
  50
+
  51
+				$fileparts = pathinfo($file);
  52
+
  53
+				// add .php files starting with 'test'
  54
+				if (is_file($path) && strpos($fileparts['basename'], $starts_with) === 0 && $fileparts['extension'] == 'php') {
  55
+					require_once $path;
  56
+				}
  57
+			}
  58
+			closedir($dh);
  59
+		}
  60
+	}
21 61
 }

0 notes on commit 2e42960

Please sign in to comment.
Something went wrong with that request. Please try again.