/
ControllerTest.php
executable file
·94 lines (79 loc) · 3.1 KB
/
ControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Pushword\AdminBlockEditor\Tests;
use App\Entity\Page;
use Pushword\Admin\Tests\AbstractAdminTest;
class ControllerTest extends AbstractAdminTest
{
public function testBasics()
{
$client = $this->loginUser(
// static::createPantherClient([ 'webServerDir' => __DIR__.'/../../skeleton/public' ])
);
$id = $this->createNewPage();
$client->request('GET', '/admin/app/page/'.$id.'/edit');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
// does'nt throw error = good start, can do better ?
$client->request('GET', '/admin-block-editor.test/test');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
// does'nt throw error = every filters are working (well ?)
// if bug encouter, test them via BlockEditorFilterTest
}
private function createNewPage()
{
$em = self::$kernel->getContainer()->get('doctrine.orm.default_entity_manager');
$page = (new Page())
->setH1('Test editorJsPage')
->setSlug('test')
->setHost('admin-block-editor.test')
->setLocale('en')
->setMainContent(file_get_contents(__DIR__.'/content/content.json'));
$em->persist($page);
$em->flush();
return $page->getId();
}
public function testPageController()
{
$client = $this->loginUser(
// static::createPantherClient([ 'webServerDir' => __DIR__.'/../../skeleton/public' ])
);
$client->request(
'POST',
'/admin/page/block/',
[],
[],
[],
json_encode(['kw' => 'fun', 'display' => 'list', 'order' => 'priority ↓,publishedAt ↓', 'max' => '', 'maxPages' => ''])
);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
// dd(str_replace([' ', '\n'], '', $client->getResponse()->getContent()));
$this->assertStringStartsWith(
'{"success":1,"content":"<ul><li><ahref=\"',
str_replace([' ', '\n'], '', $client->getResponse()->getContent())
);
$client->request(
'POST',
'/admin/page/block/1',
[],
[],
[],
json_encode(['kw' => 'fun', 'display' => 'list', 'order' => 'priority ↓,publishedAt ↓', 'max' => '', 'maxPages' => ''])
);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
public function testMediaController()
{
$client = $this->loginUser(
// static::createPantherClient([ 'webServerDir' => __DIR__.'/../../skeleton/public' ])
);
$client->request(
'POST',
'/admin/media/block',
[],
[],
[],
json_encode(['url' => 'https://github.com/fluidicon.png'])
);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertSame('image/png', json_decode($client->getResponse()->getContent())->file->mimeType);
}
}