56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Tests for project term metadata.
|
|
*
|
|
* @package CHRNX
|
|
*/
|
|
|
|
/**
|
|
* Verify the project term meta contract.
|
|
*/
|
|
class ProjectMetaTest extends WP_UnitTestCase {
|
|
/**
|
|
* Register taxonomies and meta before each test.
|
|
*/
|
|
public function set_up() {
|
|
parent::set_up();
|
|
do_action( 'init' );
|
|
}
|
|
|
|
/**
|
|
* Ensure every project meta key is registered for the taxonomy.
|
|
*/
|
|
public function test_project_meta_keys_are_registered() {
|
|
$registered = get_registered_meta_keys( 'term', 'chrnx_project' );
|
|
|
|
foreach ( array_keys( chrnx_get_project_meta_definitions() ) as $meta_key ) {
|
|
$this->assertArrayHasKey( $meta_key, $registered );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Ensure a plain http repository URL is rejected.
|
|
*/
|
|
public function test_project_links_reject_insecure_urls() {
|
|
$term_id = self::factory()->term->create( array( 'taxonomy' => 'chrnx_project' ) );
|
|
update_term_meta( $term_id, 'chrnx_project_repo', 'http://example.com/repo' );
|
|
|
|
$this->assertArrayNotHasKey( 'repo', chrnx_get_project_links( $term_id ) );
|
|
}
|
|
|
|
/**
|
|
* Ensure stored https links come back keyed by their slot.
|
|
*/
|
|
public function test_project_links_return_stored_https_urls() {
|
|
$term_id = self::factory()->term->create( array( 'taxonomy' => 'chrnx_project' ) );
|
|
update_term_meta( $term_id, 'chrnx_project_repo', 'https://github.com/Expressive-Tea/green-tea' );
|
|
update_term_meta( $term_id, 'chrnx_project_package', 'https://www.npmjs.com/package/@green-tea/core' );
|
|
|
|
$links = chrnx_get_project_links( $term_id );
|
|
|
|
$this->assertSame( 'https://github.com/Expressive-Tea/green-tea', $links['repo'] );
|
|
$this->assertSame( 'https://www.npmjs.com/package/@green-tea/core', $links['package'] );
|
|
$this->assertArrayNotHasKey( 'site', $links );
|
|
}
|
|
}
|