Security update for permissions_by_term
[yaffs-website] / vendor / drupal / drupal-driver / doc / _static / snippets / phpunitDrupalDriver.php
1 <?php
2
3 use aik099\PHPUnit\BrowserTestCase;
4
5 use Drupal\Driver\DrupalDriver;
6
7 class GeneralTest extends BrowserTestCase
8 {
9
10     /**
11      * @var \Drupal\Driver\DriverInterface
12      */
13      protected static $driver;
14
15     // Path to a Drupal install. This example assumes the directory is in the same one as the `composer.json` file.
16     protected static $drupalRoot = './drupal';
17
18     // Url to the homepage of the Drupal install.
19     protected static $uri = 'http://d8.devl';
20
21     public static $browsers = array(
22         // Selenium info.
23         array(
24             'host' => 'localhost',
25             'port' => 4444,
26             'browserName' => 'firefox',
27             'baseUrl' => 'http://d8.devl',
28         ),
29     );
30
31      public static function setUpBeforeClass() {
32         self::$driver = new DrupalDriver(static::$drupalRoot, static::$uri);
33         self::$driver->setCoreFromVersion();
34         self::$driver->bootstrap();
35     }
36
37     public function testUsingSession()
38     {
39         // This is Mink's Session.
40         $session = $this->getSession();
41
42         // Go to a page.
43         $session->visit(static::$uri);
44
45         // Validate text presence on a page.
46         $this->assertTrue($session->getPage()->hasContent('Site-Install'));
47     }
48
49     public function testUsingBrowser()
50     {
51         // Prints the name of used browser.
52         echo sprintf(
53             "I'm executed using '%s' browser",
54             $this->getBrowser()->getBrowserName()
55         );
56     }
57
58     public function testNodeCreate() {
59         $drupal = self::$driver;
60         $node = (object) [
61             'title' => $drupal->getRandom()->string(),
62             'type' => 'article',
63         ];
64         $drupal->createNode($node);
65
66         $session = $this->getSession();
67         $session->visit(static::$uri . '/node/' . $node->nid);
68
69         $this->assertTrue($session->getPage()->hasContent($node->title));
70     }
71
72 }