+ $this->post("/import/{$userImport->id}")->assertRedirect('/');
+ $this->post("/import/{$adminImport->id}")->assertRedirect('/');
+
+ $this->permissions->grantUserRolePermissions($user, ['content-import']);
+
+ $this->post("/import/{$userImport->id}")->assertRedirect($userImport->getUrl()); // Getting validation response instead of access issue response
+ $this->post("/import/{$adminImport->id}")->assertStatus(404);
+
+ $this->permissions->grantUserRolePermissions($user, ['settings-manage']);
+
+ $this->post("/import/{$adminImport->id}")->assertRedirect($adminImport->getUrl()); // Getting validation response instead of access issue response
+ }
+
+ public function test_run_revalidates_content()
+ {
+ $import = ZipTestHelper::importFromData([], [
+ 'book' => [
+ 'id' => 'abc',
+ ]
+ ]);
+
+ $resp = $this->asAdmin()->post("/import/{$import->id}");
+ $resp->assertRedirect($import->getUrl());
+
+ $resp = $this->followRedirects($resp);
+ $resp->assertSeeText('The name field is required.');
+ $resp->assertSeeText('The id must be an integer.');
+ }
+
+ public function test_run_checks_permissions_on_import()
+ {
+ $viewer = $this->users->viewer();
+ $this->permissions->grantUserRolePermissions($viewer, ['content-import']);
+ $import = ZipTestHelper::importFromData(['created_by' => $viewer->id], [
+ 'book' => ['name' => 'My import book'],
+ ]);
+
+ $resp = $this->asViewer()->post("/import/{$import->id}");
+ $resp->assertRedirect($import->getUrl());
+
+ $resp = $this->followRedirects($resp);
+ $resp->assertSeeText('You are lacking the required permissions to create books.');
+ }
+
+ public function test_run_requires_parent_for_chapter_and_page_imports()
+ {
+ $book = $this->entities->book();
+ $pageImport = ZipTestHelper::importFromData([], [
+ 'page' => ['name' => 'My page', 'html' => '<p>page test!</p>'],
+ ]);
+ $chapterImport = ZipTestHelper::importFromData([], [
+ 'chapter' => ['name' => 'My chapter'],
+ ]);
+
+ $resp = $this->asAdmin()->post("/import/{$pageImport->id}");
+ $resp->assertRedirect($pageImport->getUrl());
+ $this->followRedirects($resp)->assertSee('The parent field is required.');
+
+ $resp = $this->asAdmin()->post("/import/{$pageImport->id}", ['parent' => "book:{$book->id}"]);
+ $resp->assertRedirectContains($book->getUrl());
+
+ $resp = $this->asAdmin()->post("/import/{$chapterImport->id}");
+ $resp->assertRedirect($chapterImport->getUrl());
+ $this->followRedirects($resp)->assertSee('The parent field is required.');
+
+ $resp = $this->asAdmin()->post("/import/{$chapterImport->id}", ['parent' => "book:{$book->id}"]);
+ $resp->assertRedirectContains($book->getUrl());
+ }
+
+ public function test_run_validates_correct_parent_type()
+ {
+ $chapter = $this->entities->chapter();
+ $import = ZipTestHelper::importFromData([], [
+ 'chapter' => ['name' => 'My chapter'],
+ ]);
+
+ $resp = $this->asAdmin()->post("/import/{$import->id}", ['parent' => "chapter:{$chapter->id}"]);
+ $resp->assertRedirect($import->getUrl());
+
+ $resp = $this->followRedirects($resp);
+ $resp->assertSee('Parent book required for chapter import.');
+ }