All Data Structures Functions Variables Pages
ShortUrlTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
37  {
38  public static function getDependentTestModelClassNames()
39  {
40  return array('ShortUrlForTest');
41  }
42 
43  public function testResolveHashByUrl()
44  {
45  $url = 'http://www.zurmo.com';
46  $hash = ShortUrl::resolveHashByUrl($url);
47  $this->assertEquals(ShortUrl::HASH_LENGTH, strlen($hash));
48  $shortUrls = ShortUrl::getAll();
49  $this->assertCount (1, $shortUrls);
50  $this->assertEquals($url, $shortUrls[0]->url);
51 
52  //The same url should return the same hash and not create a new one
53  $hash2 = ShortUrl::resolveHashByUrl($url);
54  $this->assertEquals($hash, $hash2);
55  $this->assertCount (1, ShortUrl::getAll());
56 
57  //New url should have new hash
58  $url2 = 'http://www.zurmo.org';
59  $hash2 = ShortUrl::resolveHashByUrl($url2);
60  $this->assertNotEquals($hash, $hash2);
61  $this->assertCount (2, ShortUrl::getAll());
62 
64  }
65 
66  public function testGetHashByUrl()
67  {
68  $url = 'http://www.zurmo.com';
69  try
70  {
72  $this->assertTrue(false);
73  }
74  catch (NotFoundException $exception)
75  {
76  $this->assertTrue(true);
77  }
78 
79  $shortUrl = new ShortUrl();
80  $shortUrl->hash = 'abcdefghij';
81  $shortUrl->url = $url;
82  $shortUrl->save();
83  $hash = ShortUrl::getHashByUrl($url);
84  $this->assertEquals('abcdefghij', $hash);
85 
87  }
88 
89  public function testDeleteOld()
90  {
91  $shortUrlForTest = new ShortUrlForTest();
92  $shortUrlForTest->setStubCreatedDateTime(time() - 200 * 24 * 60 * 60);
93  $shortUrlForTest->hash = 'abcdefghij';
94  $shortUrlForTest->url = 'http://www.zurmo.com';
95  $this->assertTrue($shortUrlForTest->save());
96 
97  $shortUrlForTest2 = new ShortUrlForTest();
98  $shortUrlForTest2->setStubCreatedDateTime(time() - 3 * 24 * 60 * 60);
99  $shortUrlForTest2->hash = '1234567890';
100  $shortUrlForTest2->url = 'http://www.zurmo.org';
101  $this->assertTrue($shortUrlForTest2->save());
102 
103  $this->assertEquals(2, $shortUrlForTest::getCount());
105  $this->assertEquals(1, $shortUrlForTest::getCount());
106  $shortUrlsForTest = ShortUrlForTest::getAll();
107  $this->assertEquals($shortUrlForTest2, $shortUrlsForTest[0]);
108  }
109  }
110 ?>
static deleteAll()
static getHashByUrl($url)
Definition: ShortUrl.php:119
static resolveHashByUrl($url)
Definition: ShortUrl.php:82
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static deleteOld()
Definition: ShortUrl.php:181
Generated on Fri Feb 21 2020 07:10:37