public function testSync() { $media = new Media(); $media->sync($this->mediaPath); // Standard mp3 files under root path should be recognized $this->seeInDatabase('songs', ['path' => $this->mediaPath . '/full.mp3']); // Ogg files and audio files in subdirectories should be recognized $this->seeInDatabase('songs', ['path' => $this->mediaPath . '/subdir/back-in-black.ogg']); // Non-audio files shouldn't be recognized $this->notSeeInDatabase('songs', ['path' => $this->mediaPath . '/rubbish.log']); // Broken/corrupted audio files shouldn't be recognized $this->notSeeInDatabase('songs', ['path' => $this->mediaPath . '/fake.mp3']); // Artists should be created $this->seeInDatabase('artists', ['name' => 'Cuckoo']); $this->seeInDatabase('artists', ['name' => 'Koel']); // Albums should be created $this->seeInDatabase('albums', ['name' => 'Koel Testing Vol. 1']); // Albums and artists should be correctly linked $album = Album::whereName('Koel Testing Vol. 1')->first(); $this->assertEquals('Koel', $album->artist->name); $currentCover = $album->cover; $song = Song::orderBy('id', 'desc')->first(); // Modified file should be recognized touch($song->path, $time = time()); $media->sync($this->mediaPath); $song = Song::find($song->id); $this->assertEquals($time, $song->mtime); // Albums with a non-default cover should have their covers overwritten $this->assertEquals($currentCover, Album::find($album->id)->cover); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($society) { $data['soc'] = Society::find($society); $data['lets'] = array('1' => 'A', '2' => 'B', '3' => 'C', '4' => 'D', '5' => 'E', '6' => 'F', '7' => 'G', '8' => 'H', '9' => 'I', '10' => 'J', '11' => 'K', '12' => 'L', '13' => 'M', '14' => 'N', '15' => 'O', '16' => 'P', '17' => 'Q', '18' => 'R', '19' => 'S', '20' => 'T', '21' => 'U', '22' => 'V', '23' => 'W', '24' => 'X', '25' => 'Y', '26' => 'Z'); $data['songs'] = Song::orderBy('title')->get(); return View::make('songs.index', $data); }
public function testWatchSingleFileDeleted() { $this->expectsEvents(LibraryChanged::class); $this->createSampleMediaSet(); $song = Song::orderBy('id', 'desc')->first(); (new Media())->syncByWatchRecord(new InotifyWatchRecord("DELETE {$song->path}")); $this->notSeeInDatabase('songs', ['id' => $song->id]); }
public function testWatchSingleFileDeleted() { $this->expectsEvents(LibraryChanged::class); $this->createSampleMediaSet(); $song = Song::orderBy('id', 'desc')->first(); $record = m::mock(FSWatchRecord::class, ['isDeleted' => true, 'getPath' => $song->path, 'isFile' => true, 'isValidEvent' => true], ["{$song->path} IsFile"]); (new Media())->syncFSWatchRecord($record); $this->notSeeInDatabase('songs', ['id' => $song->id]); }
public function testBatchLikeAndUnlike() { $user = factory(User::class)->create(); $songs = Song::orderBy('id')->take(2)->get(); $songIds = array_pluck($songs->toArray(), 'id'); $this->actingAs($user)->post('api/interaction/batch/like', ['ids' => $songIds]); foreach ($songs as $song) { $this->seeInDatabase('interactions', ['user_id' => $user->id, 'song_id' => $song->id, 'liked' => 1]); } $this->actingAs($user)->post('api/interaction/batch/unlike', ['ids' => $songIds]); foreach ($songs as $song) { $this->seeInDatabase('interactions', ['user_id' => $user->id, 'song_id' => $song->id, 'liked' => 0]); } }
public function testSyncPlaylist() { $user = factory(User::class)->create(); $playlist = factory(Playlist::class)->create(['user_id' => $user->id]); $songs = Song::orderBy('id')->take(4)->get(); $playlist->songs()->attach(array_pluck($songs->toArray(), 'id')); $removedSong = $songs->pop(); $this->actingAs($user)->put("api/playlist/{$playlist->id}/sync", ['songs' => array_pluck($songs->toArray(), 'id')]); // We should still see the first 3 songs, but not the removed one foreach ($songs as $song) { $this->seeInDatabase('playlist_song', ['playlist_id' => $playlist->id, 'song_id' => $song->id]); } $this->notSeeInDatabase('playlist_song', ['playlist_id' => $playlist->id, 'song_id' => $removedSong->id]); }
public function testSingleUpdateAllInfoYesCompilation() { $admin = factory(User::class, 'admin')->create(); $this->createSampleMediaSet(); $song = Song::orderBy('id', 'desc')->first(); $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Foo Bar', 'artistName' => 'John Cena', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 1]])->seeStatusCode(200); $compilationAlbum = Album::whereArtistIdAndName(Artist::VARIOUS_ID, 'One by One')->first(); $this->assertNotNull($compilationAlbum); $contributingArtist = Artist::whereName('John Cena')->first(); $this->assertNotNull($contributingArtist); $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => $contributingArtist->id, 'album_id' => $compilationAlbum->id, 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1]); // Now try changing stuff and make sure things work. // Case 1: Keep compilation state and artist the same $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Barz Qux', 'artistName' => 'John Cena', 'albumName' => 'Two by Two', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 2]])->seeStatusCode(200); $compilationAlbum = Album::whereArtistIdAndName(Artist::VARIOUS_ID, 'Two by Two')->first(); $this->assertNotNull($compilationAlbum); $contributingArtist = Artist::whereName('John Cena')->first(); $this->assertNotNull($contributingArtist); $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => $contributingArtist->id, 'album_id' => $compilationAlbum->id]); // Case 2: Keep compilation state, but change the artist. $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Barz Qux', 'artistName' => 'Foo Fighters', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 2]])->seeStatusCode(200); $compilationAlbum = Album::whereArtistIdAndName(Artist::VARIOUS_ID, 'One by One')->first(); $this->assertNotNull($compilationAlbum); $contributingArtist = Artist::whereName('Foo Fighters')->first(); $this->assertNotNull($contributingArtist); $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => $contributingArtist->id, 'album_id' => $compilationAlbum->id]); // Case 3: Change compilation state only $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Barz Qux', 'artistName' => 'Foo Fighters', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 0]])->seeStatusCode(200); $artist = Artist::whereName('Foo Fighters')->first(); $this->assertNotNull($artist); $album = Album::whereArtistIdAndName($artist->id, 'One by One')->first(); $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => null, 'album_id' => $album->id]); // Case 3: Change compilation state and artist // Remember to set the compliation state back to 1 $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Barz Qux', 'artistName' => 'Foo Fighters', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 1]])->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Twilight of the Thunder God', 'artistName' => 'Amon Amarth', 'albumName' => 'Twilight of the Thunder God', 'lyrics' => 'Thor! Nanananananana Batman.', 'track' => 1, 'compilationState' => 0]])->seeStatusCode(200); $artist = Artist::whereName('Amon Amarth')->first(); $this->assertNotNull($artist); $album = Album::whereArtistIdAndName($artist->id, 'Twilight of the Thunder God')->first(); $this->assertNotNull($album); $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => null, 'album_id' => $album->id, 'lyrics' => 'Thor! Nanananananana Batman.']); }
public function testMultipleUpdateSomeInfo() { $this->createSampleMediaSet(); $originalSongs = Song::orderBy('id', 'desc')->take(3)->get(); $songIds = $originalSongs->pluck('id')->toArray(); $this->actingAs(factory(User::class, 'admin')->create())->put('/api/songs', ['songs' => $songIds, 'data' => ['title' => 'Foo Bar', 'artistName' => 'John Cena', 'albumName' => '', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1]])->seeStatusCode(200); $songs = Song::orderBy('id', 'desc')->take(3)->get(); // Even though the album name doesn't change, a new artist should have been created // and thus, a new album with the same name was created as well. $this->assertEquals($songs[0]->album->name, $originalSongs[0]->album->name); $this->assertNotEquals($songs[0]->album->id, $originalSongs[0]->album->id); $this->assertEquals($songs[1]->album->name, $originalSongs[1]->album->name); $this->assertNotEquals($songs[1]->album->id, $originalSongs[1]->album->id); $this->assertEquals($songs[2]->album->name, $originalSongs[2]->album->name); $this->assertNotEquals($songs[2]->album->id, $originalSongs[2]->album->id); // And of course, the new artist is... $this->assertEquals('John Cena', $songs[0]->album->artist->name); // JOHN CENA!!! $this->assertEquals('John Cena', $songs[1]->album->artist->name); // JOHN CENA!!! $this->assertEquals('John Cena', $songs[2]->album->artist->name); // And... JOHN CENAAAAAAAAAAA!!! }