2016-02-07 15:52:59 +00:00
|
|
|
<?php
|
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
namespace Wallabag\AnnotationBundle\Tests\Controller;
|
2016-02-07 15:52:59 +00:00
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
use Wallabag\AnnotationBundle\Tests\WallabagAnnotationTestCase;
|
2016-02-07 15:52:59 +00:00
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
class AnnotationControllerTest extends WallabagAnnotationTestCase
|
2016-02-07 15:52:59 +00:00
|
|
|
{
|
2016-02-26 12:59:08 +00:00
|
|
|
public function testGetAnnotations()
|
2016-02-07 15:52:59 +00:00
|
|
|
{
|
2016-02-26 12:59:08 +00:00
|
|
|
$annotation = $this->client->getContainer()
|
2016-02-07 15:52:59 +00:00
|
|
|
->get('doctrine.orm.entity_manager')
|
2016-02-26 12:59:08 +00:00
|
|
|
->getRepository('WallabagAnnotationBundle:Annotation')
|
2016-03-11 16:56:41 +00:00
|
|
|
->findOneByUsername('admin');
|
2016-02-07 15:52:59 +00:00
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
if (!$annotation) {
|
2016-02-07 15:52:59 +00:00
|
|
|
$this->markTestSkipped('No content found in db.');
|
|
|
|
}
|
2016-03-11 16:56:41 +00:00
|
|
|
|
2016-02-07 15:52:59 +00:00
|
|
|
$this->logInAs('admin');
|
2016-02-26 12:59:08 +00:00
|
|
|
$crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json');
|
2016-02-07 15:52:59 +00:00
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
|
|
|
$this->assertEquals(1, $content['total']);
|
2016-02-26 12:59:08 +00:00
|
|
|
$this->assertEquals($annotation->getText(), $content['rows'][0]['text']);
|
2016-02-07 15:52:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
public function testSetAnnotation()
|
2016-02-07 15:52:59 +00:00
|
|
|
{
|
|
|
|
$this->logInAs('admin');
|
|
|
|
|
|
|
|
$entry = $this->client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagCoreBundle:Entry')
|
2016-03-11 16:56:41 +00:00
|
|
|
->findOneByUsernameAndNotArchived('admin');
|
2016-02-07 15:52:59 +00:00
|
|
|
|
2016-04-12 09:36:01 +00:00
|
|
|
$headers = ['CONTENT_TYPE' => 'application/json'];
|
|
|
|
$content = json_encode([
|
2016-02-26 12:59:08 +00:00
|
|
|
'text' => 'my annotation',
|
2016-02-07 15:52:59 +00:00
|
|
|
'quote' => 'my quote',
|
2016-04-12 09:36:01 +00:00
|
|
|
'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31],
|
|
|
|
]);
|
|
|
|
$crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', [], [], $headers, $content);
|
2016-02-07 15:52:59 +00:00
|
|
|
|
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
|
|
|
|
2016-03-11 16:56:41 +00:00
|
|
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
|
|
|
|
|
|
|
$this->assertEquals('Big boss', $content['user']);
|
|
|
|
$this->assertEquals('v1.0', $content['annotator_schema_version']);
|
|
|
|
$this->assertEquals('my annotation', $content['text']);
|
|
|
|
$this->assertEquals('my quote', $content['quote']);
|
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
$annotation = $this->client->getContainer()
|
2016-02-07 15:52:59 +00:00
|
|
|
->get('doctrine.orm.entity_manager')
|
2016-02-26 12:59:08 +00:00
|
|
|
->getRepository('WallabagAnnotationBundle:Annotation')
|
|
|
|
->findLastAnnotationByPageId($entry->getId(), 1);
|
2016-02-07 15:52:59 +00:00
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
$this->assertEquals('my annotation', $annotation->getText());
|
2016-02-07 15:52:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
public function testEditAnnotation()
|
2016-02-07 15:52:59 +00:00
|
|
|
{
|
2016-02-26 12:59:08 +00:00
|
|
|
$annotation = $this->client->getContainer()
|
2016-02-07 15:52:59 +00:00
|
|
|
->get('doctrine.orm.entity_manager')
|
2016-02-26 12:59:08 +00:00
|
|
|
->getRepository('WallabagAnnotationBundle:Annotation')
|
2016-03-11 16:56:41 +00:00
|
|
|
->findOneByUsername('admin');
|
2016-02-07 15:52:59 +00:00
|
|
|
|
|
|
|
$this->logInAs('admin');
|
|
|
|
|
2016-04-12 09:36:01 +00:00
|
|
|
$headers = ['CONTENT_TYPE' => 'application/json'];
|
|
|
|
$content = json_encode([
|
2016-02-26 12:59:08 +00:00
|
|
|
'text' => 'a modified annotation',
|
2016-04-12 09:36:01 +00:00
|
|
|
]);
|
|
|
|
$crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content);
|
2016-02-07 15:52:59 +00:00
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
|
|
|
|
2016-03-11 16:56:41 +00:00
|
|
|
$this->assertEquals('Big boss', $content['user']);
|
|
|
|
$this->assertEquals('v1.0', $content['annotator_schema_version']);
|
2016-02-26 12:59:08 +00:00
|
|
|
$this->assertEquals('a modified annotation', $content['text']);
|
2016-03-12 09:45:14 +00:00
|
|
|
$this->assertEquals('my quote', $content['quote']);
|
2016-02-07 15:52:59 +00:00
|
|
|
|
2016-02-26 12:59:08 +00:00
|
|
|
$annotationUpdated = $this->client->getContainer()
|
2016-02-07 15:52:59 +00:00
|
|
|
->get('doctrine.orm.entity_manager')
|
2016-02-26 12:59:08 +00:00
|
|
|
->getRepository('WallabagAnnotationBundle:Annotation')
|
2016-03-11 16:56:41 +00:00
|
|
|
->findOneById($annotation->getId());
|
2016-02-26 12:59:08 +00:00
|
|
|
$this->assertEquals('a modified annotation', $annotationUpdated->getText());
|
2016-02-07 15:52:59 +00:00
|
|
|
}
|
2016-03-11 16:56:41 +00:00
|
|
|
|
|
|
|
public function testDeleteAnnotation()
|
|
|
|
{
|
|
|
|
$annotation = $this->client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagAnnotationBundle:Annotation')
|
|
|
|
->findOneByUsername('admin');
|
|
|
|
|
|
|
|
$this->logInAs('admin');
|
|
|
|
|
2016-04-12 09:36:01 +00:00
|
|
|
$headers = ['CONTENT_TYPE' => 'application/json'];
|
|
|
|
$content = json_encode([
|
2016-03-11 16:56:41 +00:00
|
|
|
'text' => 'a modified annotation',
|
2016-04-12 09:36:01 +00:00
|
|
|
]);
|
|
|
|
$crawler = $this->client->request('DELETE', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content);
|
2016-03-11 16:56:41 +00:00
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
|
|
|
|
|
|
|
$this->assertEquals('a modified annotation', $content['text']);
|
|
|
|
|
|
|
|
$annotationDeleted = $this->client->getContainer()
|
|
|
|
->get('doctrine.orm.entity_manager')
|
|
|
|
->getRepository('WallabagAnnotationBundle:Annotation')
|
|
|
|
->findOneById($annotation->getId());
|
|
|
|
|
|
|
|
$this->assertNull($annotationDeleted);
|
|
|
|
}
|
2016-02-07 15:52:59 +00:00
|
|
|
}
|