extractor = new StringExtractor; $this->extractor->rules = array( '__' => array('string'), ); } function test_with_just_a_string() { $expected = new Translation_Entry( array( 'singular' => 'baba', 'references' => array('baba.php:1') ) ); $result = $this->extractor->extract_from_code('', 'baba.php' ); $this->assertEquals( $expected, $result->entries['baba'] ); } function test_entry_from_call_simple() { $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('baba') ), 'baba.php' ); $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba' ) ) ); } function test_entry_from_call_nonexisting_function() { $entry = $this->extractor->entry_from_call( array( 'name' => 'f', 'args' => array('baba') ), 'baba.php' ); $this->assertEquals( $entry, null ); } function test_entry_from_call_too_few_args() { $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array() ), 'baba.php' ); $this->assertEquals( $entry, null ); } function test_entry_from_call_non_expected_null_arg() { $this->extractor->rules = array( '_nx' => array( 'singular', 'plural', 'context' ) ); $entry = $this->extractor->entry_from_call( array( 'name' => '_nx', 'args' => array('%s baba', null, 'noun') ), 'baba.php' ); $this->assertEquals( $entry, null ); } function test_entry_from_call_more_args_should_be_ok() { $this->extractor->rules = array( '__' => array('string') ); $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('baba', 5, 'pijo', null) ), 'baba.php' ); $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba' ) ) ); } function test_entry_from_call_context() { $this->extractor->rules = array( '_x' => array( 'string', 'context' ) ); $entry = $this->extractor->entry_from_call( array( 'name' => '_x', 'args' => array('baba', 'noun') ), 'baba.php' ); $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba', 'context' => 'noun' ) ) ); } function test_entry_from_call_plural() { $this->extractor->rules = array( '_n' => array( 'singular', 'plural' ) ); $entry = $this->extractor->entry_from_call( array( 'name' => '_n', 'args' => array('%s baba', '%s babas') ), 'baba.php' ); $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => '%s baba', 'plural' => '%s babas' ) ) ); } function test_entry_from_call_plural_and_context() { $this->extractor->rules = array( '_nx' => array( 'singular', 'plural', 'context' ) ); $entry = $this->extractor->entry_from_call( array( 'name' => '_nx', 'args' => array('%s baba', '%s babas', 'noun') ), 'baba.php' ); $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => '%s baba', 'plural' => '%s babas', 'context' => 'noun' ) ) ); } function test_entry_from_call_extracted_comment() { $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('baba'), 'comment' => 'translators: give me back my pants!' ), 'baba.php' ); $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba', 'extracted_comments' => "translators: give me back my pants!\n" ) ) ); } function test_entry_from_call_line_number() { $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('baba'), 'line' => 10 ), 'baba.php' ); $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba', 'references' => array('baba.php:10') ) ) ); } function test_entry_from_call_zero() { $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('0') ), 'baba.php' ); $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => '0' ) ) ); } function test_entry_from_call_multiple() { $this->extractor->rules = array( 'c' => array( 'string', 'singular', 'plural' ) ); $entries = $this->extractor->entry_from_call( array( 'name' => 'c', 'args' => array('baba', 'dyado', 'dyados') ), 'baba.php' ); $this->assertEquals( array( new Translation_Entry( array( 'singular' => 'baba' ) ), new Translation_Entry( array( 'singular' => 'dyado', 'plural' => 'dyados' ) ) ), $entries ); } function test_entry_from_call_multiple_first_plural_then_two_strings() { $this->extractor->rules = array( 'c' => array( 'singular', 'plural', null, 'string', 'string' ) ); $entries = $this->extractor->entry_from_call( array( 'name' => 'c', 'args' => array('dyado', 'dyados', 'baba', 'foo', 'bar') ), 'baba.php' ); $this->assertEquals( array( new Translation_Entry( array( 'singular' => 'dyado', 'plural' => 'dyados' ) ), new Translation_Entry( array( 'singular' => 'foo' ) ), new Translation_Entry( array( 'singular' => 'bar' ) ) ), $entries ); } function test_find_function_calls_one_arg_literal() { $this->assertEquals( array( array( 'name' => '__', 'args' => array( 'baba' ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('__'), '' ) ); } function test_find_function_calls_one_arg_zero() { $this->assertEquals( array( array( 'name' => '__', 'args' => array( '0' ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('__'), '' ) ); } function test_find_function_calls_one_arg_non_literal() { $this->assertEquals( array( array( 'name' => '__', 'args' => array( null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('__'), '' ) ); } function test_find_function_calls_shouldnt_be_mistaken_by_a_class() { $this->assertEquals( array(), $this->extractor->find_function_calls( array('__'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( null, "baba" ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( null, "baba", null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( "baba", null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( null, "baba" ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ), $this->extractor->find_function_calls( array('f'), 'assertEquals( array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'Translators: let your ears fly!' ) ), $this->extractor->find_function_calls( array('f'), '