Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Sander's fixes #60

Merged
merged 31 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
086190f
add query setting to scaffolding
Nov 25, 2015
8c5aa79
Merge branch 'master' into v1.1
Nov 25, 2015
c1f808d
Add option to set query from crud controller
Nov 25, 2015
8c7db8b
Add query option to Scaffolding MySQL adapter
Nov 25, 2015
e850773
Add tests for paginator and query options
Nov 26, 2015
4bb2963
- Update tests for Scaffolding MySQL pagination
Nov 26, 2015
8c3b526
php to 5.5
krzysztof-kabala Mar 23, 2016
dd5b6cf
php 5.6
krzysztof-kabala Mar 29, 2016
a81fb87
Merge branch 'v1.1-vegas' into v1.1
Mar 30, 2016
557c276
i18n task
krzysztof-kabala Apr 7, 2016
90b0c72
i18n task
krzysztof-kabala Apr 7, 2016
9900c60
build & testing
krzysztof-kabala Apr 7, 2016
931000e
build & testing
krzysztof-kabala Apr 7, 2016
a711edf
Create I18nTask.php
krzysztof-kabala Apr 7, 2016
0b50011
Merge pull request #2 from krzysztof-kabala/patch-3
sanderborgman Apr 7, 2016
a1979ec
quickfix
krzysztof-kabala Apr 7, 2016
8a3086b
quickfix
krzysztof-kabala Apr 7, 2016
3a9da70
quickfix
krzysztof-kabala Apr 7, 2016
da69448
Update I18nTask.php
krzysztof-kabala Apr 7, 2016
02f9c43
Merge pull request #3 from krzysztof-kabala/patch-4
sanderborgman Apr 7, 2016
0f9fa60
quickfix
krzysztof-kabala Apr 7, 2016
abd59b2
Update I18nTask.php
krzysztof-kabala May 19, 2016
04fb155
Merge pull request #4 from krzysztof-kabala/patch-5
sanderborgman May 19, 2016
05d207a
Update I18nTask.php
krzysztof-kabala May 19, 2016
1f93f43
Merge pull request #5 from krzysztof-kabala/patch-6
sanderborgman May 19, 2016
c92018a
Update I18nTask.php
krzysztof-kabala Aug 2, 2016
aa23843
Merge pull request #6 from krzysztof-kabala/patch-7
sanderborgman Aug 2, 2016
58da14e
cleanup
krzysztof-kabala Feb 9, 2017
8ad04b8
cleanup
krzysztof-kabala Feb 9, 2017
8578455
Merge pull request #1 from sanderborgman/v1.1
krzysztof-kabala Feb 9, 2017
1310ef7
remove i18n
krzysztof-kabala Feb 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ before_script:
- (cd cphalcon/ext; export CFLAGS="-g3 -O1 -fno-delete-null-pointer-checks -Wall"; phpize && ./configure --enable-phalcon && make -j4 && sudo make install && phpenv config-add ../unit-tests/ci/phalcon.ini)
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev

script:
- cp tests/config.sample.php tests/config.php
- mkdir -p tests/fixtures/cache
Expand All @@ -29,4 +29,4 @@ script:
- php vendor/bin/phpunit -c travis/phpunit.xml.dist

after_script:
- php vendor/bin/coveralls -v
- php vendor/bin/coveralls -v
18 changes: 17 additions & 1 deletion src/DI/Scaffolding.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class Scaffolding implements ScaffoldingInterface
*/
protected $formName;

/**
* Query
*
* @var array
*/
protected $query = [];

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -135,6 +142,15 @@ public function setModelName($name)
return $this;
}

/**
* {@inheritdoc}
*/
public function setQuery($query)
{
$this->adapter->setQuery($query);
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -194,7 +210,7 @@ public function doDelete($id)
*/
private function processForm($values)
{
$form = $this->getForm();
$form = $this->getForm($this->record);
$form->bind($values, $this->record);

if ($form->isValid()) {
Expand Down
18 changes: 18 additions & 0 deletions src/DI/Scaffolding/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Mongo implements AdapterInterface, ScaffoldingAdapterInterface
*/
protected $scaffolding;

/**
* Query for paginator
*
* @var array
*/
protected $query = [];

/**
* Constructor
* Verifies services required by Mongo
Expand All @@ -49,6 +56,16 @@ public function __construct()
$this->setupExtraServices($di);
}

/**
* {@inheritdoc}
*/
public function setQuery($query)
{
$this->query = $query;

return $this;
}

/**
* {@inheritdoc}
*/
Expand All @@ -69,6 +86,7 @@ public function retrieveOne($id)
public function getPaginator($page = 1, $limit = 10)
{
return new PaginatorAdapterMongo(array(
'query' => $this->query,
'model' => $this->scaffolding->getRecord(),
'limit' => $limit,
'page' => $page
Expand Down
19 changes: 18 additions & 1 deletion src/DI/Scaffolding/Adapter/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Mysql implements AdapterInterface, ScaffoldingAdapterInterface
*/
protected $scaffolding;

/**
* Query for paginator
*
* @var array
*/
protected $query = [];

/**
* Constructor
*/
Expand All @@ -47,6 +54,16 @@ public function __construct()
$this->verifyRequiredServices($di);
}

/**
* {@inheritdoc}
*/
public function setQuery($query)
{
$this->query = $query;

return $this;
}

/**
* {@inheritdoc}
*/
Expand All @@ -71,7 +88,7 @@ public function getPaginator($page = 1, $limit = 10)
$this->ensureScaffolding();

return new PaginatorAdapterModel(array(
'data' => (object) call_user_func(array($this->scaffolding->getRecord(), 'find')),
'data' => call_user_func(array($this->scaffolding->getRecord(), 'find'), $this->query),
'limit' => $limit,
'page' => $page
));
Expand Down
8 changes: 8 additions & 0 deletions src/DI/Scaffolding/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ interface AdapterInterface
*/
public function retrieveOne($id);

/**
* Sets query for the paginator
*
* @param $id
* @return mixed
*/
public function setQuery($query);

/**
* Retrieve list of records as paginator object.
*
Expand Down
8 changes: 8 additions & 0 deletions src/DI/ScaffoldingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function getForm($entity = null);
*/
public function setFormName($name);

/**
* Sets query for paginator
*
* @param $query
* @return mixed
*/
public function setQuery($query);

/**
* Sets model name
*
Expand Down
8 changes: 8 additions & 0 deletions src/Mvc/Controller/CrudAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public function initialize()
*/
protected $modelName;

/**
* Query that will be used in index action
*
* @var array
*/
protected $query = [];

/**
* Array of fields names that will be used in index action
*
Expand Down Expand Up @@ -104,6 +111,7 @@ protected function initializeScaffolding()

$this->scaffolding->setModelName($this->modelName);
$this->scaffolding->setFormName($this->formName);
$this->scaffolding->setQuery($this->query);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Mvc/Module/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function dump($inputDirectory, $outputDirectory, $dumpVendorModules = tru
* @param $modulesList
* @return mixed
*/
private function dumpModulesFromVendor(array &$modulesList)
public function dumpModulesFromVendor(array &$modulesList)
{
if (!file_exists(APP_ROOT.'/composer.json')) {
return $modulesList;
Expand Down
37 changes: 34 additions & 3 deletions src/Task/AssetsTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Vegas\Cli\Task\Option;
use Vegas\Cli\Task;
use Vegas\Cli\TaskAbstract;
use Vegas\Mvc\Module\Loader;

/**
* Class AssetsTask
Expand All @@ -28,16 +29,20 @@ class AssetsTask extends TaskAbstract
*/
public function publishAction()
{
$this->putText("Copying assets...");
$this->copyAllAssets();
$this->putText("Copying Vegas CMF assets...");
$this->copyCmfAssets();

$this->putText("Copying vendor assets:");
$this->copyVendorAssets();

$this->putSuccess("Done.");
}

/**
* Copies all assets from vegas-cmf libraries
* @internal
*/
private function copyAllAssets()
private function copyCmfAssets()
{
$vegasCmfPath = APP_ROOT . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'vegas-cmf';
$publicAssetsDir = $this->getOption('d', APP_ROOT.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.'assets');
Expand All @@ -59,6 +64,32 @@ private function copyAllAssets()
}
}

/**
* Copies all assets vendor modules
* @internal
*/
private function copyVendorAssets()
{
$modules = [];
$moduleLoader = new Loader($this->di);
$moduleLoader->dumpModulesFromVendor($modules);

$publicAssetsDir = $this->getOption('d', APP_ROOT.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.'assets');


if ($modules) {
foreach ($modules as $moduleName => $module) {
$assetsDir = dirname($module['path']) . '/../assets';

if (file_exists($assetsDir)) {
$this->putText("- " . $moduleName . "...");

$this->copyRecursive($assetsDir, $publicAssetsDir);
}
}
}
}

/**
* Copies assets recursively
*
Expand Down
34 changes: 32 additions & 2 deletions tests/DI/Scaffolding/Adapter/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,47 @@ public function testShouldReturnValidPagination()
$mysql = new \Vegas\DI\Scaffolding\Adapter\Mysql();
$scaffolding = new Scaffolding($mysql);

$scaffolding->setModelName('\Test\Models\Fake');
$scaffolding->setModelName('\Test\Models\FakeSql');
$scaffolding->setFormName('\Test\Forms\Fake');
$scaffolding->doCreate([
'fake_field' => 'fake'
]);
$scaffolding->doCreate([
'fake_field' => 'fake2'
]);

$pagination = $mysql->getPaginator();
$paginate = $pagination->getPaginate();

$this->assertInstanceOf('\Phalcon\Paginator\Adapter\Model', $pagination);
$this->assertInstanceOf('\stdClass', $paginate);
$this->assertNotEquals(0, $paginate->total_items);
}

public function testShouldReturnFilteredPagination()
{
$mysql = new \Vegas\DI\Scaffolding\Adapter\Mysql();
$scaffolding = new Scaffolding($mysql);

$scaffolding->setModelName('\Test\Models\FakeSql');
$scaffolding->setFormName('\Test\Forms\Fake');
$scaffolding->doCreate([
'fake_field' => 'fake'
]);
$scaffolding->doCreate([
'fake_field' => 'fake2'
]);
$scaffolding->doCreate([
'fake_field' => 'fake'
]);
$scaffolding->setQuery('fake_field = "fake2"');

$pagination = $mysql->getPaginator();
$paginate = $pagination->getPaginate();

$this->assertInstanceOf('\Phalcon\Paginator\Adapter\Model', $pagination);
$this->assertInstanceOf('\stdClass', $pagination->getPaginate());
$this->assertInstanceOf('\stdClass', $paginate);
$this->assertNotEquals(0, $paginate->total_items);
$this->assertEquals('fake2', $paginate->items[0]->fake_field);
}
}
29 changes: 29 additions & 0 deletions tests/DI/ScaffoldingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ protected function setUp()
$record = new \Vegas\Tests\Stub\Models\FakeModel();
$record->fake_field = 'test';
$record->save();

$record = new \Vegas\Tests\Stub\Models\FakeModel();
$record->fake_field = 'test_query';
$record->save();

$this->record = $record;
}
Expand Down Expand Up @@ -133,4 +137,29 @@ public function testDoDelete()
$this->assertInstanceOf('\Vegas\DI\Scaffolding\Exception\RecordNotFoundException', $ex);
}
}

public function testShouldReturnValidPagination()
{
$pagination = $this->scaffolding->doPaginate();

$this->assertInstanceOf('\Vegas\Paginator\Adapter\Mongo', $pagination);

$results = $pagination->getResults();

$this->assertNotCount(0, $results);
$this->assertInstanceOf('\Vegas\Tests\Stub\Models\FakeModel', $results[0]);
}

public function testShouldReturnFilteredPagination()
{
$this->scaffolding->setQuery([
'fake_field' => 'test_query'
]);

$pagination = $this->scaffolding->doPaginate();
$results = $pagination->getResults();

$this->assertNotCount(0, $results);
$this->assertEquals('test_query', $results[0]->fake_field);
}
}
27 changes: 27 additions & 0 deletions tests/fixtures/app/modules/Test/models/FakeSql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* This file is part of Vegas package
*
* @author Slawomir Zytko <slawek@amsterdam-standard.pl>
* @copyright Amsterdam Standard Sp. Z o.o.
* @homepage http://vegas-cmf.github.io
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Test\Models;

use Vegas\Db\Decorator\ModelAbstract;

class FakeSql extends ModelAbstract
{
public function getSource()
{
return 'fake';
}

protected $mappings = array(
'arraydata' => 'json'
);
}
3 changes: 3 additions & 0 deletions tests/fixtures/public/assets/css/vendor.another.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
color: #111;
}
3 changes: 3 additions & 0 deletions tests/fixtures/public/assets/css/vendor.test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: #FDFDFD;
}
3 changes: 3 additions & 0 deletions tests/fixtures/public/assets/js/vendor.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* Created by arius on 30.05.14.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
color: #111;
}