Skip to content

Commit 6c47918

Browse files
committed
Update tests
1 parent e6bdc6e commit 6c47918

File tree

4 files changed

+52
-86
lines changed

4 files changed

+52
-86
lines changed

includes/helper.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,9 @@ public function generate_post_url($post_id = 0)
15511551
*/
15521552
private function comment_exists($comment_list = [], $identifier = '')
15531553
{
1554-
if (empty($comment_list))
1554+
$identifier = trim($identifier);
1555+
1556+
if (empty($comment_list) || empty($identifier))
15551557
{
15561558
return false;
15571559
}

tests/functional/acp_seometadata_test.php

+5-20
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ protected function init()
2424

2525
public function test_acp_form_settings()
2626
{
27-
$crawler = self::request('GET', sprintf(
28-
'adm/index.php?i=-alfredoramos-seometadata-acp-main_module&mode=settings&sid=%s',
29-
$this->sid
30-
));
27+
$crawler = self::request('GET', 'adm/index.php?i=-alfredoramos-seometadata-acp-main_module&mode=settings&sid=' . $this->sid);
3128

3229
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
3330

@@ -95,10 +92,7 @@ public function test_acp_form_settings()
9592

9693
public function test_update_acp_form_settings()
9794
{
98-
$crawler = self::request('GET', sprintf(
99-
'adm/index.php?i=-alfredoramos-seometadata-acp-main_module&mode=settings&sid=%s',
100-
$this->sid
101-
));
95+
$crawler = self::request('GET', 'adm/index.php?i=-alfredoramos-seometadata-acp-main_module&mode=settings&sid=' . $this->sid);
10296

10397
$form = $crawler->selectButton($this->lang('SUBMIT'))->form([
10498
'seo_metadata_default_image' => 'default_image.jpg',
@@ -108,10 +102,7 @@ public function test_update_acp_form_settings()
108102
self::submit($form);
109103

110104
// Check the new values in the ACP form
111-
$crawler = self::request('GET', sprintf(
112-
'adm/index.php?i=-alfredoramos-seometadata-acp-main_module&mode=settings&sid=%s',
113-
$this->sid
114-
));
105+
$crawler = self::request('GET', 'adm/index.php?i=-alfredoramos-seometadata-acp-main_module&mode=settings&sid=' . $this->sid);
115106

116107
// Extract image width, height and MIME type
117108
$this->assertSame(250, (int) $crawler->filter('#seo_metadata_default_image_width')->text());
@@ -159,10 +150,7 @@ public function test_update_acp_form_settings()
159150
$this->assertSame(150, (int) $elements['json_ld']['publisher']['logo']['height']);
160151

161152
// Check the new values in topics (remote image)
162-
$this->update_config_value(
163-
'seo_metadata_local_images',
164-
'0'
165-
);
153+
$this->update_config(['seo_metadata_local_images' => '0']);
166154

167155
$data = [
168156
'title' => 'SEO Metadata functional test 3',
@@ -216,10 +204,7 @@ public function test_update_acp_form_settings()
216204
$this->assertSame(150, (int) $elements['json_ld']['publisher']['logo']['width']);
217205
$this->assertSame(150, (int) $elements['json_ld']['publisher']['logo']['height']);
218206

219-
$this->update_config_value(
220-
'seo_metadata_local_images',
221-
'1'
222-
);
207+
$this->update_config(['seo_metadata_local_images' => '1']);
223208
}
224209

225210
public function test_forum_image()

tests/functional/functional_test_case_trait.php

+29-19
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,52 @@ protected function setUp(): void
2222
{
2323
parent::setUp();
2424

25-
// Set default image
26-
$this->update_config_value(
27-
'seo_metadata_default_image',
28-
'default_image.jpg'
29-
);
30-
31-
// Set JSON-LD logo
32-
$this->update_config_value(
33-
'seo_metadata_json_ld_logo',
34-
'default_logo.jpg'
35-
);
25+
$this->update_config([
26+
'seo_metadata_default_image' => 'default_image.jpg',
27+
'seo_metadata_json_ld_logo' => 'default_logo.jpg'
28+
]);
3629

3730
$this->init();
3831
}
3932

40-
private function update_config_value($name = '', $value = '')
33+
private function update_config(array $data = [])
4134
{
42-
$name = trim($name);
43-
$value = trim($value);
44-
45-
if (empty($name))
35+
if (empty($data))
4636
{
4737
return;
4838
}
4939

5040
$db = $this->get_db();
51-
$sql = 'UPDATE ' . CONFIG_TABLE . '
41+
$db->sql_transaction('begin');
42+
43+
foreach ($data as $key => $value)
44+
{
45+
if (!is_string($key) || !is_string($value))
46+
{
47+
continue;
48+
}
49+
50+
$key = trim($key);
51+
$value = trim($value);
52+
53+
if (empty($key))
54+
{
55+
continue;
56+
}
57+
58+
$sql = 'UPDATE ' . CONFIG_TABLE . '
5259
SET ' . $db->sql_build_array('UPDATE',
5360
[
5461
'config_value' => $value,
5562
'is_dynamic' => 1 // Fix cache
5663
]
5764
) . '
5865
WHERE ' . $db->sql_build_array('UPDATE',
59-
['config_name' => $name]
66+
['config_name' => $key]
6067
);
61-
$db->sql_query($sql);
68+
$db->sql_query($sql);
69+
}
70+
71+
$db->sql_transaction('commit');
6272
}
6373
}

tests/functional/seometadata_test.php

+15-46
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ public function test_open_graph()
124124

125125
public function test_twitter_cards()
126126
{
127-
$this->update_config_value(
128-
'seo_metadata_twitter_publisher',
129-
'@varsmx'
130-
);
127+
$this->update_config(['seo_metadata_twitter_publisher' => '@varsmx']);
131128

132129
$crawler = self::request('GET', sprintf(
133130
'viewtopic.php?t=1&sid=%s',
@@ -386,11 +383,7 @@ public function test_extracted_image_fallback()
386383
public function test_extracted_image_remote()
387384
{
388385
$this->login();
389-
390-
$this->update_config_value(
391-
'seo_metadata_local_images',
392-
'0'
393-
);
386+
$this->update_config(['seo_metadata_local_images' => '0']);
394387

395388
$data = [
396389
'title' => 'SEO Metadata functional test 3',
@@ -442,20 +435,13 @@ public function test_extracted_image_remote()
442435
$elements['json_ld']['image']
443436
);
444437

445-
$this->update_config_value(
446-
'seo_metadata_local_images',
447-
'1'
448-
);
438+
$this->update_config(['seo_metadata_local_images' => '1']);
449439
}
450440

451441
public function test_extracted_image_parameters()
452442
{
453443
$this->login();
454-
455-
$this->update_config_value(
456-
'seo_metadata_local_images',
457-
'0'
458-
);
444+
$this->update_config(['seo_metadata_local_images' => '0']);
459445

460446
$data = [
461447
'title' => 'SEO Metadata functional test 4',
@@ -507,10 +493,7 @@ public function test_extracted_image_parameters()
507493
$elements['json_ld']['image']
508494
);
509495

510-
$this->update_config_value(
511-
'seo_metadata_local_images',
512-
'1'
513-
);
496+
$this->update_config(['seo_metadata_local_images' => '1']);
514497
}
515498

516499
public function test_forum_description()
@@ -536,14 +519,10 @@ public function test_forum_description()
536519
public function test_post_reply_metadata()
537520
{
538521
$this->login();
539-
$this->update_config_value(
540-
'seo_metadata_post_metadata',
541-
'1'
542-
);
543-
$this->update_config_value(
544-
'seo_metadata_local_images',
545-
'0'
546-
);
522+
$this->update_config([
523+
'seo_metadata_post_metadata' => '1',
524+
'seo_metadata_local_images' => '0'
525+
]);
547526

548527
$data = [
549528
'title' => 'SEO Metadata functional test 5',
@@ -613,23 +592,16 @@ public function test_post_reply_metadata()
613592
$elements['json_ld']['image']
614593
);
615594

616-
$this->update_config_value(
617-
'seo_metadata_post_metadata',
618-
'0'
619-
);
620-
$this->update_config_value(
621-
'seo_metadata_local_images',
622-
'1'
623-
);
595+
$this->update_config([
596+
'seo_metadata_post_metadata' => '0',
597+
'seo_metadata_local_images' => '1'
598+
]);
624599
}
625600

626601
public function test_summary_large_image()
627602
{
628603
$this->login();
629-
$this->update_config_value(
630-
'seo_metadata_open_graph',
631-
'0'
632-
);
604+
$this->update_config(['seo_metadata_open_graph' => '0']);
633605

634606
$data = [
635607
'title' => 'SEO Metadata functional test 5',
@@ -677,10 +649,7 @@ public function test_summary_large_image()
677649
$this->assertSame(1, $elements['image']->count());
678650
$this->assertSame('http://localhost/images/wide_image.jpg', $elements['image']->attr('content'));
679651

680-
$this->update_config_value(
681-
'seo_metadata_open_graph',
682-
'1'
683-
);
652+
$this->update_config(['seo_metadata_open_graph' => '1']);
684653
}
685654

686655
public function test_short_description()

0 commit comments

Comments
 (0)