Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/cydrobolt/polr.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaoyi Zha <summermontreal@gmail.com>2016-02-14 10:14:25 +0300
committerChaoyi Zha <summermontreal@gmail.com>2016-02-14 10:14:25 +0300
commitd52b634913597d464eddc45bfd4668a9b648f257 (patch)
tree416a3f53e78baaab3e869a9f3dc5c264ea94317b
parent73617a2fe7a628924f79530c5f568a93fc1a6b70 (diff)
Add basic LinkHelperTest
-rw-r--r--app/Factories/LinkFactory.php6
-rw-r--r--tests/LinkHelperTest.php46
-rw-r--r--tests/TestCase.php3
-rw-r--r--tests/test_env2
4 files changed, 53 insertions, 4 deletions
diff --git a/app/Factories/LinkFactory.php b/app/Factories/LinkFactory.php
index 173e0fc..52cbb56 100644
--- a/app/Factories/LinkFactory.php
+++ b/app/Factories/LinkFactory.php
@@ -24,7 +24,7 @@ class LinkFactory {
return $short_url;
}
- public static function createLink($long_url, $is_secret=false, $custom_ending=null, $link_ip='127.0.0.1', $creator=false) {
+ public static function createLink($long_url, $is_secret=false, $custom_ending=null, $link_ip='127.0.0.1', $creator=false, $return_object=false) {
/**
* Given parameters needed to create a link, generate appropriate ending and
* return formatted link.
@@ -94,6 +94,10 @@ class LinkFactory {
$formatted_link = self::formatLink($link_ending, $secret_key);
+ if ($return_object) {
+ return $link;
+ }
+
return $formatted_link;
}
diff --git a/tests/LinkHelperTest.php b/tests/LinkHelperTest.php
new file mode 100644
index 0000000..9d0153e
--- /dev/null
+++ b/tests/LinkHelperTest.php
@@ -0,0 +1,46 @@
+<?php
+use App\Helpers\LinkHelper;
+use App\Factories\LinkFactory;
+
+class LinkHelperTest extends TestCase
+{
+ /**
+ * Test LinkHelper
+ *
+ * @return void
+ */
+
+ public function testLinkHelperAlreadyShortened() {
+ $not_short = [
+ 'https://google.com',
+ 'https://example.com/google',
+ 'https://cydrobolt.com',
+ 'http://github.com/cydrobolt/polr'
+ ];
+
+ $shortened = [
+ 'https://polr.me/1',
+ 'http://bit.ly/1PUf6Sw',
+ 'http://'.env('APP_ADDRESS').'/1',
+ 'https://goo.gl/2pSp9f'
+ ];
+
+
+ foreach ($not_short as $u) {
+ $this->assertEquals(false, LinkHelper::checkIfAlreadyShortened($u));
+ }
+
+ foreach ($shortened as $u) {
+ $this->assertEquals(true, LinkHelper::checkIfAlreadyShortened($u));
+ }
+ }
+
+ public function testLinkExists() {
+ $link = LinkFactory::createLink('http://example.com/ci', $is_secret=false, $custom_ending=null, $link_ip='127.0.0.1', $creator=false, $return_object=true);
+ // assert that existent link ending returns true
+ $this->assertEquals(LinkHelper::linkExists($link->short_url), true);
+ // assert that nonexistent link ending returns false
+ $this->assertEquals(LinkHelper::linkExists('nonexistent'), false);
+
+ }
+}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 651d9cb..65bf8ad 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -7,8 +7,7 @@ class TestCase extends Laravel\Lumen\Testing\TestCase
*
* @return \Laravel\Lumen\Application
*/
- public function createApplication()
- {
+ public function createApplication() {
return require __DIR__.'/../bootstrap/app.php';
}
}
diff --git a/tests/test_env b/tests/test_env
index e712c52..be9d0cd 100644
--- a/tests/test_env
+++ b/tests/test_env
@@ -13,7 +13,7 @@ APP_NAME=Polr CI
APP_PROTOCOL=http://
# Your app's external address (e.g example.com)
-APP_ADDRESS=localhost:5000
+APP_ADDRESS=travis.polr.me
# Your app's bootstrap stylesheet
# e.g https://maxcdn.bootstrapcdn.com/bootswatch/3.3.5/flatly/bootstrap.min.css