forked from Trismegiste/iinano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetizenControllerTest.php
85 lines (69 loc) · 2.67 KB
/
NetizenControllerTest.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
<?php
namespace Trismegiste\SocialBundle\Tests\Functional\Controller;
/**
* NetizenControllerTest tests the NetizenController
*/
class NetizenControllerTest extends WebTestCasePlus
{
protected $collection;
/** @var \Trismegiste\SocialBundle\Repository\NetizenRepository */
protected $repo;
protected function setUp()
{
parent::setUp();
$this->client->followRedirects();
$this->logIn('kirk');
$this->collection = $this->getService('dokudoki.collection');
$this->repo = $this->getService('social.netizen.repository');
}
/**
* @test
*/
public function initialize()
{
$this->collection->drop();
$this->assertCount(0, $this->collection->find());
$this->addUserFixture('kirk');
$this->addUserFixture('spock');
}
public function testMyProfile()
{
$crawler = $this->getPage('netizen_show', ['author' => 'kirk']);
$this->assertGreaterThan(
0, $crawler->filter('div.profile-body:contains("kirk")')->count()
);
$this->assertCount(1, $crawler->filter('div.content')->selectLink('Edit my profile'), 'The logged user can edit his profile');
}
public function testOtherProfile()
{
$crawler = $this->getPage('netizen_show', ['author' => 'spock']);
$this->assertGreaterThan(
0, $crawler->filter('div.profile-body:contains("spock")')->count()
);
$this->assertCount(0, $crawler->filter('div.content')->selectLink('Edit my profile'), 'A logged user cannot edit others profile');
}
public function testEditMyProfile()
{
$newFullName = 'James Tiberius Kirk';
$crawler = $this->getPage('netizen_profile_edit');
$form = $crawler->selectButton('Save')->form();
$this->client->submit($form, ['profile' => ['fullName' => $newFullName]]);
$user = $this->repo->findByNickname('kirk');
$this->assertEquals($newFullName, $user->getProfile()->fullName);
}
public function testAvatarForm()
{
$crawler = $this->getPage('netizen_avatar_edit');
$this->assertCount(1, $crawler->selectButton('send-crop'));
}
public function testAjaxSendAvatar()
{
$filename = __DIR__ . '/../../../Resources/icon/avatar-xy.jpg';
$send = $this->generateUrl('netizen_avatar_edit');
$this->client->request('POST', $send, [
'content' => 'data:image/jpg;base64,' . base64_encode(file_get_contents($filename))
], [], ['HTTP_X-Requested-With' => 'XMLHttpRequest']);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
}