Last active
December 22, 2015 03:59
-
-
Save MichalKalita/6414295 to your computer and use it in GitHub Desktop.
Testování modelu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/../vendor/autoload.php'; | |
if (!class_exists('Tester\Assert')) { | |
echo "Install Nette Tester using `composer update --dev`\n"; | |
exit(1); | |
} | |
Tester\Environment::setup(); | |
function id($val) { | |
return $val; | |
} | |
$configurator = new Nette\Configurator; | |
$configurator->setDebugMode(FALSE); | |
$configurator->setTempDirectory(__DIR__ . '/../temp'); | |
$configurator->createRobotLoader() | |
->addDirectory(__DIR__ . '/../app') | |
->addDirectory(__DIR__ . '/../vendor/others') | |
->register(); | |
$configurator->addConfig(__DIR__ . '/../app/config/config.neon'); | |
$configurator->addConfig(__DIR__ . '/../app/config/config.local.neon'); | |
return $configurator->createContainer(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Test; | |
use Nette, | |
Tester, | |
Tester\Assert, | |
AdminModule; | |
$container = require __DIR__ . '/../../bootstrap.php'; | |
class AdminModelCategoryTest extends Tester\TestCase | |
{ | |
/** @var Nette\DI\Container */ | |
private $container; | |
/** @var AdminModule\Model\Category */ | |
private $model; | |
/** @var Nette\Database\SelectionFactory */ | |
private $database; | |
function __construct(Nette\DI\Container $container) | |
{ | |
$this->container = $container; | |
$this->model = $container->getByType('AdminModule\Model\Category'); | |
$this->database = $container->getByType('Nette\Database\SelectionFactory'); | |
} | |
function setUp() | |
{ | |
$this->database->table('category')->delete(); | |
$this->database->table('category_translate')->delete(); | |
$this->database->table('language')->delete(); | |
$this->database->table('language')->insert(array('id' => 1, 'code' => 'en', 'name' => 'english', 'numbers' => '1,2')); | |
} | |
function testAdd() | |
{ | |
$insertData = array( | |
'parent' => NULL, | |
'priority' => 0, | |
'names' => array( | |
1 => "Category 1", | |
) | |
); | |
$this->model->add($insertData); | |
$category = $this->database->table('category')->fetch(); | |
Assert::same($insertData['parent'], $category->parent); | |
Assert::same($insertData['priority'], $category->priority); | |
Assert::same(1, $category->level); | |
Assert::same(1, $category->left); | |
Assert::same(2, $category->right); | |
$translate = $this->database->table('category_translate')->fetch(); | |
Assert::same(1, $translate->language_id); | |
Assert::same($insertData['names'][1], $translate->name); | |
} | |
} | |
id(new AdminModelCategoryTest($container))->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment