2019-08-26 22:03:30 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Tests\Wallabag\Controller;
|
2019-08-26 22:03:30 +00:00
|
|
|
|
2024-02-24 19:24:51 +00:00
|
|
|
use Tests\Wallabag\WallabagTestCase;
|
2019-08-26 22:03:30 +00:00
|
|
|
|
2024-02-24 19:24:51 +00:00
|
|
|
class IgnoreOriginInstanceRuleControllerTest extends WallabagTestCase
|
2019-08-26 22:03:30 +00:00
|
|
|
{
|
|
|
|
public function testListIgnoreOriginInstanceRule()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
2022-11-23 16:09:32 +00:00
|
|
|
$client = $this->getTestClient();
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
$crawler = $client->request('GET', '/ignore-origin-instance-rules/');
|
|
|
|
|
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$body = $crawler->filter('body')->extract(['_text'])[0];
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('ignore_origin_instance_rule.description', $body);
|
|
|
|
$this->assertStringContainsString('ignore_origin_instance_rule.list.create_new_one', $body);
|
2019-08-26 22:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIgnoreOriginInstanceRuleCreationEditionDeletion()
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
2022-11-23 16:09:32 +00:00
|
|
|
$client = $this->getTestClient();
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
// Creation
|
|
|
|
$crawler = $client->request('GET', '/ignore-origin-instance-rules/new');
|
|
|
|
|
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$body = $crawler->filter('body')->extract(['_text'])[0];
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('ignore_origin_instance_rule.new_ignore_origin_instance_rule', $body);
|
|
|
|
$this->assertStringContainsString('ignore_origin_instance_rule.form.back_to_list', $body);
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
$form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ignore_origin_instance_rule[rule]' => 'host = "foo.example.com"',
|
|
|
|
];
|
|
|
|
|
|
|
|
$client->submit($form, $data);
|
|
|
|
|
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$crawler = $client->followRedirect();
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('flashes.ignore_origin_instance_rule.notice.added', $crawler->filter('body')->extract(['_text'])[0]);
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
// Edition
|
|
|
|
$editLink = $crawler->filter('div[id=content] table a')->last()->link();
|
|
|
|
|
|
|
|
$crawler = $client->click($editLink);
|
|
|
|
|
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('foo.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]);
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
$body = $crawler->filter('body')->extract(['_text'])[0];
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('ignore_origin_instance_rule.edit_ignore_origin_instance_rule', $body);
|
|
|
|
$this->assertStringContainsString('ignore_origin_instance_rule.form.back_to_list', $body);
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
$form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ignore_origin_instance_rule[rule]' => 'host = "bar.example.com"',
|
|
|
|
];
|
|
|
|
|
|
|
|
$client->submit($form, $data);
|
|
|
|
|
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$crawler = $client->followRedirect();
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('flashes.ignore_origin_instance_rule.notice.updated', $crawler->filter('body')->extract(['_text'])[0]);
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
$editLink = $crawler->filter('div[id=content] table a')->last()->link();
|
|
|
|
|
|
|
|
$crawler = $client->click($editLink);
|
|
|
|
|
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('bar.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]);
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
$deleteForm = $crawler->filter('body')->selectButton('ignore_origin_instance_rule.form.delete')->form();
|
|
|
|
|
|
|
|
$client->submit($deleteForm, []);
|
|
|
|
|
|
|
|
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$crawler = $client->followRedirect();
|
|
|
|
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('flashes.ignore_origin_instance_rule.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]);
|
2019-08-26 22:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function dataForIgnoreOriginInstanceRuleCreationFail()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'ignore_origin_instance_rule[rule]' => 'foo = "bar"',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'The variable',
|
|
|
|
'does not exist.',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'ignore_origin_instance_rule[rule]' => '_all != "none"',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'The operator',
|
|
|
|
'does not exist.',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataForIgnoreOriginInstanceRuleCreationFail
|
|
|
|
*/
|
|
|
|
public function testIgnoreOriginInstanceRuleCreationFail($data, $messages)
|
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
2022-11-23 16:09:32 +00:00
|
|
|
$client = $this->getTestClient();
|
2019-08-26 22:03:30 +00:00
|
|
|
|
|
|
|
$crawler = $client->request('GET', '/ignore-origin-instance-rules/new');
|
|
|
|
|
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
|
|
|
|
|
|
|
|
$crawler = $client->submit($form, $data);
|
|
|
|
|
|
|
|
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
|
|
|
|
|
|
|
|
foreach ($messages as $message) {
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString($message, $body[0]);
|
2019-08-26 22:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|