mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-15 21:41:06 +00:00
Merge pull request #4161 from aaa2000/bug-empty-quote
API return an error with empty quote
This commit is contained in:
commit
d816ef0530
3 changed files with 61 additions and 3 deletions
|
@ -17,7 +17,8 @@ class NewAnnotationType extends AbstractType
|
|||
'empty_data' => '',
|
||||
])
|
||||
->add('quote', null, [
|
||||
'empty_data' => null,
|
||||
'empty_data' => '',
|
||||
'trim' => false,
|
||||
])
|
||||
->add('ranges', CollectionType::class, [
|
||||
'entry_type' => RangeType::class,
|
||||
|
|
|
@ -37,8 +37,8 @@ class AnnotationRestController extends WallabagRestController
|
|||
* @ApiDoc(
|
||||
* requirements={
|
||||
* {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"},
|
||||
* {"name"="quote", "dataType"="string", "required"=false, "description"="Optional, quote for the annotation"},
|
||||
* {"name"="text", "dataType"="string", "required"=true, "description"=""},
|
||||
* {"name"="quote", "dataType"="string", "description"="The annotated text"},
|
||||
* {"name"="text", "dataType"="string", "required"=true, "description"="Content of annotation"},
|
||||
* }
|
||||
* )
|
||||
*
|
||||
|
|
|
@ -107,6 +107,63 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
|||
$this->assertSame('my annotation', $annotation->getText());
|
||||
}
|
||||
|
||||
public function testAllowEmptyQuote()
|
||||
{
|
||||
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
/** @var Entry $entry */
|
||||
$entry = $em
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
|
||||
$headers = ['CONTENT_TYPE' => 'application/json'];
|
||||
$content = json_encode([
|
||||
'text' => 'my annotation',
|
||||
'quote' => null,
|
||||
'ranges' => [
|
||||
['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31],
|
||||
],
|
||||
]);
|
||||
$this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content);
|
||||
|
||||
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
||||
|
||||
$content = json_decode($this->client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertSame('Big boss', $content['user']);
|
||||
$this->assertSame('v1.0', $content['annotator_schema_version']);
|
||||
$this->assertSame('my annotation', $content['text']);
|
||||
$this->assertSame('', $content['quote']);
|
||||
}
|
||||
|
||||
public function testAllowOmmittedQuote()
|
||||
{
|
||||
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
/** @var Entry $entry */
|
||||
$entry = $em
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
|
||||
$headers = ['CONTENT_TYPE' => 'application/json'];
|
||||
$content = json_encode([
|
||||
'text' => 'my new annotation',
|
||||
'ranges' => [
|
||||
['start' => '', 'startOffset' => 25, 'end' => '', 'endOffset' => 32],
|
||||
],
|
||||
]);
|
||||
$this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content);
|
||||
|
||||
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
||||
|
||||
$content = json_decode($this->client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertSame('Big boss', $content['user']);
|
||||
$this->assertSame('v1.0', $content['annotator_schema_version']);
|
||||
$this->assertSame('my new annotation', $content['text']);
|
||||
$this->assertSame('', $content['quote']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForEachAnnotations
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue