1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
From ea2a862f0a0b3bc8cedb9adf160f18892d152984 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Wed, 3 May 2017 13:29:53 +0200
Subject: [PATCH] don't rely on directory entries order
---
framework/Compress/test/Horde/Compress/TarTest.php | 24 ++++++++++++++--------
framework/Compress/test/Horde/Compress/ZipTest.php | 24 ++++++++++++++--------
2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/framework/Compress/test/Horde/Compress/TarTest.php b/framework/Compress/test/Horde/Compress/TarTest.php
index 1875f8b..82ba8a1 100644
--- a/framework/Compress/test/Horde/Compress/TarTest.php
+++ b/framework/Compress/test/Horde/Compress/TarTest.php
@@ -112,14 +112,20 @@ public function testTarDirectory()
$list = $compress->decompress($tar_data);
$this->assertCount(3, $list);
- $this->assertEquals('one.txt', $list[0]['name']);
- $this->assertEquals(4, $list[0]['size']);
- $this->assertEquals("One\n", $list[0]['data']);
- $this->assertEquals('sub/three.txt', $list[1]['name']);
- $this->assertEquals(6, $list[1]['size']);
- $this->assertEquals("Three\n", $list[1]['data']);
- $this->assertEquals('two.bin', $list[2]['name']);
- $this->assertEquals(2, $list[2]['size']);
- $this->assertEquals("\x02\x0a", $list[2]['data']);
+ for ($i=0 ; $i<3 ; $i++) {
+ $list[$list[$i]['name']] = $list[$i];
+ unset($list[$i]);
+ }
+ $this->assertArrayHasKey($k='one.txt', $list);
+ $this->assertEquals(4, $list[$k]['size']);
+ $this->assertEquals("One\n", $list[$k]['data']);
+
+ $this->assertArrayHasKey($k='sub/three.txt', $list);
+ $this->assertEquals(6, $list[$k]['size']);
+ $this->assertEquals("Three\n", $list[$k]['data']);
+
+ $this->assertArrayHasKey($k='two.bin', $list);
+ $this->assertEquals(2, $list[$k]['size']);
+ $this->assertEquals("\x02\x0a", $list[$k]['data']);
}
}
diff --git a/framework/Compress/test/Horde/Compress/ZipTest.php b/framework/Compress/test/Horde/Compress/ZipTest.php
index 7e215b2..25729b6 100644
--- a/framework/Compress/test/Horde/Compress/ZipTest.php
+++ b/framework/Compress/test/Horde/Compress/ZipTest.php
@@ -143,39 +143,45 @@ public function testZipDirectory()
$zip_data, array('action' => Horde_Compress_Zip::ZIP_LIST)
);
$this->assertCount(3, $list);
- $this->assertEquals('one.txt', $list[0]['name']);
- $this->assertEquals(4, $list[0]['size']);
- $this->assertEquals('sub/three.txt', $list[1]['name']);
- $this->assertEquals(6, $list[1]['size']);
- $this->assertEquals('two.bin', $list[2]['name']);
- $this->assertEquals(2, $list[2]['size']);
+ for ($i=0 ; $i<3 ; $i++) {
+ $index[$list[$i]['name']] = $i;
+ }
+ $this->assertArrayHasKey($k='one.txt', $index);
+ $this->assertEquals($k, $list[$index[$k]]['name']);
+ $this->assertEquals(4, $list[$index[$k]]['size']);
$data = $compress->decompress(
$zip_data,
array(
'action' => Horde_Compress_Zip::ZIP_DATA,
'info' => $list,
- 'key' => 0
+ 'key' => $index[$k]
)
);
$this->assertEquals("One\n", $data);
+ $this->assertArrayHasKey($k='sub/three.txt', $index);
+ $this->assertEquals($k, $list[$index[$k]]['name']);
+ $this->assertEquals(6, $list[$index[$k]]['size']);
$data = $compress->decompress(
$zip_data,
array(
'action' => Horde_Compress_Zip::ZIP_DATA,
'info' => $list,
- 'key' => 1
+ 'key' => $index[$k]
)
);
$this->assertEquals("Three\n", $data);
+ $this->assertArrayHasKey($k='two.bin', $index);
+ $this->assertEquals('two.bin', $list[$index[$k]]['name']);
+ $this->assertEquals(2, $list[$index[$k]]['size']);
$data = $compress->decompress(
$zip_data,
array(
'action' => Horde_Compress_Zip::ZIP_DATA,
'info' => $list,
- 'key' => 2
+ 'key' => $index[$k]
)
);
$this->assertEquals("\x02\x0a", $data);
|