8fa81ac2904b17dca484bf5026f5ed427a947c5a
[yaffs-website] / web / core / modules / system / tests / src / Functional / System / SystemAuthorizeTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\System;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the authorize.php script and related API.
9  *
10  * @group system
11  */
12 class SystemAuthorizeTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['system_test'];
20
21   protected function setUp() {
22     parent::setUp();
23
24     // Create an administrator user.
25     $this->drupalLogin ($this->drupalCreateUser(['administer software updates']));
26   }
27
28   /**
29    * Helper function to initialize authorize.php and load it via drupalGet().
30    *
31    * Initializing authorize.php needs to happen in the child Drupal
32    * installation, not the parent. So, we visit a menu callback provided by
33    * system_test.module which calls system_authorized_init() to initialize the
34    * $_SESSION inside the test site, not the framework site. This callback
35    * redirects to authorize.php when it's done initializing.
36    *
37    * @see system_authorized_init()
38    */
39   public function drupalGetAuthorizePHP($page_title = 'system-test-auth') {
40     $this->drupalGet('system-test/authorize-init/' . $page_title);
41   }
42
43   /**
44    * Tests the FileTransfer hooks
45    */
46   public function testFileTransferHooks() {
47     $page_title = $this->randomMachineName(16);
48     $this->drupalGetAuthorizePHP($page_title);
49     $this->assertTitle(strtr('@title | Drupal', ['@title' => $page_title]), 'authorize.php page title is correct.');
50     $this->assertNoText('It appears you have reached this page in error.');
51     $this->assertText('To continue, provide your server connection details');
52     // Make sure we see the new connection method added by system_test.
53     $this->assertRaw('System Test FileTransfer');
54     // Make sure the settings form callback works.
55     $this->assertText('System Test Username');
56     // Test that \Drupal\Core\Render\BareHtmlPageRenderer adds assets as
57     // expected to the first page of the authorize.php script.
58     $this->assertRaw('core/misc/states.js');
59   }
60
61 }