Add file and utility unit tests, and extend media management unit test.
This commit is contained in:
parent
ab9dac908c
commit
10280c4686
|
@ -52,7 +52,7 @@ class File
|
|||
$file_parts = pathinfo($this->name);
|
||||
$new_file_name = $file_parts['filename'].$suffix.'.'.$file_parts['extension'];
|
||||
|
||||
if ($file_parts['dirname'])
|
||||
if ($file_parts['dirname'] != '.')
|
||||
$this->name = $file_parts['dirname'].DIRECTORY_SEPARATOR.$new_file_name;
|
||||
else
|
||||
$this->name = $new_file_name;
|
||||
|
|
|
@ -38,7 +38,7 @@ class Utilities
|
|||
*/
|
||||
public static function money_format($number)
|
||||
{
|
||||
return (($number < 0) ? '-' : '') . money_format(abs($number), 2);
|
||||
return (($number < 0) ? '-' : '') .'$'.number_format(abs($number), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
namespace Modules\Api\Controllers;
|
||||
|
||||
use \Entity\Song;
|
||||
use \Entity\SongHistory;
|
||||
use \Entity\SongVote;
|
||||
|
||||
class SongController extends BaseController
|
||||
{
|
||||
public function listAction()
|
||||
{
|
||||
$cache = $this->di['cache'];
|
||||
$return = $cache->get('api_songs');
|
||||
|
||||
if (!$return)
|
||||
{
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
$all_songs = $this->em->getRepository(Song::class)->fetchArray();
|
||||
$return = array();
|
||||
|
||||
foreach ($all_songs as $song)
|
||||
$return[$song['id']] = Song::api($song);
|
||||
|
||||
$cache->save($return, 'api_songs', array(), 60);
|
||||
}
|
||||
|
||||
return $this->returnSuccess($return);
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
if (!$this->hasParam('id'))
|
||||
return $this->listAction();
|
||||
|
||||
$id = $this->getParam('id');
|
||||
|
||||
$record = $this->em->getRepository(Song::class)->find($id);
|
||||
|
||||
if (!($record instanceof Song))
|
||||
return $this->returnError('Song not found.');
|
||||
|
||||
$return = Song::api($record);
|
||||
$return['external'] = $record->getExternal();
|
||||
return $this->returnSuccess($return);
|
||||
}
|
||||
|
||||
public function searchAction()
|
||||
{
|
||||
if (!$this->hasParam('q'))
|
||||
return $this->returnError('No query provided.');
|
||||
|
||||
$q = trim($this->getParam('q'));
|
||||
$results_raw = $this->em->createQuery('SELECT s FROM Entity\Song s WHERE (s.text LIKE :q OR s.id = :q_exact) ORDER BY s.text ASC')
|
||||
->setParameter('q', '%'.addcslashes($q, "%_").'%')
|
||||
->setParameter('q_exact', $q)
|
||||
->setMaxResults(50)
|
||||
->getArrayResult();
|
||||
|
||||
$results = array();
|
||||
|
||||
foreach($results_raw as $row)
|
||||
$results[$row['id']] = Song::api($row);
|
||||
|
||||
return $this->returnSuccess($results);
|
||||
}
|
||||
}
|
|
@ -49,6 +49,7 @@ coverage:
|
|||
# Exceptions
|
||||
- app/library/App/Exception.php
|
||||
- app/library/App/Exception/*.php
|
||||
- app/library/App/Mvc/ErrorHandler.php
|
||||
|
||||
# Used in application, but not detected properly by the coverage tool :(
|
||||
- app/**/routes.php
|
||||
|
|
|
@ -35,5 +35,9 @@ class C01_Station_MediaCest extends CestAbstract
|
|||
$I->seeResponseContainsJson([
|
||||
'media_name' => 'AzuraCast - AzuraCast Is Live!',
|
||||
]);
|
||||
|
||||
$I->amOnPage('/station/'.$station_id.'/files');
|
||||
|
||||
$I->see('Media Manager');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
class FileTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
public function testFile()
|
||||
{
|
||||
$file = new \App\File('test_file.wav', APP_INCLUDE_TEMP);
|
||||
$file->setName('test_file.mp3');
|
||||
|
||||
$expected_path = APP_INCLUDE_TEMP.'/test_file.mp3';
|
||||
$this->assertEquals($expected_path, $file->getPath());
|
||||
|
||||
$expected_extension = 'mp3';
|
||||
$this->assertEquals($expected_extension, $file->getExtension());
|
||||
|
||||
$file->addSuffix('.test');
|
||||
|
||||
$expected_name = 'test_file.test.mp3';
|
||||
$this->assertEquals($expected_name, $file->getName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
class UtilitiesTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
public function testUtilities()
|
||||
{
|
||||
$test_arr = ['test' => true, 'sub_test' => ['sub_test_1' => 42]];
|
||||
$test_result = \App\Utilities::print_r($test_arr, true);
|
||||
$expected_result = print_r($test_arr, true);
|
||||
$this->assertContains($expected_result, $test_result);
|
||||
|
||||
$money_test = -14.00;
|
||||
$test_result = \App\Utilities::money_format($money_test);
|
||||
$expected_result = '-$14.00';
|
||||
$this->assertEquals($expected_result, $test_result);
|
||||
|
||||
$test_result = \App\Utilities::generatePassword(10);
|
||||
$this->assertTrue(strlen($test_result) == 10);
|
||||
|
||||
$test_result = \App\Utilities::timeToText(8640000);
|
||||
$expected_result = '100 days';
|
||||
$this->assertEquals($expected_result, $test_result);
|
||||
|
||||
$time = time();
|
||||
$test_result = \App\Utilities::gstrtotime('+5 minutes', $time);
|
||||
$expected_result = $time+(60*5);
|
||||
$this->assertEquals($test_result, $expected_result);
|
||||
|
||||
$test_string = 'Lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet';
|
||||
$test_result = \App\Utilities::truncate_text($test_string, 15);
|
||||
$expected_result = 'Lorem ipsum...';
|
||||
$this->assertEquals($test_result, $expected_result);
|
||||
|
||||
$test_url = 'https://www.twitter.com/';
|
||||
$test_result = \App\Utilities::truncate_url($test_url);
|
||||
$expected_result = 'twitter.com';
|
||||
$this->assertEquals($test_result, $expected_result);
|
||||
|
||||
$test_array = ['one', 'two', 'three'];
|
||||
$test_result = \App\Utilities::join_compound($test_array);
|
||||
$expected_result = 'one, two and three';
|
||||
$this->assertEquals($test_result, $expected_result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue