core /.dev/tests/Classes/Model/Module.php

Language PHP Lines 321
MD5 Hash 77ac55273aa16dd0c41bfceb1048b955
Repository https://github.com/istran/core.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
// vim: set ts=4 sw=4 sts=4 et:

/**
 * LiteCommerce
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to licensing@litecommerce.com so we can send you a copy immediately.
 * 
 * @category   LiteCommerce
 * @package    Tests
 * @subpackage Classes
 * @author     Creative Development LLC <info@cdev.ru> 
 * @copyright  Copyright (c) 2010 Creative Development LLC <info@cdev.ru>. All rights reserved
 * @license    http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * @version    GIT: $Id: 9ed56d3a7f0e1c6d67e99f24a849d616714619fe $
 * @link       http://www.litecommerce.com/
 * @see        ____file_see____
 * @since      3.0.0
 */

class XLite_Tests_Model_Module extends XLite_Tests_Model_ModuleAbstract
{

    // TODO: implement using a test module package once installation and packing
    //       is complete. Currently Featured products module is used for testing
    
    public function testCreate()
    {
        $module = $this->getTestModule();

        $this->assertTrue(0 < $module->getModuleId(), 'Check Module ID');

        foreach ($this->testModule as $k => $v) {
            $m = 'get' . \XLite\Core\Converter::convertToCamelCase($k);
            $this->assertEquals($v, $module->$m(), 'Check ' . $k);
        }

        // Test create() method itself
        $module = new \XLite\Model\Module();
        $module->create('CreatedModule', 'CreatedAuthor');

        $module = \XLite\Core\Database::getRepo('XLite\Model\Module')->find($module->getModuleId());
        $this->assertEquals('CreatedModule', $module->getName(), 'Check name using create() method');
        $this->assertEquals('CreatedAuthor', $module->getAuthor(), 'Check author using create() method');
    }

    public function testUpdate()
    {
        $newValues = array(
            'name'          => 'TestModule1',
            'author'        => 'TestAuthor1',
            'moduleName'    => 'Test module name1',
            'authorName'    => 'Test module author1',
            'description'   => 'Test module description1',
            'installed'     => false,
            'version'       => '1.2.31',
            'rating'        => 99,
            'downloads'     => 101,
            'iconURL'       => 'icon/url/test/path1',
            'date'          => 1295513913,
            'changelog'     => 'Test changelog1',
            'currency'      => 'USD',
            'purchased'     => true,
            'price'         => 10.12,
            'uploadCode'    => 'abc',
            'packHash'      => 'asdasd',
            'dependencies'  => array(
                array('CDev', 'AOM')
            ),
        );

        $module = $this->getTestModule();

        // Set values
        foreach ($newValues as $k => $newval) {
            $m = 'set' . \XLite\Core\Converter::convertToCamelCase($k);
            $module->$m($newval);
        }

        $module->setStatus($module::EXISTS);

        \XLite\Core\Database::getEM()->persist($module);
        \XLite\Core\Database::getEM()->flush();

        \XLite\Core\Database::getEM()->clear();

        // Get values
        $module = \XLite\Core\Database::getRepo('XLite\Model\Module')->find($module->getModuleId());

        foreach ($newValues as $k => $newval) {
            $m = 'get' . \XLite\Core\Converter::convertToCamelCase($k);
            $this->assertEquals($newval, $module->$m(), 'check new ' . $k);
            $module->$m();
        }

        $this->assertEquals($module::EXISTS, $module->getStatus(), 'check new status');
    }

    public function testDelete()
    {
        $module = $this->getTestModule();

        $id = $module->getModuleId();

        \XLite\Core\Database::getEM()->remove($module);
        \XLite\Core\Database::getEM()->flush();

        $module = \XLite\Core\Database::getRepo('XLite\Model\Module')
            ->find($id);

        $this->assertTrue(is_null($module), 'check removed module');
    }

    public function testHasIcon()
    {
        $module = $this->getTestModule();
        $this->assertTrue($module->hasIcon(), 'check if module has icon');
    }

    public function testIsFree()
    {
        $module = $this->getTestModule();
        $this->assertFalse($module->isFree(), 'check if module is free');
    }

    public function testGetMarketplaceURL()
    {
        $module = $this->getTestModule();
        $this->assertEquals('https://www.litecommerce.com/marketplace/', $module::getMarketplaceURL(), 'check marketplace URL');
    }

    public function testGetPageURL()
    {
        $module = $this->getTestModule();
        $this->assertEquals('https://www.litecommerce.com/marketplace/module/TestAuthor/TestModule', $module->getPageURL(), 'check module URL');
    }

    public function testGetAuthorPageURL()
    {
        $module = $this->getTestModule();
        $this->assertEquals('https://www.litecommerce.com/marketplace/module/TestAuthor', $module->getAuthorPageURL(), 'check module author URL');
    }

    public function testSetEnabled()
    {
        $module = $this->getEnabledModule();
        $module->setEnabled(false);
        \XLite\Core\Database::getEM()->flush();

        \XLite\Core\Database::getEM()->clear();
 
        $module = \XLite\Core\Database::getRepo('XLite\Model\Module')->find($module->getModuleId());
        $this->assertFalse($module->getEnabled(), 'check if module is disabled');
        
        $module->setEnabled(true);
        \XLite\Core\Database::getEM()->flush();
        $this->assertTrue($module->getEnabled(), 'check if module is enabled');
    }

    public function testProtectedStructures()
    {
        $path = LC_VAR_DIR . '.disabled.structures.php';

        if (file_exists($path)) {
            unlink($path);
        }

        $module = \Xlite\Core\Database::getRepo('XLite\Model\Module')
            ->findOneBy(array('author' => 'CDev', 'name' => 'ProductOptions'));
        $module->disableModule();
        \XLite\Core\Database::getEM()->flush();

        $etalon = "# <?php if (!defined('LC_DS')) { die(); } ?>

CDev\ProductOptions:
  tables: [options, option_exceptions, option_groups, option_group_translations, option_surcharges, option_translations, order_item_options]
  columns: {  }
";

        $this->assertEquals($etalon, file_get_contents($path), 'check .disabled.structures.php');
        if (file_exists($path)) {
            unlink($path);
        }
    }

    public function testPrepareUpdate()
    {
        // TODO: check if possible
    }

    public function testGetDependedModules()
    {
        // TODO: implement after module installation tests are done
    }

    public function testDisableModule()
    {
        $module = $this->getEnabledModule();
        $module->disableModule();
        $this->assertFalse($module->getEnabled(), 'check if module is disabled');
    }

    public function testGetSettingsFormLink()
    {
        $module = $this->getEnabledModule(true, 'FeaturedProducts');
        $this->assertEquals('admin.php?target=module&moduleId=' . $module->getModuleId(), $module->getSettingsFormLink(), 'check general settings form link');
        
        $module = $this->getEnabledModule(true, 'AustraliaPost');
        $this->assertEquals('admin.php?target=aupost', $module->getSettingsFormLink(), 'check custom settings form link');
    }
    
    public function testGetMainClass()
    {
        $module = $this->getEnabledModule(true, 'FeaturedProducts');
        $this->assertEquals('\XLite\Module\CDev\FeaturedProducts\Main', $module->getMainClass(), 'check main class');
    }
    
    public function testGetDependenciesModules()
    {
        // TODO: implement after dependencies system refactoring
    }
    
    public function testCanEnable()
    {
        $module = $this->getEnabledModule();

        $module->setInstalled(false);
        $this->assertFalse($module->canEnable(), 'check if module can be enabled');

        // TODO: implement dependencies checker after dependencies system refactoring
        // TODO: implement checking of the static check() method of the main class
    }
    
    public function testGetHash()
    {
        // TODO: implement after all upload/install functions and tests are completed
    }

    public function testUninstall()
    {
        // TODO: after packing mechanism is completed
    }

    public function testAnonymousCall()
    {
        $module = $this->getEnabledModule(true, 'FeaturedProducts');

        $module->setModuleName('aaa');
        $module->setAuthorName('bbb');
        $module->setDescription('ccc');

        $this->assertEquals('This module enables featured products list', $module->__call('getDescription'), 'check description call');
        $this->assertEquals('Featured Products', $module->__call('getModuleName'), 'check name call');
        $this->assertEquals('Creative Development LLC', $module->__call('getAuthorName'), 'check author call');
    }
    
    public function testIsUpdateAvailable()
    {
        $module = $this->getEnabledModule(true, 'FeaturedProducts');
        $this->assertFalse($module->isUpdateAvailable(), 'check not available update');

        $module->setVersion($module->getVersion() . '.1');
        $this->assertTrue($module->isUpdateAvailable(), 'check available update');
    }

    public function testGetLastVersion()
    {
        $module = $this->getEnabledModule(true, 'FeaturedProducts');
        $this->assertEquals($module->getVersion(), $module->getLastVersion(), 'check last version getter');
    }

    public function testGetCurrentVersion()
    {
        $module = $this->getEnabledModule(true, 'FeaturedProducts');
        $oldVer = $module->getVersion();
        $module->setVersion($module->getVersion() . '.1');
        $this->assertEquals($oldVer, $module->getCurrentVersion(), 'check current version getter');
    }

    public function testGetActualName()
    {
        $module = $this->getTestModule();
        $this->assertEquals('TestAuthor\\TestModule', $module->getActualName(), 'check actual name');
    }

    public function testGetPath()
    {
        $module = $this->getTestModule();
        $this->assertEquals('TestAuthor/TestModule', $module->getPath(), 'check path');
    }
 
    public function testGetModel()
    {
        $module = $this->getTestModule();
        $this->assertEquals($module->getModel(), $module->model, 'check model');

    }

    public function testCanUpload()
    {
        $module = $this->getTestModule();
        $this->assertFalse($module->canUpload(), 'check if can upload');

        $module->setUploadCode('1234567890.1234567890.1234567890');
        $this->assertTrue($module->canUpload(), 'check if can upload');
    }

    public function testUpload()
    {
        // TODO:
    }
}
Back to Top