|
17 | 17 | use emteknetnz\RestApi\Tests\Controllers\RestApiTest\TestCanMethodStatic; |
18 | 18 | use emteknetnz\RestApi\Exceptions\RestApiEndpointConfigException; |
19 | 19 | use SilverStripe\Security\SecurityToken; |
20 | | -use SilverStripe\Versioned\Versioned; |
| 20 | +use emteknetnz\RestApi\Tests\Controllers\RestApiTest\TestVersionedExtension; |
| 21 | + |
21 | 22 |
|
22 | 23 | # vendor/bin/phpunit app/tests/Controllers/RestApiTest.php flush=1 |
23 | 24 |
|
@@ -83,6 +84,7 @@ protected function setUp(): void |
83 | 84 | SecurityToken::enable(); |
84 | 85 | TestCanMethodStatic::setCanMethodsThatPass(self::VIEW_CREATE_EDIT_DELETE_ACTION); |
85 | 86 | TestApiEndpoint::resetHooksCalled(); |
| 87 | + TestVersionedExtension::enableAutoPublish(); |
86 | 88 | $this->setConfig(self::PATH, $this->endpointPath); |
87 | 89 | // Create fixtures |
88 | 90 | $testTeam = TestTeam::create([ |
@@ -2302,6 +2304,30 @@ public function testExtensionHooks(): void |
2302 | 2304 | $this->assertTrue(TestApiEndpoint::$hooksCalled['updateApiConfig']); |
2303 | 2305 | } |
2304 | 2306 |
|
| 2307 | + public function testVersionedActions(): void |
| 2308 | + { |
| 2309 | + // Set ACCESS to LOGGED_IN to set versioned mode to DRAFT in rest-api |
| 2310 | + $this->setConfig(self::ACCESS, self::LOGGED_IN); |
| 2311 | + $this->login(self::AUTH_LEVEL_LOGGED_IN); |
| 2312 | + TestVersionedExtension::disableAutoPublish(); |
| 2313 | + $task = TestTask::get()->first(); |
| 2314 | + $taskID = $task->ID; |
| 2315 | + // create a draft change |
| 2316 | + $this->req('PATCH', $taskID, null, null, ['title' => 'Updated'])->getStatusCode(); |
| 2317 | + // assert versioning actions |
| 2318 | + $task = TestTask::get()->byID($taskID); |
| 2319 | + $this->assertTrue($task->stagesDiffer()); |
| 2320 | + $this->req('PUT', $taskID, 'publish'); |
| 2321 | + $task = TestTask::get()->byID($taskID); |
| 2322 | + $this->assertFalse($task->stagesDiffer()); |
| 2323 | + $this->req('PUT', $taskID, 'unpublish'); |
| 2324 | + $task = TestTask::get()->byID($taskID); |
| 2325 | + $this->assertTrue($task->stagesDiffer()); |
| 2326 | + $this->req('PUT', $taskID, 'archive'); |
| 2327 | + $task = TestTask::get()->byID($taskID); |
| 2328 | + $this->assertNull($task); |
| 2329 | + } |
| 2330 | + |
2305 | 2331 | private function login(int $authLevel) |
2306 | 2332 | { |
2307 | 2333 | if ($authLevel === self::AUTH_LEVEL_NONE) { |
|
0 commit comments