Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/test/Readline/LibeditTest.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of Psy Shell. | |
5 * | |
6 * (c) 2012-2018 Justin Hileman | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Psy\Test\Readline; | |
13 | |
14 use Psy\Readline\Libedit; | |
15 | |
16 class LibeditTest extends \PHPUnit\Framework\TestCase | |
17 { | |
18 private $historyFile; | |
19 | |
20 public function setUp() | |
21 { | |
22 if (!Libedit::isSupported()) { | |
23 $this->markTestSkipped('Libedit not enabled'); | |
24 } | |
25 | |
26 $this->historyFile = tempnam(sys_get_temp_dir(), 'psysh_test_history'); | |
27 if (false === file_put_contents($this->historyFile, "_HiStOrY_V2_\n")) { | |
28 $this->fail('Unable to write history file: ' . $this->historyFile); | |
29 } | |
30 // Calling readline_read_history before readline_clear_history | |
31 // avoids segfault with PHP 5.5.7 & libedit v3.1 | |
32 readline_read_history($this->historyFile); | |
33 readline_clear_history(); | |
34 } | |
35 | |
36 public function tearDown() | |
37 { | |
38 if (is_file($this->historyFile)) { | |
39 unlink($this->historyFile); | |
40 } | |
41 } | |
42 | |
43 public function testHistory() | |
44 { | |
45 $readline = new Libedit($this->historyFile); | |
46 $this->assertEmpty($readline->listHistory()); | |
47 $readline->addHistory('foo'); | |
48 $this->assertSame(['foo'], $readline->listHistory()); | |
49 $readline->addHistory('bar'); | |
50 $this->assertSame(['foo', 'bar'], $readline->listHistory()); | |
51 $readline->addHistory('baz'); | |
52 $this->assertSame(['foo', 'bar', 'baz'], $readline->listHistory()); | |
53 $readline->clearHistory(); | |
54 $this->assertEmpty($readline->listHistory()); | |
55 } | |
56 | |
57 /** | |
58 * @depends testHistory | |
59 */ | |
60 public function testHistorySize() | |
61 { | |
62 $readline = new Libedit($this->historyFile, 2); | |
63 $this->assertEmpty($readline->listHistory()); | |
64 $readline->addHistory('foo'); | |
65 $readline->addHistory('bar'); | |
66 $this->assertSame(['foo', 'bar'], $readline->listHistory()); | |
67 $readline->addHistory('baz'); | |
68 $this->assertSame(['bar', 'baz'], $readline->listHistory()); | |
69 $readline->addHistory('w00t'); | |
70 $this->assertSame(['baz', 'w00t'], $readline->listHistory()); | |
71 $readline->clearHistory(); | |
72 $this->assertEmpty($readline->listHistory()); | |
73 } | |
74 | |
75 /** | |
76 * @depends testHistory | |
77 */ | |
78 public function testHistoryEraseDups() | |
79 { | |
80 $readline = new Libedit($this->historyFile, 0, true); | |
81 $this->assertEmpty($readline->listHistory()); | |
82 $readline->addHistory('foo'); | |
83 $readline->addHistory('bar'); | |
84 $readline->addHistory('foo'); | |
85 $this->assertSame(['bar', 'foo'], $readline->listHistory()); | |
86 $readline->addHistory('baz'); | |
87 $readline->addHistory('w00t'); | |
88 $readline->addHistory('baz'); | |
89 $this->assertSame(['bar', 'foo', 'w00t', 'baz'], $readline->listHistory()); | |
90 $readline->clearHistory(); | |
91 $this->assertEmpty($readline->listHistory()); | |
92 } | |
93 | |
94 public function testListHistory() | |
95 { | |
96 $readline = new Libedit($this->historyFile); | |
97 file_put_contents( | |
98 $this->historyFile, | |
99 "This is an entry\n\0This is a comment\nThis is an entry\0With a comment\n", | |
100 FILE_APPEND | |
101 ); | |
102 $this->assertSame([ | |
103 'This is an entry', | |
104 'This is an entry', | |
105 ], $readline->listHistory()); | |
106 $readline->clearHistory(); | |
107 } | |
108 | |
109 /** | |
110 * Libedit being a BSD library, | |
111 * it doesn't support non-unix line separators. | |
112 */ | |
113 public function testLinebreaksSupport() | |
114 { | |
115 $readline = new Libedit($this->historyFile); | |
116 file_put_contents( | |
117 $this->historyFile, | |
118 "foo\rbar\nbaz\r\nw00t", | |
119 FILE_APPEND | |
120 ); | |
121 $this->assertSame([ | |
122 "foo\rbar", | |
123 "baz\r", | |
124 'w00t', | |
125 ], $readline->listHistory()); | |
126 $readline->clearHistory(); | |
127 } | |
128 } |