Exemple #1
0
 /**
  * Construct a new WPTheme object
  *
  * @param string $path The path to the root folder of the theme
  */
 public function __construct($path)
 {
     $this->path = WPRequire::THEMES_DIR() . "/" . $path;
     $themeObject = wp_get_theme($this->path . "/style.css", $this->path);
     // Extract the theme data into an assosiativ array
     $this->themeData = array("Name" => $themeObject->get("Name"), "ThemeURI" => $themeObject->get("ThemeURI"), "Description" => $themeObject->get("Description"), "Author" => $themeObject->get("Author"), "AuthorURI" => $themeObject->get("AuthorURI"), "Version" => $themeObject->get("Version"), "Template" => $themeObject->get("Template"), "Status" => $themeObject->get("Status"), "Tags" => $themeObject->get("Tags"), "TextDomain" => $themeObject->get("TextDomain"), "DomainPath" => $themeObject->get("DomainPath"));
     if (isset($this->themeData['version'])) {
         $this->version = new Version($this->themeData['version']);
     } else {
         // Null if none is spesified
         $this->version = null;
     }
     parent::__construct();
 }
 /**
  * Create a mock theme that is deleted
  * when the tests are done running 
  * with a wp-require file
  * with the contents of $require.
  *
  * @param array $requires The desired contents of the wp-require file.
  *
  * @return WPTheme The theme
  */
 public static function createMockTheme($requires)
 {
     $baseThemesDir = WPRequire::THEMES_DIR();
     // Create a random name
     $themeName = Str::random(20);
     // Create the plugin directory
     $themeDir = new File($baseThemesDir . "/{$themeName}");
     $themeDir->createDir();
     // Create the base plugin file
     $styleCss = new File($themeDir->getPath() . "/style.css");
     $styleCss->createFile();
     // Write plugin name and version to the plugin header
     $styleCssWriter = new FileWriter($styleCss);
     $styleCssWriter->open();
     $styleCssWriter->write("\n/*\n * Theme Name: {$themeName}\n * Version: 1.0.0\n */");
     $styleCssWriter->close();
     // Create the wp-require.json file
     $wpRequireFile = new File($themeDir->getPath() . "/wp-require.json");
     $wpRequireFile->createFile();
     $wpRequireFileWriter = new FileWriter($wpRequireFile);
     // Write the array as json to the wp-require.json file
     $wpRequireFileWriter->open();
     $wpRequireFileWriter->write((string) new Json($requires));
     $wpRequireFileWriter->close();
     // Request files to be deleted on tearDown
     $styleCss->deleteOnExit();
     $wpRequireFile->deleteOnExit();
     $themeDir->deleteOnExit();
     $theme = new WPTheme("{$themeName}");
     return $theme;
 }