Skip to content

Commit

Permalink
Refactoring tests (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
carusogabriel authored and rhukster committed Jan 19, 2018
1 parent 9d2dea0 commit f261173
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 123 deletions.
74 changes: 37 additions & 37 deletions tests/unit/Grav/Common/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ public function testAddInlineJs()

public function testGetCollections()
{
$this->assertTrue(is_array($this->assets->getCollections()));
$this->assertTrue(in_array('jquery', array_keys($this->assets->getCollections())));
$this->assertTrue(in_array('system://assets/jquery/jquery-2.x.min.js', $this->assets->getCollections()));
$this->assertInternalType('array', $this->assets->getCollections());
$this->assertContains('jquery', array_keys($this->assets->getCollections()));
$this->assertContains('system://assets/jquery/jquery-2.x.min.js', $this->assets->getCollections());
}

public function testExists()
Expand All @@ -492,107 +492,107 @@ public function testRegisterCollection()
{
$this->assets->registerCollection('debugger', ['/system/assets/debugger.css']);
$this->assertTrue($this->assets->exists('debugger'));
$this->assertTrue(in_array('debugger', array_keys($this->assets->getCollections())));
$this->assertContains('debugger', array_keys($this->assets->getCollections()));
}

public function testReset()
{
$this->assets->addInlineJs('alert("test")');
$this->assets->reset();
$this->assertTrue(count($this->assets->js()) == 0);
$this->assertSame(0, count($this->assets->js()));

$this->assets->addAsyncJs('jquery');
$this->assets->reset();

$this->assertTrue(count($this->assets->js()) == 0);
$this->assertSame(0, count($this->assets->js()));

$this->assets->addInlineCss('body { color: black }');
$this->assets->reset();

$this->assertTrue(count($this->assets->css()) == 0);
$this->assertSame(0, count($this->assets->css()));

$this->assets->add('/system/assets/debugger.css', null, true);
$this->assets->reset();

$this->assertTrue(count($this->assets->css()) == 0);
$this->assertSame(0, count($this->assets->css()));
}

public function testResetJs()
{
$this->assets->addInlineJs('alert("test")');
$this->assets->resetJs();
$this->assertTrue(count($this->assets->js()) == 0);
$this->assertSame(0, count($this->assets->js()));

$this->assets->addAsyncJs('jquery');
$this->assets->resetJs();

$this->assertTrue(count($this->assets->js()) == 0);
$this->assertSame(0, count($this->assets->js()));
}

public function testResetCss()
{
$this->assertTrue(count($this->assets->js()) == 0);
$this->assertSame(0, count($this->assets->js()));

$this->assets->addInlineCss('body { color: black }');
$this->assets->resetCss();

$this->assertTrue(count($this->assets->css()) == 0);
$this->assertSame(0, count($this->assets->css()));

$this->assets->add('/system/assets/debugger.css', null, true);
$this->assets->resetCss();

$this->assertTrue(count($this->assets->css()) == 0);
$this->assertSame(0, count($this->assets->css()));
}

public function testAddDirCss()
{
$this->assets->addDirCss('/system');

$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) > 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) == 0);
$this->assertInternalType('array', $this->assets->getCss());
$this->assertGreaterThan(0, $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertCount(0, $this->assets->getJs());

$this->assets->reset();
$this->assets->addDirCss('/system/assets');

$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) > 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) == 0);
$this->assertInternalType('array', $this->assets->getCss());
$this->assertGreaterThan(0, $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertCount(0, $this->assets->getJs());

$this->assets->reset();
$this->assets->addDirJs('/system');

$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) == 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) > 0);
$this->assertInternalType('array', $this->assets->getCss());
$this->assertCount(0, $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertGreaterThan(0, $this->assets->getJs());

$this->assets->reset();
$this->assets->addDirJs('/system/assets');

$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) == 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) > 0);
$this->assertInternalType('array', $this->assets->getCss());
$this->assertCount(0, $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertGreaterThan(0, $this->assets->getJs());

$this->assets->reset();
$this->assets->addDir('/system/assets');

$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) > 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) > 0);
$this->assertInternalType('array', $this->assets->getCss());
$this->assertGreaterThan(0, $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertGreaterThan(0, $this->assets->getJs());

//Use streams
$this->assets->reset();
$this->assets->addDir('system://assets');

$this->assertTrue(is_array($this->assets->getCss()));
$this->assertTrue(count($this->assets->getCss()) > 0);
$this->assertTrue(is_array($this->assets->getJs()));
$this->assertTrue(count($this->assets->getJs()) > 0);
$this->assertInternalType('array', $this->assets->getCss());
$this->assertGreaterThan(0, $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs());
$this->assertGreaterThan(0, $this->assets->getJs());

}
}
13 changes: 6 additions & 7 deletions tests/unit/Grav/Common/ComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ protected function _after()
public function testGetComposerLocation()
{
$composerLocation = Composer::getComposerLocation();
$this->assertTrue(is_string($composerLocation));
$this->assertTrue($composerLocation[0] == '/');
$this->assertInternalType('string', $composerLocation);
$this->assertSame('/', $composerLocation[0]);
}

public function testGetComposerExecutor()
{
$composerExecutor = Composer::getComposerExecutor();
$this->assertTrue(is_string($composerExecutor));
$this->assertTrue($composerExecutor[0] == '/');
$this->assertTrue(strstr($composerExecutor, 'php') !== null);
$this->assertTrue(strstr($composerExecutor, 'composer') !== null);
$this->assertInternalType('string', $composerExecutor);
$this->assertSame('/', $composerExecutor[0]);
$this->assertNotNull(strstr($composerExecutor, 'php'));
$this->assertNotNull(strstr($composerExecutor, 'composer'));
}

}

46 changes: 23 additions & 23 deletions tests/unit/Grav/Common/GPM/GPMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@ public function testCalculateMergedDependenciesOfPackages()

$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);

$this->assertTrue(is_array($dependencies));
$this->assertSame(5, count($dependencies));
$this->assertInternalType('array', $dependencies);
$this->assertCount(5, $dependencies);

$this->assertTrue($dependencies['grav'] == '>=1.0.10');
$this->assertTrue(isset($dependencies['errors']));
$this->assertTrue(isset($dependencies['problems']));
$this->assertSame('>=1.0.10', $dependencies['grav']);
$this->assertArrayHasKey('errors', $dependencies);
$this->assertArrayHasKey('problems', $dependencies);

//////////////////////////////////////////////////////////////////////////////////////////
// Second working example
//////////////////////////////////////////////////////////////////////////////////////////
$packages = ['admin', 'form'];

$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertTrue(is_array($dependencies));
$this->assertSame(5, count($dependencies));
$this->assertTrue($dependencies['errors'] == '>=3.2');
$this->assertInternalType('array', $dependencies);
$this->assertCount(5, $dependencies);
$this->assertSame('>=3.2', $dependencies['errors']);

//////////////////////////////////////////////////////////////////////////////////////////
// Third working example
Expand Down Expand Up @@ -124,9 +124,9 @@ public function testCalculateMergedDependenciesOfPackages()


$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertTrue(is_array($dependencies));
$this->assertSame(1, count($dependencies));
$this->assertTrue($dependencies['errors'] == '>=4.0');
$this->assertInternalType('array', $dependencies);
$this->assertCount(1, $dependencies);
$this->assertSame('>=4.0', $dependencies['errors']);



Expand Down Expand Up @@ -161,10 +161,10 @@ public function testCalculateMergedDependenciesOfPackages()


$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertTrue($dependencies['package1'] == '>=4.0.0-rc2');
$this->assertTrue($dependencies['package2'] == '>=3.2.0-beta.11');
$this->assertTrue($dependencies['package3'] == '>=3.2.0-alpha.2');
$this->assertTrue($dependencies['package4'] == '>=3.2.0');
$this->assertSame('>=4.0.0-rc2', $dependencies['package1']);
$this->assertSame('>=3.2.0-beta.11', $dependencies['package2']);
$this->assertSame('>=3.2.0-alpha.2', $dependencies['package3']);
$this->assertSame('>=3.2.0', $dependencies['package4']);


//////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -253,14 +253,14 @@ public function testCalculateMergedDependenciesOfPackages()

$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);

$this->assertTrue(is_array($dependencies));
$this->assertSame(7, count($dependencies));
$this->assertInternalType('array', $dependencies);
$this->assertCount(7, $dependencies);

$this->assertSame('>=1.0.10', $dependencies['grav']);
$this->assertTrue(isset($dependencies['errors']));
$this->assertTrue(isset($dependencies['problems']));
$this->assertTrue(isset($dependencies['antimatter']));
$this->assertTrue(isset($dependencies['something']));
$this->assertArrayHasKey('errors', $dependencies);
$this->assertArrayHasKey('problems', $dependencies);
$this->assertArrayHasKey('antimatter', $dependencies);
$this->assertArrayHasKey('something', $dependencies);
$this->assertSame('>=3.2', $dependencies['something']);
}

Expand Down Expand Up @@ -316,8 +316,8 @@ public function testCalculateVersionNumberFromDependencyVersion()
$this->assertSame('2.0.2', $this->gpm->calculateVersionNumberFromDependencyVersion('>=2.0.2'));
$this->assertSame('2.0.2', $this->gpm->calculateVersionNumberFromDependencyVersion('~2.0.2'));
$this->assertSame('1', $this->gpm->calculateVersionNumberFromDependencyVersion('~1'));
$this->assertSame(null, $this->gpm->calculateVersionNumberFromDependencyVersion(''));
$this->assertSame(null, $this->gpm->calculateVersionNumberFromDependencyVersion('*'));
$this->assertNull($this->gpm->calculateVersionNumberFromDependencyVersion(''));
$this->assertNull($this->gpm->calculateVersionNumberFromDependencyVersion('*'));
$this->assertSame('2.0.2', $this->gpm->calculateVersionNumberFromDependencyVersion('2.0.2'));
}
}
Loading

0 comments on commit f261173

Please sign in to comment.