From 769e19dc4ab1a068e8165a7b237f42a78a6d312f Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 29 Mar 2015 10:53:10 +0200 Subject: Move API stuff in ApiBundle --- .../Tests/Command/InstallCommandTest.php | 4 +- .../Tests/Controller/ConfigControllerTest.php | 4 +- .../Tests/Controller/EntryControllerTest.php | 4 +- .../Tests/Controller/SecurityControllerTest.php | 4 +- .../Controller/WallabagRestControllerTest.php | 214 --------------------- .../CoreBundle/Tests/WallabagCoreTestCase.php | 32 +++ src/Wallabag/CoreBundle/Tests/WallabagTestCase.php | 32 --- 7 files changed, 40 insertions(+), 254 deletions(-) delete mode 100644 src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php create mode 100644 src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php delete mode 100644 src/Wallabag/CoreBundle/Tests/WallabagTestCase.php (limited to 'src/Wallabag/CoreBundle/Tests') diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index f689b532..7a819953 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -2,7 +2,7 @@ namespace Wallabag\CoreBundle\Tests\Command; -use Wallabag\CoreBundle\Tests\WallabagTestCase; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; use Wallabag\CoreBundle\Command\InstallCommand; use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock; use Symfony\Bundle\FrameworkBundle\Console\Application; @@ -12,7 +12,7 @@ use Symfony\Component\Console\Output\NullOutput; use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; -class InstallCommandTest extends WallabagTestCase +class InstallCommandTest extends WallabagCoreTestCase { public static function tearDownAfterClass() { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 5030bcbd..3c158922 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -2,9 +2,9 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -class ConfigControllerTest extends WallabagTestCase +class ConfigControllerTest extends WallabagCoreTestCase { public function testLogin() { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 1a0d586c..8a7fdda2 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -2,10 +2,10 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; use Doctrine\ORM\AbstractQuery; -class EntryControllerTest extends WallabagTestCase +class EntryControllerTest extends WallabagCoreTestCase { public function testLogin() { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php index 1dd05f89..e560ffdd 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php @@ -2,11 +2,11 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -class SecurityControllerTest extends WallabagTestCase +class SecurityControllerTest extends WallabagCoreTestCase { public function testLogin() { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php deleted file mode 100644 index c9907065..00000000 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ /dev/null @@ -1,214 +0,0 @@ -format('Y-m-d\TH:i:s\Z'); - $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); - - return array( - 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', - 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"', - ); - } - - public function testGetSalt() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertNotEmpty(json_decode($client->getResponse()->getContent())); - - $client->request('GET', '/api/salts/notfound.json'); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); - } - - public function testWithBadHeaders() - { - $client = $this->createClient(); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByIsArchived(false); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $badHeaders = array( - 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', - 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="admin", PasswordDigest="Wr0ngDig3st", Nonce="n0Nc3", Created="2015-01-01T13:37:00Z"', - ); - - $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $badHeaders); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); - } - - public function testGetOneEntry() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByIsArchived(false); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); - $this->assertContains($entry->getTitle(), $client->getResponse()->getContent()); - - $this->assertTrue( - $client->getResponse()->headers->contains( - 'Content-Type', - 'application/json' - ) - ); - } - - public function testGetEntries() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $client->request('GET', '/api/entries', array(), array(), $headers); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $this->assertGreaterThanOrEqual(1, count(json_decode($client->getResponse()->getContent()))); - - $this->assertContains('Google', $client->getResponse()->getContent()); - - $this->assertTrue( - $client->getResponse()->headers->contains( - 'Content-Type', - 'application/json' - ) - ); - } - - public function testDeleteEntry() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - // We'll try to delete this entry again - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); - - $this->assertEquals(404, $client->getResponse()->getStatusCode()); - } - - public function testGetTagsEntry() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneWithTags(1); - - $entry = $entry[0]; - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $tags = array(); - foreach ($entry->getTags() as $tag) { - $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel()); - } - - $client->request('GET', '/api/entries/'.$entry->getId().'/tags', array(), array(), $headers); - - $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $client->getResponse()->getContent()); - } - - public function testPostTagsOnEntry() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $newTags = 'tag1,tag2,tag3'; - - $client->request('POST', '/api/entries/'.$entry->getId().'/tags', array('tags' => $newTags), array(), $headers); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $entryDB = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->find($entry->getId()); - - $tagsInDB = array(); - foreach ($entryDB->getTags()->toArray() as $tag) { - $tagsInDB[$tag->getId()] = $tag->getLabel(); - } - - foreach (explode(',', $newTags) as $tag) { - $this->assertContains($tag, $tagsInDB); - } - } -} diff --git a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php new file mode 100644 index 00000000..e5096528 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php @@ -0,0 +1,32 @@ +client; + } + + public function setUp() + { + $this->client = static::createClient(); + } + + public function logInAs($username) + { + $crawler = $this->client->request('GET', '/login'); + $form = $crawler->filter('button[type=submit]')->form(); + $data = array( + '_username' => $username, + '_password' => 'mypassword', + ); + + $this->client->submit($form, $data); + } +} diff --git a/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php deleted file mode 100644 index 22016d8e..00000000 --- a/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php +++ /dev/null @@ -1,32 +0,0 @@ -client; - } - - public function setUp() - { - $this->client = static::createClient(); - } - - public function logInAs($username) - { - $crawler = $this->client->request('GET', '/login'); - $form = $crawler->filter('button[type=submit]')->form(); - $data = array( - '_username' => $username, - '_password' => 'mypassword', - ); - - $this->client->submit($form, $data); - } -} -- cgit v1.2.3 From 9744e97131182f413b51a0ce671ff273fc28a0bb Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 1 Apr 2015 21:53:57 +0200 Subject: Fix tests --- .../CoreBundle/Tests/Controller/ConfigControllerTest.php | 2 +- src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests') diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 3c158922..a0145780 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -397,7 +397,7 @@ class ConfigControllerTest extends WallabagCoreTestCase ); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $content = json_decode($client->getResponse()->getContent(), true);; + $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('token', $content); } diff --git a/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php index 8f627b4b..b7c162a7 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php @@ -2,9 +2,9 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -class RssControllerTest extends WallabagTestCase +class RssControllerTest extends WallabagCoreTestCase { public function validateDom($xml, $nb = null) { @@ -36,13 +36,13 @@ class RssControllerTest extends WallabagTestCase { return array( array( - '/admin/YZIOAUZIAO/unread.xml' + '/admin/YZIOAUZIAO/unread.xml', ), array( - '/wallace/YZIOAUZIAO/starred.xml' + '/wallace/YZIOAUZIAO/starred.xml', ), array( - '/wallace/YZIOAUZIAO/archives.xml' + '/wallace/YZIOAUZIAO/archives.xml', ), ); } -- cgit v1.2.3