PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/.dev/tests/Classes/Model/TmpVar.php

https://github.com/istran/core
PHP | 109 lines | 55 code | 31 blank | 23 comment | 0 complexity | f6b162e79e3699b9780af9c2a6f950d6 MD5 | raw file
  1<?php
  2// vim: set ts=4 sw=4 sts=4 et:
  3
  4/**
  5 * XLite\Model\Category class tests
  6 *
  7 * @category   LiteCommerce
  8 * @package    Tests
  9 * @subpackage Classes
 10 * @author     Creative Development LLC <info@cdev.ru>
 11 * @copyright  Copyright (c) 2010 Creative Development LLC <info@cdev.ru>. All rights reserved
 12 * @license    http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 13 * @version    GIT: $Id: 2cbde48cd9c001b4697303ef7b175958a31229b7 $
 14 * @link       http://www.litecommerce.com/
 15 * @see        ____file_see____
 16 * @since      3.0.0
 17 */
 18
 19class XLite_Tests_Model_TmpVar extends XLite_Tests_TestCase
 20{
 21    protected $entityData = array(
 22        'name'  => 'test',
 23        'value' => 'value',
 24    );
 25
 26    /**
 27     * testCreate 
 28     * 
 29     * @return void
 30     * @access public
 31     * @see    ____func_see____
 32     * @since  3.0.0
 33     */
 34    public function testCreate()
 35    {
 36        $c = new \XLite\Model\TmpVar();
 37
 38        $c->map($this->entityData);
 39
 40        \XLite\Core\Database::getEM()->persist($c);
 41        \XLite\Core\Database::getEM()->flush();
 42
 43        $this->assertTrue(0 < $c->getId(), 'check id');
 44
 45        $id = $c->getId();
 46
 47        \XLite\Core\Database::getEM()->clear();
 48
 49        $c = \XLite\Core\Database::getRepo('XLite\Model\TmpVar')->find($id);
 50
 51        $this->assertEquals($c->getName(), $this->entityData['name'], 'check name');
 52        $this->assertEquals($c->getValue(), $this->entityData['value'], 'check value');
 53    }
 54
 55    public function testUpdate()
 56    {
 57        foreach (\XLite\Core\Database::getRepo('XLite\Model\TmpVar')->findAll() as $c) {
 58            \XLite\Core\Database::getEM()->remove($c);
 59        }
 60        \XLite\Core\Database::getEM()->flush();
 61
 62        $c = new \XLite\Model\TmpVar();
 63
 64        $c->map($this->entityData);
 65
 66        \XLite\Core\Database::getEM()->persist($c);
 67        \XLite\Core\Database::getEM()->flush();
 68
 69        $c->setName('zzz');
 70
 71        $id = $c->getId();
 72
 73        \XLite\Core\Database::getEM()->flush();
 74
 75        \XLite\Core\Database::getEM()->clear();
 76
 77        $c = \XLite\Core\Database::getRepo('XLite\Model\TmpVar')->find($id);
 78
 79        $this->assertEquals('zzz', $c->getName(), 'check name');
 80    }
 81
 82    public function testRemove()
 83    {
 84        foreach (\XLite\Core\Database::getRepo('XLite\Model\TmpVar')->findAll() as $c) {
 85            \XLite\Core\Database::getEM()->remove($c);
 86        }
 87        \XLite\Core\Database::getEM()->flush();
 88
 89        $c = new \XLite\Model\TmpVar();
 90    
 91        $c->map($this->entityData);
 92
 93        \XLite\Core\Database::getEM()->persist($c);
 94        \XLite\Core\Database::getEM()->flush();
 95
 96        $id = $c->getId();
 97
 98        \XLite\Core\Database::getEM()->remove($c);
 99
100        \XLite\Core\Database::getEM()->flush();
101
102        \XLite\Core\Database::getEM()->clear();
103
104        $c = \XLite\Core\Database::getRepo('XLite\Model\TmpVar')->find($id);
105
106        $this->assertTrue(is_null($c), 'check entity');
107    }
108
109}