Skip to content

Commit

Permalink
Begin testing asset copy functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Oct 29, 2014
1 parent e793153 commit 3d7e95a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ClientSide/FileOrganiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public function checkAssetValid() {
}

/**
*
* Copies the source asset directory to the www directory and stores a
* fingerprint of the source directory in a separate public file, for use in
* checkAssetValid().
*/
public function copyAsset() {
$copyCount = 0;
Expand Down
39 changes: 39 additions & 0 deletions test/Unit/ClientSide/Compiler.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Client side compilation is handled by third party libraries that must have
* full test-suites associated. This test case is intended to test how PHP.Gt
* interfaces with these libraries, rather than the functionality of the
* libraries themselves.
*
* PHP.Gt (http://php.gt)
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com)
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses
*/
namespace Gt\ClientSide;

use \scssc as ScssParser;

class Compiler_Test extends \PHPUnit_Framework_TestCase {

private $tmp;

public function setUp() {
$this->tmp = \Gt\Test\Helper::createTmpDir();
}

public function tearDown() {
\Gt\Test\Helper::cleanup($this->tmp);
}

public function testCompilesScss() {
$filePath = $this->tmp . "/file.scss";
$source = '$red: rgb(225, 16, 32); a { color: $red; }';
file_put_contents($filePath, $source);
// Regular expressions used to ignore white space.
$output = preg_replace("/\s/", "", Compiler::parse($filePath));
$expected = preg_replace("/\s/", "", "a { color: #e11020;}");

$this->assertEquals($expected, $output);
}

}#
45 changes: 44 additions & 1 deletion test/Unit/ClientSide/FileOrganiser.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,56 @@ public function textAssetInvalidWithEmptyWWW() {
$this->assertFalse($this->fileOrganiser->checkAssetValid());
}

public function testAssetInvalidates() {
public function testAssetInvalidatesFromEmpty() {
$dir = $this->getPath(Path::ASSET);
file_put_contents("$dir/file.txt", "dummy data");

$this->assertFalse($this->fileOrganiser->checkAssetValid());
}

public function testAssetCopies() {
$dir = $this->getPath(Path::ASSET);
$fileArray = [
"text-file.txt",
"picture.jpg",
"directory/markdown-file.md",
"directory/another-text-file.txt",
];
foreach ($fileArray as $file) {
$filePath = "$dir/$file";
if(!is_dir(dirname($filePath))) {
mkdir(dirname($filePath), 0775, true);
}

file_put_contents($filePath, uniqid() . "\n$file\n" . uniqid() );
}

$copyCount = $this->fileOrganiser->copyAsset();
$this->assertEquals(count($fileArray), $copyCount);

$this->assertFileExists(Path::get(Path::WWW) . "/asset-fingerprint");

// Check contents of copied files.
$wwwAssetDir = Path::get(Path::WWW) . "/Asset";
foreach ($fileArray as $file) {
$wwwFilePath = "$wwwAssetDir/$file";
$filePath = "$dir/$file";
$wwwFileContents = file_get_contents($wwwFilePath);
$sourceFileContents = file_get_contents($filePath);

$this->assertEquals($sourceFileContents, $wwwFileContents,
"www asset file should have the same contents as the source file");
}
}

public function testAssetValidAfterCopy() {

}

public function testAssetInvalidatesAfterCopy() {

}

public function testOrganiserMinifies() {
$dir = $this->getPath(Path::SCRIPT);
$publicDir = substr($dir, strlen(Path::get(Path::SRC)));
Expand Down

0 comments on commit 3d7e95a

Please sign in to comment.