From 2c3e148b0029a094431622feac79fafcd0d43fc8 Mon Sep 17 00:00:00 2001 From: adev Date: Sun, 7 May 2017 17:21:30 +0200 Subject: Displays an error with an annotation with a too long quote Fix #2762 --- .../Controller/AnnotationControllerTest.php | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/AnnotationBundle/Controller') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 81f9e9ec..8f87ccf3 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -84,7 +84,9 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $content = json_encode([ 'text' => 'my annotation', 'quote' => 'my quote', - 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], + 'ranges' => [ + ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31] + ], ]); $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content); @@ -106,6 +108,36 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $this->assertEquals('my annotation', $annotation->getText()); } + /** + * @dataProvider dataForEachAnnotations + */ + public function testSetAnnotationWithQuoteTooLong($prefixUrl) + { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + + if ('annotations' === $prefixUrl) { + $this->logInAs('admin'); + } + + /** @var Entry $entry */ + $entry = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUsernameAndNotArchived('admin'); + + $longQuote = str_repeat('a', 10001); + $headers = ['CONTENT_TYPE' => 'application/json']; + $content = json_encode([ + 'text' => 'my annotation', + 'quote' => $longQuote, + 'ranges' => [ + ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31] + ], + ]); + $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content); + + $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + } + /** * Test editing an existing annotation. * -- cgit v1.2.3 From eb570e49c8e3ba12638fac600bb5527191c2aaa2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 7 Jun 2017 23:23:34 +0200 Subject: CS --- .../Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/AnnotationBundle/Controller') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 8f87ccf3..3c94382c 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -85,7 +85,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase 'text' => 'my annotation', 'quote' => 'my quote', 'ranges' => [ - ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31] + ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], ], ]); $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content); @@ -130,7 +130,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase 'text' => 'my annotation', 'quote' => $longQuote, 'ranges' => [ - ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31] + ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], ], ]); $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content); -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../Controller/AnnotationControllerTest.php | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'tests/Wallabag/AnnotationBundle/Controller') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 3c94382c..96474468 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -49,12 +49,12 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $this->logInAs('admin'); } - $this->client->request('GET', $prefixUrl.'/'.$entry->getId().'.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->client->request('GET', $prefixUrl . '/' . $entry->getId() . '.json'); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThanOrEqual(1, $content['total']); - $this->assertEquals($annotation->getText(), $content['rows'][0]['text']); + $this->assertSame($annotation->getText(), $content['rows'][0]['text']); // we need to re-fetch the annotation becase after the flush, it has been "detached" from the entity manager $annotation = $em->getRepository('WallabagAnnotationBundle:Annotation')->findAnnotationById($annotation->getId()); @@ -88,16 +88,16 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], ], ]); - $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content); + $this->client->request('POST', $prefixUrl . '/' . $entry->getId() . '.json', [], [], $headers, $content); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $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']); + $this->assertSame('Big boss', $content['user']); + $this->assertSame('v1.0', $content['annotator_schema_version']); + $this->assertSame('my annotation', $content['text']); + $this->assertSame('my quote', $content['quote']); /** @var Annotation $annotation */ $annotation = $this->client->getContainer() @@ -105,7 +105,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase ->getRepository('WallabagAnnotationBundle:Annotation') ->findLastAnnotationByPageId($entry->getId(), 1); - $this->assertEquals('my annotation', $annotation->getText()); + $this->assertSame('my annotation', $annotation->getText()); } /** @@ -133,9 +133,9 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], ], ]); - $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content); + $this->client->request('POST', $prefixUrl . '/' . $entry->getId() . '.json', [], [], $headers, $content); - $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + $this->assertSame(400, $this->client->getResponse()->getStatusCode()); } /** @@ -166,21 +166,21 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $content = json_encode([ 'text' => 'a modified annotation', ]); - $this->client->request('PUT', $prefixUrl.'/'.$annotation->getId().'.json', [], [], $headers, $content); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->client->request('PUT', $prefixUrl . '/' . $annotation->getId() . '.json', [], [], $headers, $content); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals('Big boss', $content['user']); - $this->assertEquals('v1.0', $content['annotator_schema_version']); - $this->assertEquals('a modified annotation', $content['text']); - $this->assertEquals('my quote', $content['quote']); + $this->assertSame('Big boss', $content['user']); + $this->assertSame('v1.0', $content['annotator_schema_version']); + $this->assertSame('a modified annotation', $content['text']); + $this->assertSame('my quote', $content['quote']); /** @var Annotation $annotationUpdated */ $annotationUpdated = $em ->getRepository('WallabagAnnotationBundle:Annotation') ->findOneById($annotation->getId()); - $this->assertEquals('a modified annotation', $annotationUpdated->getText()); + $this->assertSame('a modified annotation', $annotationUpdated->getText()); $em->remove($annotationUpdated); $em->flush(); @@ -218,12 +218,12 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $content = json_encode([ 'text' => 'a modified annotation', ]); - $this->client->request('DELETE', $prefixUrl.'/'.$annotation->getId().'.json', [], [], $headers, $content); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->client->request('DELETE', $prefixUrl . '/' . $annotation->getId() . '.json', [], [], $headers, $content); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals('This is my annotation /o/', $content['text']); + $this->assertSame('This is my annotation /o/', $content['text']); $annotationDeleted = $em ->getRepository('WallabagAnnotationBundle:Annotation') -- cgit v1.2.3