Skip to content

Commit c604e81

Browse files
committed
Add a functional test for cron reparser
1 parent ae62ad2 commit c604e81

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
*
4+
* Pages extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace functional;
12+
13+
use phpbb\pages\tests\functional\pages_functional_base;
14+
15+
/**
16+
* @group functional
17+
*/
18+
class cron_reparser_test extends pages_functional_base
19+
{
20+
/**
21+
* Test the cron reparser functionality
22+
*/
23+
public function test_cron_reparser()
24+
{
25+
$this->login();
26+
$this->admin_login();
27+
28+
// Store some of our data in variables
29+
$page_title = 'Cron Reparser Test Page';
30+
$page_content = '[b]This is a functional test page for the cron task reparser.[/b]';
31+
32+
// Create a test page
33+
$route = $this->create_page($page_title, $page_content);
34+
35+
// Go to the test page
36+
$crawler = self::request('GET', "app.php/$route?sid=$this->sid");
37+
$this->assertStringContainsString($page_title, $crawler->filter('h2')->text());
38+
39+
// Assert no reparsers have run yet
40+
$this->assertEmpty($this->get_reparser_resume());
41+
42+
// Run the cron task to reparse pages
43+
self::request('GET', "app.php/cron/cron.task.text_reparser.phpbb_pages", [], false);
44+
45+
// Try to ensure that the cron can actually run before we start to wait for it
46+
sleep(1);
47+
$cron_lock = new \phpbb\lock\db(
48+
'cron_lock',
49+
new \phpbb\config\db(
50+
$this->db,
51+
new \phpbb\cache\driver\dummy(),
52+
'phpbb_config'
53+
),
54+
$this->db
55+
);
56+
57+
// Add timeout to prevent infinite loop
58+
$timeout = time() + 30; // 30-second timeout
59+
while (!$cron_lock->acquire())
60+
{
61+
if (time() > $timeout)
62+
{
63+
$this->fail('Cron lock could not be acquired within 30 seconds');
64+
}
65+
usleep(100000); // Sleep for 100 ms between attempts
66+
}
67+
$cron_lock->release();
68+
69+
// Assert there's now a record of reparsing pages in the database
70+
$this->assertEquals(
71+
['phpbb.pages.text_reparser.page_text'],
72+
array_keys(unserialize($this->get_reparser_resume(), ['allowed_classes' => false]))
73+
);
74+
}
75+
76+
/**
77+
* Get the reparser resume data from the database
78+
*
79+
* @return string|null The config value or null if not found
80+
*/
81+
private function get_reparser_resume()
82+
{
83+
$sql = "SELECT config_value
84+
FROM " . CONFIG_TEXT_TABLE . "
85+
WHERE config_name = 'reparser_resume'";
86+
$result = $this->db->sql_query($sql);
87+
$row = $this->db->sql_fetchrow($result);
88+
$this->db->sql_freeresult($result);
89+
90+
return $row['config_value'] ?? null;
91+
}
92+
}

0 commit comments

Comments
 (0)