Skip to content

Commit

Permalink
BIGINT(10) for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Sep 27, 2016
1 parent 947a78c commit 9b078ce
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
5 changes: 4 additions & 1 deletion plugins/CustomPiwikJs/File.php
Expand Up @@ -60,7 +60,10 @@ public function getName()
*/
public function hasWriteAccess()
{
return $this->hasReadAccess() && is_writable($this->file);
if(file_exists($this->file) && !is_writable($this->file)) {
return false;
}
return is_writable(dirname($this->file)) || is_writable($this->file);
}

/**
Expand Down
61 changes: 52 additions & 9 deletions plugins/CustomPiwikJs/tests/Integration/FileTest.php
Expand Up @@ -19,7 +19,8 @@
*/
class FileTest extends IntegrationTestCase
{
const NOT_EXISTING_FILE = 'notExisTinGFile.js';
const NOT_EXISTING_FILE_IN_WRITABLE_DIRECTORY = 'notExisTinGFile.js';
const NOT_EXISTING_FILE_IN_NON_WRITABLE_DIRECTORY = 'is-not-writable/notExisTinGFile.js';

/**
* @var string
Expand All @@ -30,14 +31,23 @@ public function setUp()
{
parent::setUp();
$this->dir = PIWIK_DOCUMENT_ROOT . '/plugins/CustomPiwikJs/tests/resources/';

// make directory not writable
$nonWritableDir = dirname($this->dir . self::NOT_EXISTING_FILE_IN_NON_WRITABLE_DIRECTORY);
@chmod($nonWritableDir, 0444);
if(is_writable($nonWritableDir)) {
throw new \Exception("The directory $nonWritableDir should have been made non writable by this test, but it didn't work");
}
}

public function tearDown()
{
if (file_exists($this->dir . self::NOT_EXISTING_FILE)) {
unlink($this->dir . self::NOT_EXISTING_FILE);
}
// restore permissions changed by makeNotWritableFile()
chmod($this->dir, 0777);

if (file_exists($this->dir . self::NOT_EXISTING_FILE_IN_WRITABLE_DIRECTORY)) {
unlink($this->dir . self::NOT_EXISTING_FILE_IN_WRITABLE_DIRECTORY);
}
parent::tearDown();
}

Expand All @@ -46,9 +56,31 @@ private function makeFile($fileName = 'test.js')
return new File($this->dir . $fileName);
}

private function makeNotWritableFile()
{
$path = $this->dir . 'file-made-non-writable.js';
chmod($path, 0777);
$file = new File($path);
$file->save('will be saved OK, and then we make it non writable.');

chmod($path, 0444);
chmod($this->dir, 0444);
return $file;
}

private function makeNotReadableFile()
{
return $this->makeFile(self::NOT_EXISTING_FILE);
return $this->makeNotReadableFile_inWritableDirectory();
}

private function makeNotReadableFile_inNonWritableDirectory()
{
return $this->makeFile(self::NOT_EXISTING_FILE_IN_NON_WRITABLE_DIRECTORY);
}

private function makeNotReadableFile_inWritableDirectory()
{
return $this->makeFile(self::NOT_EXISTING_FILE_IN_WRITABLE_DIRECTORY);
}

public function test_getName()
Expand All @@ -66,7 +98,13 @@ public function test_hasReadAccess()
public function test_hasWriteAccess()
{
$this->assertTrue($this->makeFile()->hasWriteAccess());
$this->assertFalse($this->makeNotReadableFile()->hasWriteAccess());
$this->assertTrue($this->makeNotReadableFile_inWritableDirectory()->hasWriteAccess());
$this->assertFalse($this->makeNotReadableFile_inNonWritableDirectory()->hasWriteAccess());
}

public function test_hasWriteAccess_whenFileExistAndIsNotWritable()
{
$this->assertFalse($this->makeNotWritableFile()->hasWriteAccess());
}

public function test_checkReadable_shouldNotThrowException_IfIsReadable()
Expand Down Expand Up @@ -96,7 +134,12 @@ public function test_checkReadable_shouldThrowException_IfNotIsReadable()
*/
public function test_checkWritable_shouldThrowException_IfNotIsWritable()
{
$this->makeNotReadableFile()->checkWritable();
$this->makeNotReadableFile_inNonWritableDirectory()->checkWritable();
}

public function test_checkWritable_shouldNotThrowException_IfDirectoryIsWritable()
{
$this->makeNotReadableFile_inWritableDirectory()->checkWritable();
}

public function test_getContent()
Expand All @@ -111,9 +154,9 @@ public function test_getContent_returnsNull_IfFileIsNotReadableOrNotExists()

public function test_save()
{
$notExistingFile = $this->makeNotReadableFile();
$notExistingFile = $this->makeNotReadableFile_inWritableDirectory();
$this->assertFalse($notExistingFile->hasReadAccess());
$this->assertFalse($notExistingFile->hasWriteAccess());
$this->assertTrue($notExistingFile->hasWriteAccess());

$notExistingFile->save('myTestContent');

Expand Down
Expand Up @@ -62,7 +62,13 @@ public function test_checkWillSucceed_shouldNotThrowExceptionIfPiwikJsTargetIsWr
* @expectedException \Piwik\Plugins\CustomPiwikJs\Exception\AccessDeniedException
* @expectedExceptionMessage not writable
*/
public function test_checkWillSucceed_shouldThrowExceptionIfTargetIsNotWritable()
public function test_checkWillSucceed_shouldNotThrowExceptionIfTargetIsNotWritable()
{
$updater = $this->makeUpdater(null, $this->dir . 'not-writable/MyNotExisIngFilessss.js');
$updater->checkWillSucceed();
}

public function test_checkWillSucceed_shouldNotThrowExceptionIfTargetIsWritable()
{
$updater = $this->makeUpdater(null, $this->dir . 'MyNotExisIngFilessss.js');
$updater->checkWillSucceed();
Expand Down
2 changes: 0 additions & 2 deletions tests/javascript/index.php
Expand Up @@ -28,8 +28,6 @@
$sourceFile = PIWIK_DOCUMENT_ROOT . TrackerUpdater::DEVELOPMENT_PIWIK_JS;
$targetFile = PIWIK_DOCUMENT_ROOT . $targetFileName;

file_put_contents($targetFile, '');

$updater = new TrackerUpdater($sourceFile, $targetFile);
$updater->setTrackerFiles(new JsTestPluginTrackerFiles());
$updater->checkWillSucceed();
Expand Down

0 comments on commit 9b078ce

Please sign in to comment.