| 1 |
<?php |
| 2 |
|
| 3 |
namespace Extendify\Tests\Integration\Agent\Controllers; |
| 4 |
|
| 5 |
use Extendify\Agent\Controllers\WPController; |
| 6 |
use Extendify\Shared\Services\Import\Post; |
| 7 |
use WP_UnitTestCase; |
| 8 |
|
| 9 |
class WPControllerTest extends WP_UnitTestCase |
| 10 |
{ |
| 11 |
public function test_lock_post_prevents_importer_update() |
| 12 |
{ |
| 13 |
$postId = self::factory()->post->create(['post_content' => '<p>original</p>']); |
| 14 |
$post = get_post($postId); |
| 15 |
|
| 16 |
$user = self::factory()->user->create(); |
| 17 |
wp_set_current_user($user); |
| 18 |
|
| 19 |
$request = new \WP_REST_Request(); |
| 20 |
$request->set_param('postId', $postId); |
| 21 |
WPController::lockPost($request); |
| 22 |
|
| 23 |
// Attempt to update as the cron user (no user). |
| 24 |
wp_set_current_user(0); |
| 25 |
$result = Post::update($post, '<p>imported content</p>'); |
| 26 |
|
| 27 |
$this->assertWPError($result); |
| 28 |
$this->assertSame(1005, $result->get_error_code()); |
| 29 |
$this->assertSame('<p>original</p>', get_post($postId)->post_content); |
| 30 |
} |
| 31 |
} |
| 32 |
|