| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class SyncDiscourseTopicMultisiteTest |
| 4 |
* |
| 5 |
* @package WPDiscourse |
| 6 |
*/ |
| 7 |
|
| 8 |
use WPDiscourse\Test\Multisite; |
| 9 |
use WPDiscourse\Test\SyncDiscourseTopicTest; |
| 10 |
use WPDiscourse\DiscoursePublish\DiscoursePublish; |
| 11 |
|
| 12 |
/** |
| 13 |
* SyncDiscourseTopicMultisiteTest test case. |
| 14 |
*/ |
| 15 |
class SyncDiscourseTopicMultisiteTest extends SyncDiscourseTopicTest { |
| 16 |
use Multisite; |
| 17 |
|
| 18 |
/** |
| 19 |
* update_topic_content handles webhook results correctly in multisite. |
| 20 |
*/ |
| 21 |
public function test_update_topic_content() { |
| 22 |
// Set as multisite. |
| 23 |
self::$plugin_options['multisite-configuration-enabled'] = 1; |
| 24 |
$this->sync_topic->setup_options( self::$plugin_options ); |
| 25 |
|
| 26 |
// Setup the posts |
| 27 |
$post_id = wp_insert_post( self::$post_atts, false, false ); |
| 28 |
$discourse_post = json_decode( $this->payload )->post; |
| 29 |
|
| 30 |
// Setup the post meta |
| 31 |
$discourse_topic_id = $discourse_post->topic_id; |
| 32 |
update_post_meta( $post_id, 'discourse_topic_id', $discourse_topic_id ); |
| 33 |
|
| 34 |
// Setup multisite data |
| 35 |
$blog_id = intval( get_current_blog_id() ); |
| 36 |
$this->sync_topic->save_topic_blog_id( $discourse_topic_id, $blog_id ); |
| 37 |
|
| 38 |
// Perform update |
| 39 |
$this->sync_topic->update_topic_content( $this->request ); |
| 40 |
|
| 41 |
// Ensure the post meta is updated correctly on the right site. |
| 42 |
$this->switch_to_blog_for_topic( $discourse_topic_id ); |
| 43 |
$this->assertEquals( get_post_meta( $post_id, 'wpdc_sync_post_comments', true ), 1 ); |
| 44 |
$this->assertEquals( get_post_meta( $post_id, 'discourse_comments_count', true ), '2' ); |
| 45 |
|
| 46 |
// Cleanup |
| 47 |
wp_delete_post( $post_id ); |
| 48 |
restore_current_blog(); |
| 49 |
} |
| 50 |
} |
| 51 |
|