From af31e54dd5e647de2461d66bd5ce8488575b03f0 Mon Sep 17 00:00:00 2001 From: Warxcell Date: Thu, 28 Jul 2022 21:45:07 +0300 Subject: [PATCH] add test case covering long-running process. --- phpunit.xml.dist | 1 + tests/App/EventListener/ConfigureMenu.php | 34 +++++++++++++++++++ tests/Functional/Controller/MenuTest.php | 40 +++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/App/EventListener/ConfigureMenu.php create mode 100644 tests/Functional/Controller/MenuTest.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5787b7178e..10b7297411 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -33,5 +33,6 @@ It's auto-generated by sonata-project/dev-kit package. + diff --git a/tests/App/EventListener/ConfigureMenu.php b/tests/App/EventListener/ConfigureMenu.php new file mode 100644 index 0000000000..864d88fa3e --- /dev/null +++ b/tests/App/EventListener/ConfigureMenu.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\App\EventListener; + +use Sonata\AdminBundle\Event\ConfigureMenuEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +final class ConfigureMenu implements EventSubscriberInterface +{ + private int $counter = 0; + + public static function getSubscribedEvents(): array + { + return [ + ConfigureMenuEvent::SIDEBAR => 'configureMenu', + ]; + } + + public function configureMenu(ConfigureMenuEvent $configureMenuEvent): void + { + $configureMenuEvent->getMenu()->addChild(sprintf('Dynamic Menu %s', ++$this->counter))->setAttribute('class', 'dynamic-menu'); + } +} diff --git a/tests/Functional/Controller/MenuTest.php b/tests/Functional/Controller/MenuTest.php new file mode 100644 index 0000000000..f648ff8763 --- /dev/null +++ b/tests/Functional/Controller/MenuTest.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\Functional\Controller; + +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +final class MenuTest extends WebTestCase +{ + public function testDynamicMenuInLongRunningProcess(): void + { + $client = static::createClient(); + $client->disableReboot(); + + for ($i = 1; $i < 5; ++$i) { + $client->request(Request::METHOD_GET, '/admin/dashboard'); + + static::assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode()); + + $crawler = $client->getCrawler(); + + $menu = $crawler->filter('.sidebar-menu .dynamic-menu a'); + + static::assertCount(1, $menu); + static::assertSame(sprintf('Dynamic Menu %s', $i), $menu->innerText()); + } + } +}