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

Language PHP Lines 227
MD5 Hash f3abfacd9be940e9d0ebac90c3fcafff
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
<?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: 4e4c1b003097e114eb642039e1c6efeee627580d $
 * @link       http://www.litecommerce.com/
 * @see        ____file_see____
 * @since      3.0.0
 */

class XLite_Tests_Model_PHARModule extends XLite_Tests_TestCase
{

    public function setUp()
    {
        parent::setUp();

        \Includes\Utils\FileManager::mkdirRecursive(LC_LOCAL_REPOSITORY);
    }

    private function getFile($file)
    {
        return dirname(__FILE__) . LC_DS . 'phars' . LC_DS . $file;
    }


    public function testBadConstruct()
    {
        \Includes\Utils\FileManager::mkdirRecursive(LC_LOCAL_REPOSITORY);

        @copy($this->getFile('bad.phar'), LC_LOCAL_REPOSITORY . 'bad.phar');

        $phar = new \XLite\Model\PHARModule('bad.phar');

        $message = $phar->getError();

        $this->assertEquals(
            $message,
            'internal corruption of phar "' . LC_LOCAL_REPOSITORY . 'bad.phar' . '" (truncated entry)',
            'must be corrupted PHAR'
        );

        @unlink(LC_LOCAL_REPOSITORY . 'bad.phar');

        $phar = new \XLite\Model\PHARModule('bad-bad-bad-name.phar');

        $message = $phar->getError();
        $status  = $phar->getStatus();

        $this->assertTrue(is_null($message) && 'error' === $status, 'Wrong error when addons catalog/file does not exist');
    }

    public function testGoodConstruct()
    {
        copy($this->getFile('good.phar'), LC_LOCAL_REPOSITORY . 'good.phar');

        $message = '';

        try {

            $phar = new \XLite\Model\PHARModule('good.phar');

        } catch (Exception $e) {

            $message = $e->getMessage();
        }

        $this->assertEquals('', $message, 'There must be no exceptions in the "Good" module');
        $this->assertTrue(is_object($phar) && !is_null($phar), 'PHAR object was not constructed');

        $phar->cleanUp();

        unlink(LC_LOCAL_REPOSITORY . 'good.phar');
    }

    public function testCheck()
    {
        // NO ini file checking
        copy($this->getFile('no_ini.phar'), LC_LOCAL_REPOSITORY . 'no_ini.phar');
        $phar = new \XLite\Model\PHARModule('no_ini.phar');
        $phar->check();

        $this->assertEquals($phar->getStatus(), 'wrong_structure', 'Wrong status for no INI file');

        $phar->cleanUp();
        unlink(LC_LOCAL_REPOSITORY . 'no_ini.phar');

        // NO catalogs checking
        copy($this->getFile('no_dir.phar'), LC_LOCAL_REPOSITORY . 'no_dir.phar');
        $phar = new \XLite\Model\PHARModule('no_dir.phar');
        $phar->check();

        $this->assertEquals($phar->getStatus(), 'wrong_structure', 'Wrong status for no DIR file');

        $phar->cleanUp();
        unlink(LC_LOCAL_REPOSITORY . 'no_dir.phar');

        // Corrupted INI checking
        copy($this->getFile('corrupted_ini.phar'), LC_LOCAL_REPOSITORY . 'corrupted_ini.phar');
        $phar = new \XLite\Model\PHARModule('corrupted_ini.phar');
        $phar->check();

        $this->assertEquals($phar->getStatus(), 'ini_corrupted', 'Wrong status for corrupted INI file');

        $phar->cleanUp();
        unlink(LC_LOCAL_REPOSITORY . 'corrupted_ini.phar');

        // Wrong INI checking
        copy($this->getFile('wrong_ini.phar'), LC_LOCAL_REPOSITORY . 'wrong_ini.phar');
        $phar = new \XLite\Model\PHARModule('wrong_ini.phar');
        $phar->check();

        $this->assertEquals($phar->getStatus(), 'wrong_specification', 'Wrong status for wrong INI file');

        $phar->cleanUp();
        unlink(LC_LOCAL_REPOSITORY . 'wrong_ini.phar');

        // Already installed module checking
        copy($this->getFile('already.phar'), LC_LOCAL_REPOSITORY . 'already.phar');
        $phar = new \XLite\Model\PHARModule('already.phar');
        $phar->check();

        $this->assertEquals($phar->getStatus(), 'wrong_install', 'Wrong status for already installed module');

        $phar->cleanUp();
        unlink(LC_LOCAL_REPOSITORY . 'already.phar');
    }

    public function testDeploy()
    {
        // Deploying only classes directory module
        copy($this->getFile('test_module.phar'), LC_LOCAL_REPOSITORY . 'test_module.phar');

        $phar = new \XLite\Model\PHARModule('test_module.phar');

        $phar->check();

        $this->assertEquals('ok', $phar->getStatus(), 'Good module must be validated');

        $phar->deploy();

        $phar->cleanUp();

        $dir = LC_CLASSES_DIR . 'XLite' . LC_DS . 'Module' . LC_DS . 'CDev' . LC_DS . 'Good';

        $this->assertTrue(is_dir($dir), 'Classes catalog was not created');

        $files = array(
            'CHANGELOG',
            'Main.php',
            'install.php',
            'install.yaml',
        );

        foreach ($files as $file) {
            $this->assertTrue(is_file($dir . LC_DS . $file));
        }

        \Includes\Utils\FileManager::unlinkRecursive($dir);

        unlink(LC_LOCAL_REPOSITORY . 'test_module.phar');
    }

    public function testDeploy2()
    {
        // Deploying classes and skins directories module
        copy($this->getFile('test_module2.phar'), LC_LOCAL_REPOSITORY . 'test_module2.phar');

        $phar = new \XLite\Model\PHARModule('test_module2.phar');

        $phar->check();

        $this->assertEquals('ok', $phar->getStatus(), 'new Bestsellers module must be validated');

        $phar->deploy();

        $phar->cleanUp();

        $classesDir = LC_CLASSES_DIR . 'XLite' . LC_DS . 'Module' . LC_DS . 'TestAuthor';

        $skins = array(
            LC_SKINS_DIR . 'admin' . LC_DS . 'en' . LC_DS . 'modules' . LC_DS . 'TestAuthor',
            LC_SKINS_DIR . 'drupal' . LC_DS . 'en' . LC_DS . 'modules' . LC_DS . 'TestAuthor',
        );

        $this->assertTrue(is_dir($classesDir . LC_DS . 'Bestsellers'), 'Classes catalog was not created');

        foreach ($skins as $skin) {
            $this->assertTrue(is_dir($skin . LC_DS . 'Bestsellers'), $skin . ' was not created');
        }

        \Includes\Utils\FileManager::unlinkRecursive($classesDir);

        foreach ($skins as $skin) {
            \Includes\Utils\FileManager::unlinkRecursive($skin);
        }

        unlink(LC_LOCAL_REPOSITORY . 'test_module2.phar');
    }


    public function testCleanUp()
    {


    }

}
Back to Top