1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-16 21:08:34 +01:00

Add ajax test (#640)

This commit is contained in:
Barry vd. Heuvel 2024-03-31 19:09:53 +02:00 committed by GitHub
parent 2bfe379a66
commit 0bf3a5f466
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 74 additions and 14 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ composer.lock
/demo/bridge/*/vendor
/src/DebugBar/Resources/vendor
.phpunit.result.cache
/drivers
/drivers
.phpunit.cache/

View File

@ -115,4 +115,4 @@ To run the demo, clone this repository and start the Built-In PHP webserver from
php -S localhost:8000
```
Then visit http://localhost:8000/demo
Then visit http://localhost:8000/demo/

View File

@ -639,6 +639,8 @@ if (typeof(PhpDebugBar) == 'undefined') {
self.showTab(name);
}
});
tab.$tab.attr('data-collector', name);
tab.$el.attr('data-collector', name);
tab.$el.appendTo(this.$body);
this.controls[name] = tab;

View File

@ -0,0 +1,28 @@
<?php
namespace DebugBar\Tests;
use DebugBar\DebugBar;
use DebugBar\DebugBarException;
use DebugBar\Tests\DataCollector\MockCollector;
use DebugBar\Tests\Storage\MockStorage;
use DebugBar\RandomRequestIdGenerator;
use Facebook\WebDriver\WebDriverElement;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\Panther\DomCrawler\Link;
use Symfony\Component\Panther\PantherTestCase;
abstract class AbstractBrowserTest extends PantherTestCase
{
public function isTabActive(Crawler $crawler, $tab)
{
$node = $crawler->filter('a.phpdebugbar-tab[data-collector="'.$tab.'"]');
return strpos($node->attr('class'), 'phpdebugbar-active"') !== false;
}
public function getTabLink(Crawler $crawler, $tab): Link
{
return $crawler->filter('a.phpdebugbar-tab[data-collector="'.$tab.'"]')->link();
}
}

View File

@ -10,23 +10,21 @@ use DebugBar\RandomRequestIdGenerator;
use Facebook\WebDriver\WebDriverElement;
use Symfony\Component\Panther\PantherTestCase;
class BasicBrowserTest extends PantherTestCase
class BasicBrowserTest extends AbstractBrowserTest
{
public function testDebugbar(): void
public function testDebugbarTab(): void
{
// Start demo
$client = static::createPantherClient();
$client->request('GET', '/demo');
$crawler = $client->request('GET', '/demo/');
// Wait for Debugbar to load
$crawler = $client->waitFor('.phpdebugbar-body');
$firstTab = $crawler->filter('a.phpdebugbar-tab')->link();
$client->click($firstTab);
$client->click($this->getTabLink($crawler, 'messages'));
$crawler = $client->waitForVisibility('.phpdebugbar-widgets-messages .phpdebugbar-widgets-list');
$crawler = $client->waitForVisibility('.phpdebugbar-panel[data-collector=messages] .phpdebugbar-widgets-list');
$messages = $crawler->filter('.phpdebugbar-widgets-messages .phpdebugbar-widgets-value')
$messages = $crawler->filter('.phpdebugbar-panel[data-collector=messages] .phpdebugbar-widgets-value')
->each(function(WebDriverElement $node){
return $node->getText();
});
@ -34,9 +32,40 @@ class BasicBrowserTest extends PantherTestCase
$this->assertEquals('hello', $messages[0]);
$this->assertCount(4, $messages);
$firstTab = $crawler->filter('a.phpdebugbar-tab')->link();
$client->click($firstTab);
$client->waitForInvisibility('.phpdebugbar-widgets-messages .phpdebugbar-widgets-list');
// Close it again
$client->click($this->getTabLink($crawler, 'messages'));
$client->waitForInvisibility('.phpdebugbar-panel[data-collector=messages] .phpdebugbar-widgets-list');
}
public function testDebugbarAjax(): void
{
$client = static::createPantherClient();
$crawler = $client->request('GET', '/demo/');
// Wait for Debugbar to load
$crawler = $client->waitFor('.phpdebugbar-body');
$client->click($this->getTabLink($crawler, 'messages'));
$crawler = $client->waitForVisibility('.phpdebugbar-widgets-messages .phpdebugbar-widgets-list');
$crawler->selectLink('load ajax content')->click();
$client->waitForElementToContain('.phpdebugbar-panel[data-collector=messages]', 'hello from ajax');
$client->waitForElementToContain('.phpdebugbar-datasets-switcher', 'ajax.php');
$messages = $crawler->filter('.phpdebugbar-panel[data-collector=messages] .phpdebugbar-widgets-value')
->each(function(WebDriverElement $node){
return $node->getText();
});
$this->assertEquals('hello from ajax', $messages[0]);
$crawler->selectLink('load ajax content with exception')->click();
$client->click($this->getTabLink($crawler, 'exceptions'));
$client->waitForElementToContain('.phpdebugbar-datasets-switcher', 'ajax_exception.php');
$client->waitForElementToContain('.phpdebugbar-panel[data-collector=exceptions] .phpdebugbar-widgets-message', 'Something failed!');
}
}