Skip to content

Commit

Permalink
Merge pull request phalcon#14848 from les-enovateurs/update_assets_co…
Browse files Browse the repository at this point in the history
…llection

phalcon#13655 - Assets/Collection - Tests finished. Thank you @jenovateurs
  • Loading branch information
ruudboon authored Feb 15, 2020
2 parents 2289774 + 708788a commit 8d90816
Show file tree
Hide file tree
Showing 52 changed files with 754 additions and 840 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fixed `Phalcon\Db\Dialect\Mysql::createTable()` to create default value with CURRENT_TIMESTAMP ON UPDATE/DELETE [#14797]
- Fixed `Phalcon\Storage\Adapter\*` to no longer accept the `serializer` option as it was clashing with the factory [#14828](https://github.com/phalcon/cphalcon/pull/14828)
- Fixed `Phalcon\Http\Request` to return the correct host on an `UnexpectedValueException` [#14763](https://github.com/phalcon/cphalcon/issues/14763)
- Fixed `Phalcon\Assets\Collection` to initialize `position` to 0 [#14848](https://github.com/phalcon/cphalcon/pull/14848)

# [4.0.3](https://github.com/phalcon/cphalcon/releases/tag/v4.0.3) (2020-01-25)
## Added
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Assets/Collection.zep
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Collection implements Countable, Iterator
/**
* @var int
*/
protected position { get };
protected position = 0 { get };

/**
* @var string
Expand Down
24 changes: 21 additions & 3 deletions tests/unit/Assets/Collection/AddCssCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,38 @@

namespace Phalcon\Test\Unit\Assets\Collection;

use Phalcon\Assets\Collection;
use UnitTester;

class AddCssCest
{
/**
* Tests Phalcon\Assets\Collection :: addCss()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*/
public function assetsCollectionAddCss(UnitTester $I)
{
$I->wantToTest('Assets\Collection - addCss()');

$I->skipTest('Need implementation');
$collection = new Collection();

$collection->addCss(
'css/docs.css'
);

$collection->addCss(
'https://assets.phalcon.io/phalcon/css/core.css'
);

foreach ($collection as $asset) {
$I->assertEquals(
'css',
$asset->getType()
);
}

$I->assertCount(2, $collection);
}
}
27 changes: 24 additions & 3 deletions tests/unit/Assets/Collection/AddFilterCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,41 @@

namespace Phalcon\Test\Unit\Assets\Collection;

use Phalcon\Assets\Collection;
use Phalcon\Assets\Filters\None;
use UnitTester;

class AddFilterCest
{
/**
* Tests Phalcon\Assets\Collection :: addFilter()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*/
public function assetsCollectionAddFilter(UnitTester $I)
{
$I->wantToTest('Assets\Collection - addFilter()');

$I->skipTest('Need implementation');
$collection = new Collection();

$collection->addFilter(
new None()
);

$collection->addFilter(
new None()
);

$filters = $collection->getFilters();

foreach ($filters as $filter) {
$I->assertInstanceOf(
None::class,
$filter
);
}

$I->assertCount(2, $filters);
}
}
23 changes: 20 additions & 3 deletions tests/unit/Assets/Collection/AddInlineCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,37 @@

namespace Phalcon\Test\Unit\Assets\Collection;

use Phalcon\Assets\Collection;
use Phalcon\Assets\Inline;
use UnitTester;

class AddInlineCest
{
/**
* Tests Phalcon\Assets\Collection :: addInline()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*/
public function assetsCollectionAddInline(UnitTester $I)
{
$I->wantToTest('Assets\Collection - addInline()');

$I->skipTest('Need implementation');
$collection = new Collection();

$inline = new Inline("js", "alert('an amazing test');");

$collection->addInline(
$inline
);

$codes = $collection->getCodes();

$I->assertCount(1, $collection->getCodes());

$I->assertEquals(
end($codes),
$inline
);
}
}
23 changes: 20 additions & 3 deletions tests/unit/Assets/Collection/AddInlineCssCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,37 @@

namespace Phalcon\Test\Unit\Assets\Collection;

use Phalcon\Assets\Collection;
use Phalcon\Assets\Inline\Css;
use UnitTester;

class AddInlineCssCest
{
/**
* Tests Phalcon\Assets\Collection :: addInlineCss()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*/
public function assetsCollectionAddInlineCss(UnitTester $I)
{
$I->wantToTest('Assets\Collection - addInlineCss()');

$I->skipTest('Need implementation');
$collection = new Collection();

$inline = new Css(".awesome{color: #8fc6bc}");

$collection->addInline(
$inline
);

$codes = $collection->getCodes();

$I->assertCount(1, $collection->getCodes());

$I->assertEquals(
end($codes),
$inline
);
}
}
23 changes: 20 additions & 3 deletions tests/unit/Assets/Collection/AddInlineJsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,37 @@

namespace Phalcon\Test\Unit\Assets\Collection;

use Phalcon\Assets\Collection;
use Phalcon\Assets\Inline\Js;
use UnitTester;

class AddInlineJsCest
{
/**
* Tests Phalcon\Assets\Collection :: addInlineJs()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*/
public function assetsCollectionAddInlineJs(UnitTester $I)
{
$I->wantToTest('Assets\Collection - addInlineJs()');

$I->skipTest('Need implementation');
$collection = new Collection();

$inline = new Js("alert('an amazing test');");

$collection->addInline(
$inline
);

$codes = $collection->getCodes();

$I->assertCount(1, $collection->getCodes());

$I->assertEquals(
end($codes),
$inline
);
}
}
24 changes: 21 additions & 3 deletions tests/unit/Assets/Collection/AddJsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,38 @@

namespace Phalcon\Test\Unit\Assets\Collection;

use Phalcon\Assets\Collection;
use UnitTester;

class AddJsCest
{
/**
* Tests Phalcon\Assets\Collection :: addJs()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*/
public function assetsCollectionAddJs(UnitTester $I)
{
$I->wantToTest('Assets\Collection - addJs()');

$I->skipTest('Need implementation');
$collection = new Collection();

$collection->addJs(
'js/jquery.css'
);

$collection->addJs(
'https://assets.phalcon.io/phalcon/js/core.js'
);

foreach ($collection as $asset) {
$I->assertEquals(
'js',
$asset->getType()
);
}

$I->assertCount(2, $collection);
}
}
28 changes: 25 additions & 3 deletions tests/unit/Assets/Collection/CountCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,42 @@

namespace Phalcon\Test\Unit\Assets\Collection;

use Phalcon\Assets\Collection;
use UnitTester;

class CountCest
{
/**
* Tests Phalcon\Assets\Collection :: count()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*/
public function assetsCollectionCount(UnitTester $I)
{
$I->wantToTest('Assets\Collection - count()');

$I->skipTest('Need implementation');
$collection = new Collection();

$collection->addCss(
'css/docs.css'
);

$collection->addCss(
'https://assets.phalcon.io/phalcon/css/core.css'
);

$collection->addJs(
'js/jquery.css'
);

$collection->addJs(
'https://assets.phalcon.io/phalcon/js/core.js'
);

$I->assertEquals(
4,
$collection->count()
);
}
}
27 changes: 24 additions & 3 deletions tests/unit/Assets/Collection/CurrentCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,41 @@

namespace Phalcon\Test\Unit\Assets\Collection;

use Phalcon\Assets\Asset;
use Phalcon\Assets\Collection;
use UnitTester;

class CurrentCest
{
/**
* Tests Phalcon\Assets\Collection :: current()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*/
public function assetsCollectionCurrent(UnitTester $I)
{
$I->wantToTest('Assets\Collection - current()');

$I->skipTest('Need implementation');
$collection = new Collection();

$asset = new Asset('js', 'js/jquery.js');

$collection->add(
$asset
);

$asset1 = new Asset('js', 'js/jquery-ui.js');

$collection->add(
$asset1
);

// ERROR TO FIX IN PHALCON Undefined index: in phalcon/Assets/Collection.zep on line 261
$I->assertEquals($asset, $collection->current());

$collection->next();

$I->assertEquals($asset1, $collection->current());
}
}
Loading

0 comments on commit 8d90816

Please sign in to comment.