FOSSology  4.4.0
Open Source License Compliance by Open Source Software
startUpTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © Fossology contributors
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
10 
11 class StartUpTest extends \PHPUnit\Framework\TestCase
12 {
14  private $pageContent;
19  private $testDb;
20  protected function setUp() : void
21  {
22  $this->testDb = new TestPgDb("uistart");
23  $this->testDb->setupSysconfig();
24  $this->setUpRepo();
25  putenv("SYSCONFDIR=" . $this->testDb->getFossSysConf());
26  $this->pageContent = '';
27  $p = popen('php '. dirname(__DIR__).'/ui/index.php 2>&1', 'r');
28  while (!feof($p)) {
29  $line = fgets($p, 1000);
30  $this->pageContent .= $line;
31  }
32  pclose($p);
33  }
34 
35  protected function tearDown() : void
36  {
37  $this->rmRepo();
38  $this->testDb->fullDestruct();
39  $this->testDb = null;
40  }
41 
42  private function setUpRepo()
43  {
44  $sysConf = $this->testDb->getFossSysConf();
45  $this->testInstaller = new TestInstaller($sysConf);
46  $this->testInstaller->init();
47  $this->testInstaller->cpRepo();
48  }
49 
50  private function rmRepo()
51  {
52  $this->testInstaller->rmRepo();
53  $this->testInstaller->clear();
54  }
55 
56  private function assertCriticalStringNotfound($critical) {
57  $criticalPos = strpos($this->pageContent, $critical);
58  $criticalEnd = $criticalPos===false ? $criticalPos : strpos($this->pageContent, "\n", $criticalPos);
59  $this->assertTrue(false===$criticalPos, "There was a $critical at position $criticalPos:\n". substr($this->pageContent, $criticalPos, $criticalEnd-$criticalPos)."\n");
60  }
61 
62  public function testIsHtmlAndNoWarningFound()
63  {
64  assertThat($this->pageContent, startsWith('<!DOCTYPE html>'));
65  $this->assertCriticalStringNotfound('PHP Notice');
66  $this->assertCriticalStringNotfound('PHP Fatal error');
67  $this->assertCriticalStringNotfound('PHP Warning');
68  }
69 
70 }