Skip to content

Commit

Permalink
Minor test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Friedman <maf675@gmail.com>
  • Loading branch information
iMattPro committed Mar 4, 2022
1 parent 4a202b1 commit 63b79bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ public function test_configure_media_embed($tag, $code, $id, $exists, $parse_url
*/
public function exception_errors_data()
{
return array(
array('notok', '\Symfony\Component\Yaml\Exception\ParseException'), // Exception when custom site YAML is invalid
array('invalid', '\InvalidArgumentException'), // Exception when MediaEmbed can't process the site definition
);
return [
['notok', '\Symfony\Component\Yaml\Exception\ParseException'], // Exception when custom site YAML is invalid
['invalid', '\InvalidArgumentException'], // Exception when MediaEmbed can't process the site definition
];
}

/**
Expand Down
34 changes: 17 additions & 17 deletions tests/functional/media_embed_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,42 @@ public function test_posting_media_bbcode()
{
$this->login();

$post = $this->create_topic(2, 'Media Embed Test Topic 1', "[media]https://youtu.be/{$this->youtubeId}[/media]");
$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
self::assertStringContainsString("//www.youtube.com/embed/{$this->youtubeId}", $crawler->filter("#post_content{$post['topic_id']} iframe")->attr('src'));
$post = $this->create_topic(2, 'Media Embed Test Topic 1', "[media]https://youtu.be/$this->youtubeId[/media]");
$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid=$this->sid");
self::assertStringContainsString("//www.youtube.com/embed/$this->youtubeId", $crawler->filter("#post_content{$post['topic_id']} iframe")->attr('src'));
}

public function test_posting_custom_site()
{
$this->login();
$this->admin_login();

$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=manage&sid={$this->sid}");
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=manage&sid=$this->sid");
$this->assert_checkbox_is_unchecked($crawler, 'ok');
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$fields = $form->all();
// Tick all the check boxes dang it, because unticked boxes can't be crawled alone
foreach ($fields as $fieldname => $fieldobject)
{
if (preg_match('/mark\[(\d+)\]/', $fieldname, $matches))
if (preg_match('/mark\[(\d+)]/', $fieldname, $matches))
{
$form['mark'][$matches[1]]->tick();
}
}
self::submit($form);
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=manage&sid={$this->sid}");
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=manage&sid=$this->sid");
$this->assert_checkbox_is_checked($crawler, 'ok');

$post = $this->create_topic(2, 'Media Embed Custom Site Test Topic 1', "[media]https://ok.ru/video/{$this->ok_ru_Id}[/media]");
$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
self::assertStringContainsString("//ok.ru/videoembed/{$this->ok_ru_Id}", $crawler->filter("#post_content{$post['topic_id']} iframe")->attr('src'));
$post = $this->create_topic(2, 'Media Embed Custom Site Test Topic 1', "[media]https://ok.ru/video/$this->ok_ru_Id[/media]");
$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid=$this->sid");
self::assertStringContainsString("//ok.ru/videoembed/$this->ok_ru_Id", $crawler->filter("#post_content{$post['topic_id']} iframe")->attr('src'));
}

public function signatures_data()
{
return [
[false, 'UNAUTHORISED_BBCODE'],
[true, "//www.youtube.com/embed/{$this->youtubeId}"],
[true, "//www.youtube.com/embed/$this->youtubeId"],
];
}

Expand All @@ -87,7 +87,7 @@ public function test_signatures($allowed, $expected)
$crawler = self::request('GET', 'ucp.php?i=ucp_profile&mode=signature');

$form = $crawler->selectButton('Submit')->form([
'signature' => "[media]https://youtu.be/{$this->youtubeId}[/media]",
'signature' => "[media]https://youtu.be/$this->youtubeId[/media]",
]);

$crawler = self::submit($form);
Expand All @@ -112,9 +112,9 @@ public function test_posting_media_bbcode_wo_permission()
$this->admin_login();

// Set f_mediaembed to never
$crawler = self::request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=setting_forum_local&forum_id[0]=2&group_id[0]=2&sid={$this->sid}");
$crawler = self::request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=setting_forum_local&forum_id[0]=2&group_id[0]=2&sid=$this->sid");
$form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
$data = array('setting[2][2][f_mediaembed]' => ACL_NEVER);
$data = ['setting[2][2][f_mediaembed]' => ACL_NEVER];
$form->setValues($data);
self::submit($form);

Expand All @@ -130,7 +130,7 @@ public function test_media_embed_help()
$this->assertContainsLang('HELP_EMBEDDING_MEDIA', $crawler->filter('#faqlinks')->text());

preg_match('/https:\/\/youtu\.be\/(.*)/', $this->lang('HELP_EMBEDDING_MEDIA_DEMO'), $matches);
self::assertStringContainsString("//www.youtube.com/embed/{$matches[1]}", $crawler->filter('body iframe')->attr('src'));
self::assertStringContainsString("//www.youtube.com/embed/$matches[1]", $crawler->filter('body iframe')->attr('src'));
}

public function test_acp_modules()
Expand All @@ -141,7 +141,7 @@ public function test_acp_modules()
$this->admin_login();

// Test settings module width error
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=settings&sid={$this->sid}");
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=settings&sid=$this->sid");
$this->assertContainsLang('ACP_MEDIA_SETTINGS', $crawler->filter('#main')->text(), 'The Media Embed settings module failed to load');
$form_data = [
'media_embed_max_width' => "vimo:100px\nyoutube:100",
Expand All @@ -153,7 +153,7 @@ public function test_acp_modules()
self::assertStringContainsString($this->lang('ACP_MEDIA_INVALID_SITE', 'vimo', '100px') . '<br>' . $this->lang('ACP_MEDIA_INVALID_WIDTH', 'youtube', '100'), $crawler->filter('.errorbox')->html());

// Test settings module width success
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=settings&sid={$this->sid}");
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=settings&sid=$this->sid");
$this->assertContainsLang('ACP_MEDIA_SETTINGS', $crawler->filter('#main')->text(), 'The Media Embed settings module failed to load');
$form_data = [
'media_embed_max_width' => "vimeo:100px\nyoutube:100%",
Expand All @@ -164,7 +164,7 @@ public function test_acp_modules()
self::assertGreaterThan(0, $crawler->filter('.successbox')->count());

// Test manage sites module
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=manage&sid={$this->sid}");
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\mediaembed\\acp\\main_module&mode=manage&sid=$this->sid");
$this->assertContainsLang('ACP_MEDIA_MANAGE', $crawler->filter('#main')->text(), 'The Media Embed settings module failed to load');

$this->assert_checkbox_is_checked($crawler, 'youtube');
Expand Down

0 comments on commit 63b79bb

Please sign in to comment.