. */ namespace SP\Tests\Modules\Api\Controllers; use SP\Core\Acl\AclActionsInterface; use SP\Tests\Modules\Api\ApiTestCase; use stdClass; /** * Class ConfigControllerTest * * @package SP\Tests\Modules\Api\Controllers */ class ConfigControllerTest extends ApiTestCase { /** * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \JsonException */ public function testExportAction(): void { $api = $this->callApi( AclActionsInterface::CONFIG_EXPORT_RUN, [] ); $response = self::processJsonResponse($api); $this->assertEquals(0, $response->result->resultCode); $this->assertEquals(1, $response->result->count); $this->assertEquals('Export process finished', $response->result->resultMessage); $this->assertEquals(0, $response->result->resultCode); $this->assertNotEmpty($response->result->result->files->xml); $this->assertFileExists($response->result->result->files->xml); } /** * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \JsonException */ public function testExportActionCustomPath(): void { $api = $this->callApi( AclActionsInterface::CONFIG_EXPORT_RUN, [ 'path' => TMP_PATH . '/export/custom/path' ] ); $response = self::processJsonResponse($api); $this->assertEquals(0, $response->result->resultCode); $this->assertEquals(1, $response->result->count); $this->assertEquals('Export process finished', $response->result->resultMessage); $this->assertEquals(0, $response->result->resultCode); $this->assertNotEmpty($response->result->result->files->xml); $this->assertFileExists($response->result->result->files->xml); } /** * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \JsonException */ public function testExportActionInvalidPath(): void { $api = $this->callApi( AclActionsInterface::CONFIG_EXPORT_RUN, [ 'path' => '/export/custom/path' ] ); $response = self::processJsonResponse($api); $this->assertInstanceOf(stdClass::class, $response->error); $this->assertStringContainsString('Unable to create the directory', $response->error->message); } /** * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \JsonException */ public function testBackupAction(): void { $api = $this->callApi( AclActionsInterface::CONFIG_BACKUP_RUN, [] ); $response = self::processJsonResponse($api); $this->assertEquals(0, $response->result->resultCode); $this->assertEquals(1, $response->result->count); $this->assertEquals('Backup process finished', $response->result->resultMessage); $this->assertEquals(0, $response->result->resultCode); $this->assertNotEmpty($response->result->result->files->app); $this->assertNotEmpty($response->result->result->files->db); $this->assertFileExists($response->result->result->files->app); $this->assertFileExists($response->result->result->files->db); } /** * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \JsonException */ public function testBackupActionInvalidPath(): void { $api = $this->callApi( AclActionsInterface::CONFIG_BACKUP_RUN, [ 'path' => '/backup/custom/path' ] ); $response = self::processJsonResponse($api); $this->assertInstanceOf(stdClass::class, $response->error); $this->assertStringContainsString('Unable to create the backups directory', $response->error->message); } /** * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \JsonException */ public function testBackupActionCustomPath(): void { $api = $this->callApi( AclActionsInterface::CONFIG_BACKUP_RUN, [ 'path' => TMP_PATH . '/backup/custom/path' ] ); $response = self::processJsonResponse($api); $this->assertEquals(0, $response->result->resultCode); $this->assertEquals(1, $response->result->count); $this->assertEquals('Backup process finished', $response->result->resultMessage); $this->assertEquals(0, $response->result->resultCode); $this->assertNotEmpty($response->result->result->files->app); $this->assertNotEmpty($response->result->result->files->db); $this->assertFileExists($response->result->result->files->app); $this->assertFileExists($response->result->result->files->db); } }