| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class \Test\Shared |
| 4 |
* |
| 5 |
* @package WPDiscourse |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPDiscourse\Test; |
| 9 |
|
| 10 |
use WPDiscourse\Test\Logging; |
| 11 |
use WPDiscourse\Test\RemotePost; |
| 12 |
|
| 13 |
/** |
| 14 |
* Base class for WPDiscourse unit tests |
| 15 |
*/ |
| 16 |
class UnitTest extends \WP_UnitTestCase { |
| 17 |
use Logging; |
| 18 |
use RemotePost; |
| 19 |
|
| 20 |
/** |
| 21 |
* Connection options. |
| 22 |
* |
| 23 |
* @access public |
| 24 |
* @var object |
| 25 |
*/ |
| 26 |
public static $connection_options; |
| 27 |
|
| 28 |
/** |
| 29 |
* Publish options. |
| 30 |
* |
| 31 |
* @access public |
| 32 |
* @var object |
| 33 |
*/ |
| 34 |
public static $publish_options; |
| 35 |
|
| 36 |
/** |
| 37 |
* Log options. |
| 38 |
* |
| 39 |
* @access public |
| 40 |
* @var object |
| 41 |
*/ |
| 42 |
public static $log_options; |
| 43 |
|
| 44 |
/** |
| 45 |
* Plugin options. |
| 46 |
* |
| 47 |
* @access public |
| 48 |
* @var object |
| 49 |
*/ |
| 50 |
public static $plugin_options; |
| 51 |
|
| 52 |
/** |
| 53 |
* WP_Post attributes. |
| 54 |
* |
| 55 |
* @access public |
| 56 |
* @var object |
| 57 |
*/ |
| 58 |
public static $post_atts; |
| 59 |
|
| 60 |
/** |
| 61 |
* Params used in remote posts. |
| 62 |
* |
| 63 |
* @access public |
| 64 |
* @var object |
| 65 |
*/ |
| 66 |
public static $remote_post_params; |
| 67 |
|
| 68 |
/** |
| 69 |
* URL of mock discourse instance. |
| 70 |
* |
| 71 |
* @access public |
| 72 |
* @var string |
| 73 |
*/ |
| 74 |
public static $discourse_url; |
| 75 |
|
| 76 |
/** |
| 77 |
* Setup test class |
| 78 |
*/ |
| 79 |
public static function setUpBeforeClass(): void { |
| 80 |
self::initialize_shared_variables(); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Setup each test. |
| 85 |
*/ |
| 86 |
public function setUp(): void { |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Teardown each test. |
| 91 |
*/ |
| 92 |
public function tearDown(): void { |
| 93 |
$this->clear_logs(); |
| 94 |
remove_all_filters( 'pre_http_request' ); |
| 95 |
\Mockery::close(); |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Initialize shared tests. |
| 100 |
*/ |
| 101 |
public static function initialize_shared_variables() { |
| 102 |
self::$discourse_url = 'http://meta.discourse.org'; |
| 103 |
self::$connection_options = array( |
| 104 |
'url' => self::$discourse_url, |
| 105 |
'api-key' => '1235567', |
| 106 |
'publish-username' => 'angus', |
| 107 |
); |
| 108 |
self::$publish_options = array( |
| 109 |
'allowed_post_types' => array( 'post' ), |
| 110 |
'publish-category-update' => 1, |
| 111 |
); |
| 112 |
self::$log_options = array( |
| 113 |
'logs-enabled' => 1, |
| 114 |
); |
| 115 |
self::$plugin_options = array_merge( self::$connection_options, self::$publish_options, self::$log_options ); |
| 116 |
self::$post_atts = array( |
| 117 |
'post_author' => 0, |
| 118 |
'post_content' => 'This is a new post', |
| 119 |
'post_title' => 'This is the post title', |
| 120 |
'meta_input' => array( |
| 121 |
'wpdc_auto_publish_overridden' => 0, |
| 122 |
'publish_to_discourse' => 1, |
| 123 |
'publish_post_category' => 1, |
| 124 |
), |
| 125 |
'post_status' => 'publish', |
| 126 |
); |
| 127 |
} |
| 128 |
} |
| 129 |
|