Skip to content

Commit 552eea9

Browse files
committed
! UnGzip tests
1 parent df8aecd commit 552eea9

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

tests/sources/ServerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ public function testSupportsSSL()
9292
$server->HTTP_X_FORWARDED_PROTO = 'http';
9393
$this->assertFalse($server->supportsSSL());
9494
}
95-
}
95+
}

tests/sources/UnTgzTest.php

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
use ElkArte\UnTgz;
4+
use PHPUnit\Framework\TestCase;
5+
6+
class UnTgzTest extends TestCase
7+
{
8+
/** @var string this is a hex value for a simple tar.gz file */
9+
public $data = "1f8b0800000000000003edd14d0ac2301086e1597b8a5c40cddf98f354e842902ecc081e5f53bab108052188f03e8b0c4c02f9e0b3b1da51faf22fa5943643c9cbd430ef1712b26a8e4953f2e2438af1244e3be79addab0d37e76498eae57c1df7d3503fbedbbaff53d6fa6fc7c11ed6e98fedfe75d57f2e398bf39df2bca17fdbfd3a0400000000000000000000000080af3c0178c8bb2c00280000";
10+
11+
/**
12+
* Tests _read_header_tgz method in the UnTgz class.
13+
*
14+
* For now a NULL test is provided as the function does not return a value
15+
*/
16+
public function testReadHeaderTgz()
17+
{
18+
$unTgz = new UnTgz(hex2bin($this->data), '', false, false, NULL);
19+
20+
$this->assertTrue($unTgz->check_valid_tgz());
21+
22+
$method = new \ReflectionMethod(UnTgz::class, '_read_header_tgz');
23+
$method->setAccessible(true);
24+
25+
$this->assertNull($method->invoke($unTgz));
26+
}
27+
28+
/**
29+
* Test the check_valid_tgz method
30+
*
31+
* This method tests the check_valid_tgz method of the UnTgz class.
32+
*
33+
* @return void
34+
*/
35+
public function testCheckValidTgz()
36+
{
37+
$destination = './'; // Target destination
38+
$single_file = true; // single file
39+
$overwrite = true; // overwrite existing files
40+
41+
// Act
42+
$unTgz = new UnTgz(hex2bin($this->data), $destination, $single_file, $overwrite);
43+
$result = $unTgz->check_valid_tgz();
44+
45+
// Assert
46+
$this->assertTrue($result, 'String data is a valid .tgz file');
47+
}
48+
49+
/**
50+
* Test for '_ungzip_data' method
51+
*
52+
* This method is responsible for ungziping the data from a .tgz file
53+
*/
54+
public function testUngzipData(): void
55+
{
56+
$unTgz = new UnTgz(hex2bin($this->data), 'destination', false, false, null);
57+
58+
// Create a reflection of '_ungzip_data' method
59+
$reflection = new \ReflectionClass($unTgz);
60+
$method = $reflection->getMethod('_read_header_tgz');
61+
$method->setAccessible(true);
62+
$method2 = $reflection->getMethod('_ungzip_data');
63+
$method2->setAccessible(true);
64+
65+
$unTgz->check_valid_tgz();
66+
$method->invoke($unTgz);
67+
68+
// Call '_ungzip_data' method and test the expected behavior
69+
$this->assertNotFalse($method2->invoke($unTgz));
70+
}
71+
72+
/**
73+
* Test for 'read_tgz_data' method
74+
*
75+
* This method is responsible for reading the data from a .tgz file
76+
*/
77+
public function testReadTgzData()
78+
{
79+
$unTgz = new UnTgz(hex2bin($this->data), '/packages', false, false, NULL);
80+
81+
$unTgz->check_valid_tgz();
82+
83+
$result = $unTgz->read_tgz_data();
84+
var_dump($result);
85+
86+
$this->assertNotEmpty($result, 'The md5 is valid');
87+
88+
//$this->assertEquals('d8e8fca2dc0f896fd7cb4cb0031ba249', $result['md5'], 'The md5 is valid');
89+
}
90+
}

0 commit comments

Comments
 (0)