function testTransformDateString()
 {
     $valid_string = "Y-m-d";
     $valid_transform = array("Y" => "YYYY", "m" => "MM", "d" => "DD");
     foreach (array(array($valid_string, null, false), array(null, $valid_transform, false), array($valid_string, array("Y"), false), array($valid_string, array("Y" => "YYYY"), false), array($valid_string, $valid_transform, "YYYY-MM-DD"), array('\\Y', $valid_transform, "Y")) as $test) {
         list($string, $replacements, $result) = $test;
         $transform_result = cpm_transform_date_string($string, $replacements);
         if (empty($transform_result)) {
             $this->assertTrue($transform_result === false);
         } else {
             $this->assertEqual($result, $transform_result);
         }
     }
 }
/**
 * Breakdown the name of a comic file into a date and proper title.
 */
function cpm_breakdown_comic_filename($filename, $allow_override = false)
{
    $pattern = CPM_DATE_FORMAT;
    if ($allow_override !== false) {
        if (is_string($allow_override)) {
            $pattern = $allow_override;
        } else {
            if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) {
                $pattern = $_POST['upload-date-format'];
            }
        }
    }
    foreach (array('[0-9]{4}', '[0-9]{2}') as $year_pattern) {
        $new_pattern = cpm_transform_date_string($pattern, array("Y" => $year_pattern, "m" => '[0-9]{2}', "d" => '[0-9]{2}'));
        if (@preg_match("#^({$new_pattern})(.*)\\.[^\\.]+\$#", $filename, $matches) > 0) {
            list($all, $date, $title) = $matches;
            if (strtotime($date) === false) {
                return false;
            }
            $converted_title = ucwords(trim(preg_replace('/[\\-\\_]/', ' ', $title)));
            $date = date($pattern, strtotime($date));
            if (is_numeric($converted_title)) {
                $converted_title = "Title: {$converted_title}";
            }
            return compact('date', 'title', 'converted_title');
        }
    }
    return false;
}