Skip to content

Commit

Permalink
feat(constants): support PHP constants as textdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
felixzapata committed Aug 12, 2017
1 parent fb99345 commit df91dfa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/fixtures/correct-domain-constant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
__( 'Hello World', MY_CUSTOM_CONSTANT );
_x( 'Post', 'verb', MY_CUSTOM_CONSTANT );
_e( 'Hello World', MY_CUSTOM_CONSTANT );
_ex( 'Post', 'verb', MY_CUSTOM_CONSTANT );


esc_html__( 'Hello World', MY_CUSTOM_CONSTANT );
esc_html_e( 'Hello World', MY_CUSTOM_CONSTANT );
esc_html_x( 'Post', 'verb', MY_CUSTOM_CONSTANT );


esc_attr__( 'Hello World', MY_CUSTOM_CONSTANT );
esc_attr_e( 'Hello World', MY_CUSTOM_CONSTANT );
esc_attr_x( 'Post', 'verb', MY_CUSTOM_CONSTANT );


$apples = 4;
_n( '%d apple', '%d apples', $apples, MY_CUSTOM_CONSTANT );
_nx( '%d post', '%d posts', $apples, 'noun, job positions', MY_CUSTOM_CONSTANT );


_n_noop( '%d apple', '%d apples', MY_CUSTOM_CONSTANT );
_nx_noop( '%d post', '%d posts', 'noun, job positions', MY_CUSTOM_CONSTANT );
?>
25 changes: 25 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,30 @@ describe('gulp-checktextdomain', function() {
});
});

it('10) Should review that the domain (set as a constant) is ok', function(done) {
var actual;
var corrected;
var expected;
var options = {
force: true,
text_domain: 'MY_CUSTOM_CONSTANT',
create_report_file: true,
keywords: keywords
};

gulp.src(fixtures('correct-domain-constant.php'))
.pipe(checktextdomain(options))
.pipe(sassert.first(function(d) {
//File is correct, should report no errors
actual = JSON.parse(fs.readFileSync('.correct-domain-constant.json'));
actual[path.join(__dirname, 'temp/correct-domain-constant.php')].length.should.equal(0);

//Clean up: Delete report file
fs.remove('.correct-domain-constant.json');
}))
.pipe(sassert.end(done));

});


});

0 comments on commit df91dfa

Please sign in to comment.