Skip to content

Commit 57b6bcd

Browse files
committed
Add a PHPUnit test
1 parent 90d7fbc commit 57b6bcd

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

src/Bridge/Sylius/templates/admin/media/show/content/header/title_block/actions/move_directory.html.twig

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/Bridge/Sylius/Admin/Controller/MediaAdminControllerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,29 @@ public function testCreateDirectoryFailsWhenEmptyName(): void
515515
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'Directory name is required');
516516
}
517517

518+
public function testMoveDirectoryFromSubdirectoryToRoot(): void
519+
{
520+
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore/sub/folder');
521+
$this->assertResponseIsSuccessful();
522+
523+
$form = $this->getMoveDirectoryForm($crawler);
524+
525+
$phpValues = $form->getPhpValues();
526+
$phpValues['to'] = '';
527+
528+
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
529+
530+
$this->assertResponseRedirects('/sylius-admin/media/explore/folder');
531+
532+
// I should be redirected to the new directory path
533+
$this->client->followRedirect();
534+
$this->assertResponseIsSuccessful();
535+
536+
// Test flash message
537+
$this->assertSelectorExists('[data-test-sylius-flash-message]');
538+
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'The directory "sub/folder" was successfully moved to "folder".');
539+
}
540+
518541
protected static function getKernelClass(): string
519542
{
520543
return Kernel::class;
@@ -561,6 +584,13 @@ private function getCreateDirectoryForm(Crawler $crawler): Form
561584
return $crawler->filter('form[data-component="directory-create-form"]')->form();
562585
}
563586

587+
private function getMoveDirectoryForm(Crawler $crawler): Form
588+
{
589+
$this->assertSelectorExists('form[id="move-form"]');
590+
591+
return $crawler->filter('form[id="move-form"]')->form();
592+
}
593+
564594
private function createTemporaryFile(): string
565595
{
566596
return tempnam(sys_get_temp_dir(), 'upload-test');

0 commit comments

Comments
 (0)