Skip to content
Snippets Groups Projects
Commit 74e8c5eb authored by JohnCullen's avatar JohnCullen
Browse files

#3384913 setting up route testing suite

parent b000ed39
No related branches found
No related tags found
No related merge requests found
<?php
namespace Drupal\Tests\support_ticket\Functional;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
/**
* Minimal test case for the examples module.
*
* @group examples
*
* @ingroup examples
*/
class ExamplesTest extends ExamplesBrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Modules to install.
*
* @var array
*/
protected static $modules = ['examples', 'toolbar'];
/**
* Verify that the toolbar tab and tray are showing and functioning.
*/
public function testExampleToolbar() {
$assert = $this->assertSession();
// Log in a user who can see the toolbar and all the routes in it.
$this->drupalLogin($this->drupalCreateUser(['access content', 'access toolbar']));
// All this should be on the front page.
$this->drupalGet('');
$assert->statusCodeEquals(200);
// Assert that the toolbar tab registered by examples is present.
$assert->linkExists('Examples');
// Assert that the toolbar tab registered by examples is present.
$this->assertNotEmpty($this->xpath('//nav/div/a[@data-toolbar-tray="toolbar-item-examples-tray"]'));
// Assert that the toolbar tray registered by examples is present.
$this->assertNotEmpty($this->xpath('//nav/div/div[@data-toolbar-tray="toolbar-item-examples-tray"]'));
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
$module_installer = $this->container->get('module_installer');
// Loop through all the routes. Check that they are not present in the
// toolbar, enable the module, and then check that they are present in the
// toolbar.
foreach (_examples_toolbar_routes() as $module => $route) {
// Convert the module name to the HTML class.
$class = Html::getClass($module);
$xpath = "//li/a[@class=\"$class\"]";
// Assert that the toolbar link item isn't present.
$this->assertEmpty($this->xpath($xpath), 'Found li with this class: ' . $class);
// Install the module.
$module_installer->install([$module], TRUE);
$this->resetAll();
// Load the route.
$this->drupalGet(Url::fromRoute($route));
// Assert that the toolbar link is present.
$this->assertNotEmpty($this->xpath($xpath), 'Unable to find toolbar link for module: ' . $module);
// Handle some special cases where modules depend on each other so they
// might have already put the toolbar link in the toolbar.
if ($module == 'file_example') {
$module_installer->uninstall(['file_example', 'stream_wrapper_example']);
}
}
}
}
<?php
namespace Drupal\support_ticket\Tests;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the basic support integration functionality.
*
* @group support
*
* @codeCoverageIgnore
*/
class SupportTicketRoutesTests extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'diff',
'comment',
'node',
'options',
'user',
'views',
'support',
'support_ticket',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Testing to see if login works.
*/
public function testCorePageFunctionality() {
$admin_user = $this->drupalCreateUser([
'access content overview',
]);
$this->drupalLogin($admin_user);
$this->drupalGet('/admin/content');
$this->assertSession()->statusCodeEquals(200);
}
/**
* Tests front page work.
*/
public function testSupportTicketAddPageFunctionality() {
$admin_user = $this->drupalCreateUser(['support_ticket']);
$this->drupalLogin($admin_user);
$this->drupalGet('/support_ticket/add');
$this->assertSession()->statusCodeEquals(200);
}
}
......@@ -27,7 +27,8 @@ echo "";
##
# Run support module tests.
##
../../vendor/bin/phpunit ../modules/custom/support/tests/src/Functional/SupportInstallationTests.php
#../../vendor/bin/phpunit ../modules/custom/support/tests/src/Functional/SupportInstallationTests.php
../../vendor/bin/phpunit ../modules/custom/support/modules/support_ticket/tests/src/Functional/SupportTicketRoutesTests.php
##
......
......@@ -16,8 +16,6 @@ class SupportInstallationTests extends BrowserTestBase {
/**
* Modules to enable.
*
* Note: node is only needed for testing 'access content'.
*
* @var array
*/
protected static $modules = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment