<commit_before><?php
namespace App\Test\TestCase\Model\Entity;

use App\Model\Entity\Audio;
use App\Model\Entity\User;
use Cake\TestSuite\TestCase;
use Cake\Core\Configure;

class AudioTest extends TestCase
{
    public $Audio;

    public function setUp()
    {
        parent::setUp();
        $this->Audio = new Audio();
        Configure::write('Recordings.path', '/foo/bar');
    }

    public function tearDown()
    {
        unset($this->Audio);

        parent::tearDown();
    }

    public function testGet_externalSetsDefaultValues()
    {
        $this->Audio->set('external', ['username' => 'foobar']);

        $this->assertTrue(array_key_exists('license', $this->Audio->external));
    }

    public function testSet_externalIgnoresUnknownKeys()
    {
        $this->Audio->set('external', ['this_does_not_exist' => true]);

        $this->assertFalse(array_key_exists('this_does_not_exist', $this->Audio->external));
    }

    public function testSet_externalMergesExistingValues()
    {
        $this->Audio->set('external', ['username' => 'foobar']);
        $this->Audio->set('external', ['attribution_url' => 'http://example.net/']);

        $this->assertEquals('foobar', $this->Audio->external['username']);
    }

    public function testGet_externalDoesntTouchNullValues()
    {
        $this->assertNull($this->Audio->external);
    }

    public function filePathProvider() {
        // audio id, sentence id, expected audio file path
        return [
            [       1,       2, '/foo/bar/000/001/2-1.mp3'       ],
            [    1234,    5678, '/foo/bar/001/234/5678-1234.mp3' ],
            [  999999,       3, '/foo/bar/999/999/3-999999.mp3'  ],
            [ 1000000,       4, '/foo/bar/000/000/4-1000000.mp3' ],
            [ 1000001,       4, '/foo/bar/000/001/4-1000001.mp3' ],
        ];
    }

    /**
     * @dataProvider filePathProvider
     */
    public function testGet_file_path($audioId, $sentenceId, $expectedPath)
    {
        $this->Audio->id = $audioId;
        $this->Audio->sentence_id = $sentenceId;
        $this->assertEquals($expectedPath, $this->Audio->file_path);
    }

    public function testGet_attributionUrl_returnsNullWithoutProperDataSet() {
        $this->assertNull($this->Audio->attribution_url);
    }

    public function testGet_attributionUrl_fromExternal() {
        $this->Audio->external = ['attribution_url' => 'https://example.com/external'];
        $this->assertEquals('https://example.com/external', $this->Audio->attribution_url);
    }

    public function testGet_attributionUrl_fromUsername() {
        $this->Audio->external = ['attribution_url' => 'https://example.com/external'];
        $this->Audio->user = new User(['username' => 'kazuki']);
        $this->assertEquals('/user/profile/kazuki', $this->Audio->attribution_url);
    }

    public function testGet_attributionUrl_fromUserAudioAttributionUrl() {
        $this->Audio->external = ['attribution_url' => 'https://example.com/external'];
        $this->Audio->user = new User([
            'username' => 'kazuki',<commit_msg>Update unit test<commit_after><?php
namespace App\Test\TestCase\Model\Entity;

use App\Model\Entity\Audio;
use App\Model\Entity\User;
use Cake\TestSuite\TestCase;
use Cake\Core\Configure;

class AudioTest extends TestCase
{
    public $Audio;

    public function setUp()
    {
        parent::setUp();
        $this->Audio = new Audio();
        Configure::write('Recordings.path', '/foo/bar');
    }

    public function tearDown()
    {
        unset($this->Audio);

        parent::tearDown();
    }

    public function testGet_externalSetsDefaultValues()
    {
        $this->Audio->set('external', ['username' => 'foobar']);

        $this->assertTrue(array_key_exists('license', $this->Audio->external));
    }

    public function testSet_externalIgnoresUnknownKeys()
    {
        $this->Audio->set('external', ['this_does_not_exist' => true]);

        $this->assertFalse(array_key_exists('this_does_not_exist', $this->Audio->external));
    }

    public function testSet_externalMergesExistingValues()
    {
        $this->Audio->set('external', ['username' => 'foobar']);
        $this->Audio->set('external', ['attribution_url' => 'http://example.net/']);

        $this->assertEquals('foobar', $this->Audio->external['username']);
    }

    public function testGet_externalDoesntTouchNullValues()
    {
        $this->assertNull($this->Audio->external);
    }

    public function fileProvider() {
        // audio id, sentence id, expected audio file path, expected pretty filename
        return [
            [       1,       2, '/foo/bar/000/001/1.mp3',       '2-1.mp3'       ],
            [    1234,    5678, '/foo/bar/001/234/1234.mp3',    '5678-1234.mp3' ],
            [  999999,       3, '/foo/bar/999/999/999999.mp3',  '3-999999.mp3'  ],
            [ 1000000,       4, '/foo/bar/000/000/1000000.mp3', '4-1000000.mp3' ],
            [ 1000001,       4, '/foo/bar/000/001/1000001.mp3', '4-1000001.mp3' ],
        ];
    }

    /**
     * @dataProvider fileProvider
     */
    public function testGet_file($audioId, $sentenceId, $expectedPath, $expectedPrettyFilename)
    {
        $this->Audio->id = $audioId;
        $this->Audio->sentence_id = $sentenceId;
        $this->assertEquals($expectedPath, $this->Audio->file_path);
        $this->assertEquals($expectedPrettyFilename, $this->Audio->pretty_filename);
    }

    public function testGet_attributionUrl_returnsNullWithoutProperDataSet() {
        $this->assertNull($this->Audio->attribution_url);
    }

    public function testGet_attributionUrl_fromExternal() {
        $this->Audio->external = ['attribution_url' => 'https://example.com/external'];
        $this->assertEquals('https://example.com/external', $this->Audio->attribution_url);
    }

    public function testGet_attributionUrl_fromUsername() {
        $this->Audio->external = ['attribution_url' => 'https://example.com/external'];
        $this->Audio->user = new User(['username' => 'kazuki']);
        $this->assertEquals('/user/profile/kazuki', $this->Audio->attribution_url);
    }

    public function testGet_attributionUrl_fromUserAudioAttributionUrl() {
        $this->Audio->external = ['attribution_url' => 'https://example.com/external'];
        $this->Audio->user = new User([
            'username' => 'kazuki',
{'fraction_non_alphanumeric': 0.16501650165016502, 'fraction_numerical': 0.03646078893603646, 'mean_word_length': 2.842995169082126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 120, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6707861', 'n_tokens_mistral': 2124, 'n_tokens_neox': 1915, 'n_words': 286}