diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CSRFTest.php | 36 | ||||
-rw-r--r-- | tests/HelpersTest.php | 11 | ||||
-rw-r--r-- | tests/OpmlManagerTest.php | 53 | ||||
-rw-r--r-- | tests/OpmlTest.php | 53 | ||||
-rw-r--r-- | tests/PlanetConfigTest.php | 7 | ||||
-rw-r--r-- | tests/PlanetTest.php | 11 | ||||
-rw-r--r-- | tests/opml/test-empty.opml | 0 | ||||
-rw-r--r-- | tests/opml/test-valid.opml | 16 |
8 files changed, 172 insertions, 15 deletions
diff --git a/tests/CSRFTest.php b/tests/CSRFTest.php new file mode 100644 index 0000000..39fda58 --- /dev/null +++ b/tests/CSRFTest.php @@ -0,0 +1,36 @@ +<?php + +use PHPUnit\Framework\TestCase; + +class CSRFTest extends TestCase +{ + public function testGetKey() + { + $this->temp_key = CSRF::getKey(); + $this->assertIsString($this->temp_key); + $this->assertEquals(32, strlen($this->temp_key)); + } + + public function testGenerate() + { + $token = CSRF::generate("some-action"); + $this->assertIsString($token); + $this->assertEquals(64, strlen($token)); + + $this->expectException(InvalidArgumentException::class); + CSRF::generate(); + CSRF::generate(12); + CSRF::generate(null); + } + + public function testVerify() + { + $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); + } +} diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php deleted file mode 100644 index a21ef1b..0000000 --- a/tests/HelpersTest.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -use PHPUnit\Framework\TestCase; - -class HelpersTest extends TestCase -{ - public function test_a() - { - $this->assertTrue(true); - } -} diff --git a/tests/OpmlManagerTest.php b/tests/OpmlManagerTest.php new file mode 100644 index 0000000..718e2f0 --- /dev/null +++ b/tests/OpmlManagerTest.php @@ -0,0 +1,53 @@ +<?php + +use PHPUnit\Framework\TestCase; + +class OpmlTest extends TestCase +{ + public function setUp() : void + { + $this->fixtures = [ + [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/' + ] + ]; + } + + public function testLoadValidFile() + { + $mngr = OpmlManager::load('tests/opml/test-valid.opml'); + $this->assertInstanceOf('Opml', $mngr); + } + + public function testLoadAbsentFile() + { + $this->expectException('Exception'); + OpmlManager::load('/some/where'); + } + + public function testFormat() + { + $file = 'tests/opml/test-valid.opml'; + $opml = OpmlManager::load($file); + $this->assertXmlStringEqualsXmlFile($file, OpmlManager::format($opml, true)); + } +} diff --git a/tests/OpmlTest.php b/tests/OpmlTest.php new file mode 100644 index 0000000..571fdaf --- /dev/null +++ b/tests/OpmlTest.php @@ -0,0 +1,53 @@ +<?php + +use PHPUnit\Framework\TestCase; + +class OpmlManagerTest extends TestCase +{ + public function setUp() : void + { + $this->fixtures = [ + [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/' + ] + ]; + } + + public function testParse() + { + foreach ($this->fixtures as $data) { + $given = $data[0]; + $entries = $data[1]; + + $opml = new Opml(); + $entries = $opml->parse($given); + + $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); + } + } +} diff --git a/tests/PlanetConfigTest.php b/tests/PlanetConfigTest.php index 4db6e90..ddf7373 100644 --- a/tests/PlanetConfigTest.php +++ b/tests/PlanetConfigTest.php @@ -70,4 +70,11 @@ class PlanetConfigTest extends TestCase $conf = new PlanetConfig(['foo' => 'bar'], false); $this->assertEquals("---\nfoo: bar\n", $conf->toYaml()); } + + public function testConfigLoad() + { + $conf = PlanetConfig::load("."); + $default = new PlanetConfig(); + $this->assertEquals($default, $conf); + } } diff --git a/tests/PlanetTest.php b/tests/PlanetTest.php index d4b87b8..1bc699b 100644 --- a/tests/PlanetTest.php +++ b/tests/PlanetTest.php @@ -22,10 +22,12 @@ class FoolItem { protected $categories; - public function __construct($categories) + public function __construct($categories = null) { - foreach ($categories as $c) { - $this->categories[] = new FoolCategory($c); + if (is_array($categories)) { + foreach ($categories as $c) { + $this->categories[] = new FoolCategory($c); + } } } @@ -49,7 +51,8 @@ class PlanetTest extends TestCase new FoolItem(array('catA', 'catB', 'catC')), new FoolItem(array('catB')), new FoolItem(array('catA')), - new FoolItem(array('catC')) + new FoolItem(array('catC')), + new FoolItem(), ); } diff --git a/tests/opml/test-empty.opml b/tests/opml/test-empty.opml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/opml/test-empty.opml diff --git a/tests/opml/test-valid.opml b/tests/opml/test-valid.opml new file mode 100644 index 0000000..686d19e --- /dev/null +++ b/tests/opml/test-valid.opml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<opml version="2.0"> +<head> +<title>Test OPML</title> +<dateCreated>2022-01-14T17:15:05+00:00</dateCreated> +<dateModified>2022-01-14T17:15:05+00:00</dateModified> +<ownerName>user name</ownerName> +<ownerEmail>user@example.com</ownerEmail> +<ownerId>http://user.example.com/</ownerId> +<docs>http://opml.org/spec2.opml</docs> +</head> +<body> +<outline text="text 1" htmlUrl="https://blog.example.com/" xmlUrl="https://some.other.example.com/feed/path" isDown="" /> +<outline text="text 2" htmlUrl="https://blog2.example.com" xmlUrl="https://blog2.example.com/rss.xml" isDown="" /> +</body> +</opml>
\ No newline at end of file |