/** * Test that when passed a department and template that the correct file path * is generated * * @since 1.0.0 * * @param null * @return null */ public function test_generate_path() { $returns_empty_cases = array('both_not_set' => array('department' => '', 'template' => ''), 'dept_not_set' => array('department' => '', 'template' => 'test'), 'template_not_set' => array('department' => 'test', 'template' => '')); $ubc_use_template_shortcode = new \UBC\Shortcode\Use_Template(); foreach ($returns_empty_cases as $name => $paths) { $returned = $ubc_use_template_shortcode->generate_path($paths['department'], $paths['template']); $empty = empty($returned); $this->assertTrue($empty, $name . ' is not empty and returned: ' . $returned); } // The root URL $path = $ubc_use_template_shortcode::$plugin_path . 'templates/'; $complex_cases = array('slashes_in_dept' => array('department' => '/dept/', 'template' => 'template', 'expected' => $path . 'dept/template.php'), 'slashes_in_template' => array('department' => 'dept', 'template' => '/template/', 'expected' => $path . 'dept/template.php'), 'slashes_in_both' => array('department' => '/dept/', 'template' => '/template/', 'expected' => $path . 'dept/template.php'), 'bad_strings_in_dept' => array('department' => ';dept;', 'template' => '/template/', 'expected' => $path . 'dept/template.php'), 'bad_strings_in_temp' => array('department' => 'dept', 'template' => ';template;', 'expected' => $path . 'dept/template.php'), 'hyphens_in_both' => array('department' => 'dept-name', 'template' => 'template-name', 'expected' => $path . 'dept-name/template-name.php'), 'dot_php_at_end' => array('department' => 'dept-name', 'template' => 'template-name.php', 'expected' => $path . 'dept-name/template-name.php')); foreach ($complex_cases as $name => $paths) { $returned = $ubc_use_template_shortcode->generate_path(sanitize_title_with_dashes($paths['department']), sanitize_title_with_dashes($paths['template'])); $this->assertEquals($paths['expected'], $returned, $name . ' is not as expected and returned ' . $returned); } }
/** * Instantiate Use_Template * * @author Richard Tape <@richardtape> * @since 1.0 * @param null * @return null */ function plugins_loaded__init_use_template() { $Use_Template = new \UBC\Shortcode\Use_Template(); $Use_Template->init(); }