Skip to content

Commit b11d81b

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2 parents 1e2114c + 3f587cc commit b11d81b

5 files changed

Lines changed: 100 additions & 36 deletions

File tree

test/classes/ConsoleTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpMyAdmin\ConfigStorage\Relation;
88
use PhpMyAdmin\Console;
99
use PhpMyAdmin\Template;
10+
use ReflectionProperty;
1011

1112
/** @covers \PhpMyAdmin\Console */
1213
class ConsoleTest extends AbstractTestCase
@@ -17,4 +18,16 @@ public function testGetScripts(): void
1718
$console = new Console(new Relation($GLOBALS['dbi']), new Template());
1819
$this->assertEquals(['console.js'], $console->getScripts());
1920
}
21+
22+
public function testSetAjax(): void
23+
{
24+
$isAjax = new ReflectionProperty(Console::class, 'isAjax');
25+
$console = new Console(new Relation($this->createDatabaseInterface()), new Template());
26+
27+
$this->assertFalse($isAjax->getValue($console));
28+
$console->setAjax(true);
29+
$this->assertTrue($isAjax->getValue($console));
30+
$console->setAjax(false);
31+
$this->assertFalse($isAjax->getValue($console));
32+
}
2033
}

test/classes/FooterTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpMyAdmin\ErrorHandler;
99
use PhpMyAdmin\Footer;
1010
use PhpMyAdmin\Template;
11+
use ReflectionProperty;
1112

1213
use function json_encode;
1314

@@ -111,10 +112,7 @@ public function testDisable(): void
111112
);
112113
}
113114

114-
/**
115-
* Test for footer when ajax enabled
116-
*/
117-
public function testAjax(): void
115+
public function testGetDisplayWhenAjaxIsEnabled(): void
118116
{
119117
$footer = new Footer();
120118
$footer->setAjax(true);
@@ -169,4 +167,16 @@ public function testMinimal(): void
169167
$footer->getDisplay(),
170168
);
171169
}
170+
171+
public function testSetAjax(): void
172+
{
173+
$isAjax = new ReflectionProperty(Footer::class, 'isAjax');
174+
$footer = new Footer();
175+
176+
$this->assertFalse($isAjax->getValue($footer));
177+
$footer->setAjax(true);
178+
$this->assertTrue($isAjax->getValue($footer));
179+
$footer->setAjax(false);
180+
$this->assertFalse($isAjax->getValue($footer));
181+
}
172182
}

test/classes/HeaderTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpMyAdmin\Tests;
66

7+
use PhpMyAdmin\Console;
78
use PhpMyAdmin\Header;
89
use ReflectionProperty;
910

@@ -265,4 +266,22 @@ public function testAddedDefaultScripts(): void
265266
];
266267
$this->assertSame($expected, $scripts->getFiles());
267268
}
269+
270+
public function testSetAjax(): void
271+
{
272+
$header = new Header();
273+
$console = (new ReflectionProperty(Header::class, 'console'))->getValue($header);
274+
$this->assertInstanceOf(Console::class, $console);
275+
$isAjax = new ReflectionProperty(Header::class, 'isAjax');
276+
$consoleIsAjax = new ReflectionProperty(Console::class, 'isAjax');
277+
278+
$this->assertFalse($isAjax->getValue($header));
279+
$this->assertFalse($consoleIsAjax->getValue($console));
280+
$header->setAjax(true);
281+
$this->assertTrue($isAjax->getValue($header));
282+
$this->assertTrue($consoleIsAjax->getValue($console));
283+
$header->setAjax(false);
284+
$this->assertFalse($isAjax->getValue($header));
285+
$this->assertFalse($consoleIsAjax->getValue($console));
286+
}
268287
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests;
6+
7+
use PhpMyAdmin\Footer;
8+
use PhpMyAdmin\Header;
9+
use PhpMyAdmin\ResponseRenderer;
10+
use PHPUnit\Framework\Attributes\PreserveGlobalState;
11+
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
12+
use ReflectionProperty;
13+
14+
/** @covers \PhpMyAdmin\ResponseRenderer */
15+
class ResponseRendererTest extends AbstractTestCase
16+
{
17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
$GLOBALS['dbi'] = $this->createDatabaseInterface();
22+
23+
$GLOBALS['lang'] = 'en';
24+
$GLOBALS['server'] = 1;
25+
$GLOBALS['text_dir'] = 'ltr';
26+
}
27+
28+
#[RunInSeparateProcess]
29+
#[PreserveGlobalState(false)]
30+
public function testSetAjax(): void
31+
{
32+
$_REQUEST = [];
33+
$response = ResponseRenderer::getInstance();
34+
$header = $response->getHeader();
35+
$footer = (new ReflectionProperty(ResponseRenderer::class, 'footer'))->getValue($response);
36+
$this->assertInstanceOf(Footer::class, $footer);
37+
$headerIsAjax = new ReflectionProperty(Header::class, 'isAjax');
38+
$footerIsAjax = new ReflectionProperty(Footer::class, 'isAjax');
39+
40+
$this->assertFalse($response->isAjax());
41+
$this->assertFalse($headerIsAjax->getValue($header));
42+
$this->assertFalse($footerIsAjax->getValue($footer));
43+
44+
$response->setAjax(true);
45+
$this->assertTrue($response->isAjax());
46+
$this->assertTrue($headerIsAjax->getValue($header));
47+
$this->assertTrue($footerIsAjax->getValue($footer));
48+
49+
$response->setAjax(false);
50+
$this->assertFalse($response->isAjax());
51+
$this->assertFalse($headerIsAjax->getValue($header));
52+
$this->assertFalse($footerIsAjax->getValue($footer));
53+
}
54+
}

test/classes/ResponseTest.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)