mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-23 08:06:33 +00:00
parent
a406434701
commit
8197f08266
4 changed files with 33 additions and 1 deletions
|
@ -60,6 +60,7 @@ class Annotation
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
|
* @Assert\NotNull()
|
||||||
* @Assert\Length(
|
* @Assert\Length(
|
||||||
* max = 10000,
|
* max = 10000,
|
||||||
* maxMessage = "validator.quote_length_too_high"
|
* maxMessage = "validator.quote_length_too_high"
|
||||||
|
|
|
@ -18,6 +18,7 @@ class NewAnnotationType extends AbstractType
|
||||||
])
|
])
|
||||||
->add('quote', null, [
|
->add('quote', null, [
|
||||||
'empty_data' => null,
|
'empty_data' => null,
|
||||||
|
'trim' => false,
|
||||||
])
|
])
|
||||||
->add('ranges', CollectionType::class, [
|
->add('ranges', CollectionType::class, [
|
||||||
'entry_type' => RangeType::class,
|
'entry_type' => RangeType::class,
|
||||||
|
|
|
@ -37,7 +37,7 @@ class AnnotationRestController extends WallabagRestController
|
||||||
* @ApiDoc(
|
* @ApiDoc(
|
||||||
* requirements={
|
* requirements={
|
||||||
* {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"},
|
* {"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"="quote", "dataType"="string", "required"=true, "description"="Quote for the annotation"},
|
||||||
* {"name"="text", "dataType"="string", "required"=true, "description"=""},
|
* {"name"="text", "dataType"="string", "required"=true, "description"=""},
|
||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
|
|
|
@ -107,6 +107,36 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
||||||
$this->assertSame('my annotation', $annotation->getText());
|
$this->assertSame('my annotation', $annotation->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCouldNotSetAnnotationWithoutQuote()
|
||||||
|
{
|
||||||
|
$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(400, $this->client->getResponse()->getStatusCode());
|
||||||
|
|
||||||
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
||||||
|
|
||||||
|
$this->assertCount(
|
||||||
|
1,
|
||||||
|
$content['errors']['children']['quote']['errors'],
|
||||||
|
'The quote field should contains an error'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataForEachAnnotations
|
* @dataProvider dataForEachAnnotations
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue