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:
parent
2bfe379a66
commit
0bf3a5f466
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@ composer.lock
|
||||
/demo/bridge/*/vendor
|
||||
/src/DebugBar/Resources/vendor
|
||||
.phpunit.result.cache
|
||||
/drivers
|
||||
/drivers
|
||||
.phpunit.cache/
|
@ -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/
|
@ -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;
|
||||
|
28
tests/DebugBar/Browser/AbstractBrowserTest.php
Normal file
28
tests/DebugBar/Browser/AbstractBrowserTest.php
Normal 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();
|
||||
}
|
||||
}
|
@ -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!');
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user