diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CSRFTest.php | 24 | ||||
-rw-r--r-- | tests/OpmlTest.php | 54 |
2 files changed, 57 insertions, 21 deletions
diff --git a/tests/CSRFTest.php b/tests/CSRFTest.php index 39fda58..ccb63e9 100644 --- a/tests/CSRFTest.php +++ b/tests/CSRFTest.php @@ -23,14 +23,24 @@ class CSRFTest extends TestCase CSRF::generate(null); } - public function testVerify() + public function verifyProvider() { $token = CSRF::generate("some-action"); - $this->assertEquals(CSRF::verify($token, "some-action"), true); - $this->assertEquals(CSRF::verify($token, "other-action"), false); - $this->assertEquals(CSRF::verify("anything-else", "some-action"), false); - $this->assertEquals(CSRF::verify(1, "string"), false); - $this->assertEquals(CSRF::verify("string", 2), false); - $this->assertEquals(CSRF::verify(null, null), false); + return [ + 'valid pair' => [$token, 'some-action', true], + 'different action' => [$token, 'other-action', false], + 'wrong token value' => ['anything-else', 'some-action', false], + 'wrong token type' => [1, 'string', false], + 'wrong action type' => ['string', 2, false], + 'null token/action' => [null, null, false] + ]; + } + + /** + * @dataProvider verifyProvider + */ + public function testVerify($token, $action, $expected) + { + $this->assertEquals(CSRF::verify($token, $action), $expected); } } diff --git a/tests/OpmlTest.php b/tests/OpmlTest.php index 571fdaf..3da4dc8 100644 --- a/tests/OpmlTest.php +++ b/tests/OpmlTest.php @@ -32,22 +32,48 @@ class OpmlManagerTest extends TestCase ]; } - public function testParse() + public function parseProvider() { - foreach ($this->fixtures as $data) { - $given = $data[0]; - $entries = $data[1]; + return [ + [file_get_contents('./tests/opml/test-empty.opml'), [], '', '', '', ''], + [ + file_get_contents('./tests/opml/test-valid.opml'), + [ + [ + 'website' => 'https://blog.example.com/', + 'name' => 'text 1', + 'feed' => 'https://some.other.example.com/feed/path', + 'isDown' => '', + ], + [ + 'website' => 'https://blog2.example.com', + 'name' => 'text 2', + 'feed' => 'https://blog2.example.com/rss.xml', + 'isDown' => '', + ] + ], + 'Test OPML', + 'user name', + 'user@example.com', + 'http://user.example.com/' + ] + ]; + } - $opml = new Opml(); - $entries = $opml->parse($given); + /** + * @dataProvider parseProvider + */ + public function testParse($feedContents, $feeds, $title, $name, $email, $id) + { + $opml = new Opml(); + $entries = $opml->parse($feedContents); - $this->assertEquals($data[1], $entries); - $this->assertEquals($data[1], $opml->entries); - $this->assertEquals($data[1], $opml->getPeople()); - $this->assertEquals($data[2], $opml->getTitle()); - $this->assertEquals($data[3], $opml->ownerName); - $this->assertEquals($data[4], $opml->ownerEmail); - $this->assertEquals($data[5], $opml->ownerId); - } + $this->assertEquals($feeds, $entries); + $this->assertEquals($feeds, $opml->entries); + $this->assertEquals($feeds, $opml->getPeople()); + $this->assertEquals($title, $opml->getTitle()); + $this->assertEquals($name, $opml->ownerName); + $this->assertEquals($email, $opml->ownerEmail); + $this->assertEquals($id, $opml->ownerId); } } |