summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-09 09:08:19 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-09 09:09:59 +0200
commit8462bed7820cecc23a0e0d64aa50db7be92272d9 (patch)
treed670947a499cd7f173ebb6c88b303aefc239b65a
parent900dbbb61e45ba6557db08ee33f6badbb8939efe (diff)
cleanup test method in appconfig class, add test for item serialization
-rw-r--r--config/appconfig.php56
-rw-r--r--tests/unit/db/ItemTest.php40
2 files changed, 73 insertions, 23 deletions
diff --git a/config/appconfig.php b/config/appconfig.php
index 52e82dc25..3729e56b2 100644
--- a/config/appconfig.php
+++ b/config/appconfig.php
@@ -153,51 +153,65 @@ class AppConfig {
}
}
- private function testDatabaseDependencies($databases, $databaseType) {
- if(!in_array($databaseType, $databases)) {
+
+ private function testDatabaseDependencies() {
+ if(array_key_exists('databases', $this->config)) {
+ $databases = $this->config['databases'];
+ $databaseType = $this->databaseType;
+
+ if(!in_array($databaseType, $databases)) {
return 'Database ' . $databaseType . ' not supported.' .
'App is only compatible with ' .
implode(', ', $databases);
- } else {
- return '';
+ }
}
+ return '';
}
- /**
- * Validates all dependencies that the app has
- * @throws DependencyException if one version is not satisfied
- */
- public function testDependencies() {
- $msg = '';
-
- // test databases
- if(array_key_exists('databases', $this->config)) {
- $msg .= $this->testDatabaseDependencies(
- $this->config['databases'], $this->databaseType
- );
- }
- // test dependencies
+ private function testPHPDependencies() {
if(array_key_exists('dependencies', $this->config)) {
$deps = $this->config['dependencies'];
if (array_key_exists('php', $deps)) {
- $msg .= $this->requireVersion($this->phpVersion, $deps['php'],
+ return $this->requireVersion($this->phpVersion, $deps['php'],
'PHP');
}
+ }
+ return '';
+ }
+
+
+ private function testLibraryDependencies() {
+ if(array_key_exists('dependencies', $this->config)) {
+
+ $deps = $this->config['dependencies'];
+
if (array_key_exists('libs', $deps)) {
foreach ($deps['libs'] as $lib => $versions) {
if(array_key_exists($lib, $this->installedExtensions)) {
- $msg .= $this->requireVersion($this->installedExtensions[$lib],
+ return $this->requireVersion($this->installedExtensions[$lib],
$versions, 'PHP extension ' . $lib);
} else {
- $msg .= 'PHP extension ' . $lib . ' required but not installed';
+ return 'PHP extension ' . $lib . ' required but not installed';
}
}
}
}
+ return '';
+ }
+
+
+ /**
+ * Validates all dependencies that the app has
+ * @throws DependencyException if one version is not satisfied
+ */
+ public function testDependencies() {
+ $msg = $this->testDatabaseDependencies();
+ $msg .= $this->testPHPDependencies();
+ $msg .= $this->testLibraryDependencies();
if($msg !== '') {
throw new DependencyException($msg);
diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php
index 23deb4c14..4c9569ed4 100644
--- a/tests/unit/db/ItemTest.php
+++ b/tests/unit/db/ItemTest.php
@@ -89,6 +89,42 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
}
+ public function testJSONSerialize() {
+ $item = new Item();
+ $item->setId(3);
+ $item->setGuid('guid');
+ $item->setGuidHash('hash');
+ $item->setUrl('https://google');
+ $item->setTitle('title');
+ $item->setAuthor('author');
+ $item->setPubDate(123);
+ $item->setBody('body');
+ $item->setEnclosureMime('audio/ogg');
+ $item->setEnclosureLink('enclink');
+ $item->setFeedId(1);
+ $item->setStatus(0);
+ $item->setUnread();
+ $item->setStarred();
+ $item->setLastModified(321);
+
+ $this->assertEquals([
+ 'id' => 3,
+ 'guid' => 'guid',
+ 'guidHash' => 'hash',
+ 'url' => 'https://google',
+ 'title' => 'title',
+ 'author' => 'author',
+ 'pubDate' => 123,
+ 'body' => 'body',
+ 'enclosureMime' => 'audio/ogg',
+ 'enclosureLink' => 'enclink',
+ 'feedId' => 1,
+ 'unread' => true,
+ 'starred' => true,
+ 'lastModified' => 321
+ ], $item->jsonSerialize());
+ }
+
public function testToExport() {
$item = new Item();
$item->setId(3);
@@ -154,7 +190,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
];
$compareWith = Item::fromImport($import);
-
+
$this->assertEquals($item, $compareWith);
}
@@ -199,7 +235,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
public function testMakeLinksInBodyOpenNewTab() {
$item = new Item();
$item->setBody("<a href=\"test\">ha</a>");
- $this->assertEquals("<a target=\"_blank\" href=\"test\">ha</a>",
+ $this->assertEquals("<a target=\"_blank\" href=\"test\">ha</a>",
$item->getBody());
}