Ejemplo n.º 1
0
    def test_psr4(self):
        # 1. composer.json doesn't exist
        mapping = {
            'path/to/vendor/name/module/Block/Subfolder/Block.php':
            'Name\\Module\\',
            'path/to/vendor/vendor-name/module-name/README.md':
            'VendorName\\ModuleName\\'
        }

        for filepath in mapping:
            app = App(filepath)
            self.assertEqual(mapping[filepath],
                             next(iter(app.composer.psr4())))

        # 2. composer.json exists
        mapping = {
            '/fixtures/vendor/v-name/module/Model/Entity.php':
            'Hello\\World\\',
            '/fixtures/app/code/Name/Module/Model/Entity.php':
            'Hello\\World2\\',
            '/fixtures/app/code/Core/Data.php': 'Code\\',
        }

        dirpath = os.path.dirname(os.path.realpath(__file__))
        for filepath in mapping:
            app = App(dirpath + filepath)
            self.assertEqual(mapping[filepath],
                             next(iter(app.composer.psr4())))
Ejemplo n.º 2
0
    def test_psr4dir(self):
        mapping = {
            'path/to/vendor/name/module/src/Model/Entity.php': 'src/',
            'path/to/vendor/name/module/subfolder/Model/Entity.php': 'subfolder/',
            'path/to/vendor/name/module/tests/Model/Entity.php': 'tests/'
        }

        for filepath in mapping:
            app = App(filepath)
            app.composer._path = 'path/to/vendor/name/module/composer.json'
            app.composer._data = json.loads(
                """{
                    "autoload": {
                        "psr-4": {
                            "Src\\\\Src\\\\": "src/",
                            "Src2\\\\Src2\\\\": "subfolder/"
                        }
                    },
                    "autoload-dev": {
                        "psr-4": {
                            "Name\\\\Module\\\\": "tests/"
                        }
                    }
                }""",
                object_pairs_hook=OrderedDict
            )
            self.assertEqual(mapping[filepath], app.file.psr4dir())
Ejemplo n.º 3
0
 def test_data(self):
     dirpath = os.path.dirname(os.path.realpath(__file__))
     app = App(dirpath + '/fixtures/app/code/Core/Data.php')
     self.assertEqual('Description', app.composer.data('description'))
     self.assertEqual('composer',
                      app.composer.data('repositories.magento.type'))
     self.assertEqual('https://repo.magento.com/',
                      app.composer.data('repositories.magento.url'))
Ejemplo n.º 4
0
    def test_path(self):
        files = {
            'path/to/vendor/name/module/Block/Subfolder/Block.php',
            'path/to/vendor/name/module/src/Model/Entity.php',
            'path/to/vendor/name/module/subfolder/Model/Entity.php.txt'
        }

        for filepath in files:
            app = App(filepath)
            self.assertEqual(filepath, app.file.path())
Ejemplo n.º 5
0
    def test_parent_folder(self):
        mapping = {
            'path/to/vendor/name/module/Block/Subfolder/Block.php': 'Block',
            'path/to/vendor/name/module/src/Model/Entity.php': 'src',
            'path/to/vendor/name/module/subfolder/Model/Entity.php.txt': 'subfolder'
        }

        for filepath in mapping:
            app = App(filepath)
            self.assertEqual(mapping[filepath], app.file.parent_folder())
Ejemplo n.º 6
0
    def test_vendor_by_package_name(self):
        mapping = {
            'vendor-name/module-hello-world': 'vendor-name',
            'swissup/magento2-hello-world': 'swissup',
        }

        for package in mapping:
            app = App('dummy')
            app.composer._data = {'name': package}
            self.assertEqual(mapping[package], app.project.vendor())
Ejemplo n.º 7
0
    def test_vendor_by_psr4key(self):
        mapping = {
            'Name\\Module\\': 'name',
            'VendorName\\ModuleName\\': 'vendor-name'
        }

        for psr4key in mapping:
            app = App('dummy')
            app.file._psr4key = psr4key
            self.assertEqual(mapping[psr4key], app.project.vendor())
Ejemplo n.º 8
0
    def test_code(self):
        mapping = {
            'Name\\Module\\': 'Name_Module',
            'VendorName\\ModuleName\\': 'VendorName_ModuleName'
        }

        for psr4key in mapping:
            app = App('dummy')
            app.file._psr4key = psr4key
            self.assertEqual(mapping[psr4key], app.project.code())
Ejemplo n.º 9
0
    def test_root(self):
        mapping = {
            'path/to/vendor/name/module/composer.json':
            'path/to/vendor/name/module'
        }

        for filepath in mapping:
            app = App(filepath)
            app.composer._path = filepath
            self.assertEqual(mapping[filepath], app.project.root())
Ejemplo n.º 10
0
 def test_guess_type_by_composer_by_type(self):
     mapping = {
         'magento2-module': 'magento2',
         'magento-module': 'magento1',
         None: None
     }
     for project_type in mapping:
         app = App('dummy')
         app.composer._data = {'type': project_type}
         self.assertEqual(mapping[project_type],
                          app.project.guess_type_by_composer())
Ejemplo n.º 11
0
    def test_project_by_psr4key(self):
        # with defined psr4keys
        mapping = {
            'Name\\Module\\': 'module',
            'VendorName\\ModuleName\\': 'module-name'
        }

        for psr4key in mapping:
            app = App('dummy')
            app.file._psr4key = psr4key
            self.assertEqual(mapping[psr4key], app.project.project())
Ejemplo n.º 12
0
    def test_relative_path(self):
        mapping = {
            'path/to/vendor/name/module/Block/Subfolder/Block.php': 'Block/Subfolder/Block.php',
            'path/to/vendor/name/module/src/Model/Entity.php': 'src/Model/Entity.php',
            'path/to/vendor/name/module/subfolder/Model/Entity.php.txt': 'subfolder/Model/Entity.php.txt'
        }

        for filepath in mapping:
            app = App(filepath)
            app.composer._path = 'path/to/vendor/name/module/composer.json'
            self.assertEqual(mapping[filepath], app.file.relative_path())
Ejemplo n.º 13
0
    def test_project(self):
        # 1. composer.json doesn't exist
        mapping = {
            'path/to/vendor/name/module/Block/Subfolder/Block.php': 'module',
            'path/to/vendor/vendor-name/module-name/README.md': 'module-name'
        }

        for filepath in mapping:
            app = App(filepath)
            self.assertEqual(mapping[filepath], app.composer.project())

        # 2. composer.json exists
        mapping = {
            '/fixtures/vendor/v-name/module/Model/Entity.php': 'module',
            '/fixtures/app/code/Name/Module/Model/Entity.php': 'module',
            '/fixtures/app/code/Core/Data.php': 'project',
        }

        dirpath = os.path.dirname(os.path.realpath(__file__))
        for filepath in mapping:
            app = App(dirpath + filepath)
            self.assertEqual(mapping[filepath], app.composer.project())
Ejemplo n.º 14
0
    def test_project_by_package_name(self):
        # without defined psr4keys
        mapping = {
            'vendor/module-hello-world': 'hello-world',
            'swissup/magento2-hello-world': 'hello-world',
            'swissup/magento-2-hello-world': 'hello-world',
            'swissup/magento1-hello-world': 'hello-world',
            'swissup/magento-hello-world': 'hello-world',
            'swissup/hello-world-extension': 'hello-world',
            'swissup/hello-world-magento-2': 'hello-world',
        }

        for package in mapping:
            app = App('dummy')
            app.composer._data = {'name': package}
            self.assertEqual(mapping[package], app.project.project())
Ejemplo n.º 15
0
    def test_guess_type_by_contents(self):
        mapping = {
            'extends Magento': 'magento2',
            'extends Mage_': 'magento1',
            '$a = Mage::': 'magento1'
        }
        for contents in mapping:
            app = App('dummy')

            self.view = sublime.active_window().new_file()

            self.view.run_command('insert', {'characters': contents})

            _type = app.project.guess_type_by_contents()

            self.view.window().focus_view(self.view)
            self.view.set_scratch(True)
            self.view.window().run_command('close_file')

            self.assertEqual(mapping[contents], _type)
Ejemplo n.º 16
0
    def test_autoload_path(self):
        mapping = {
            'path/to/vendor/name/module/Block/Subfolder/Block.php': 'Block/Subfolder/Block.php',
            'path/to/vendor/name/module/unregistered/Block/Subfolder/Block.php': 'unregistered/Block/Subfolder/Block.php',
            'path/to/vendor/name/module/src/Model/Entity.php': 'Model/Entity.php',
            'path/to/vendor/name/module/subfolder/Model/Entity.php': 'Model/Entity.php'
        }

        for filepath in mapping:
            app = App(filepath)
            app.composer._path = 'path/to/vendor/name/module/composer.json'
            app.composer._data = json.loads(
                """{
                    "autoload": {
                        "psr-4": {
                            "Src\\\\Src\\\\": "src/",
                            "Src2\\\\Src2\\\\": "subfolder/",
                            "Name\\\\Module\\\\": ""
                        }
                    }
                }""",
                object_pairs_hook=OrderedDict
            )
            self.assertEqual(mapping[filepath], app.file.autoload_path())
Ejemplo n.º 17
0
 def test_guess_type_by_composer_by_extra(self):
     app = App('dummy')
     app.composer._data = {'extra': {'magento-root-dir': '.'}}
     self.assertEqual('magento1', app.project.guess_type_by_composer())
Ejemplo n.º 18
0
 def test_guess_type_by_composer_by_vendor(self):
     app = App('dummy')
     app.composer._data = {'name': 'magento/magento2ce'}
     self.assertEqual('magento2', app.project.guess_type_by_composer())
Ejemplo n.º 19
0
    def test_guess_template_path(self):
        mapping = {
            "vendor/module/Block/Subfolder/Block.php":
            "magento2/files/Block/Block.php",
            "vendor/module/Controller/Adminhtml/Index.php":
            "magento2/files/Controller/Adminhtml/Entity/Index.php",
            "vendor/module/Controller/Adminhtml/NewAction.php":
            "magento2/files/Controller/Adminhtml/Entity/NewAction.php",
            "vendor/module/Controller/Adminhtml/Edit.php":
            "magento2/files/Controller/Adminhtml/Entity/Edit.php",
            "vendor/module/Controller/Adminhtml/Save.php":
            "magento2/files/Controller/Adminhtml/Entity/Save.php",
            "vendor/module/Controller/Adminhtml/MassDelete.php":
            "magento2/files/Controller/Adminhtml/Entity/MassDelete.php",
            "vendor/module/Controller/Adminhtml/MassStatus.php":
            "magento2/files/Controller/Adminhtml/Entity/MassStatus.php",
            "vendor/module/Controller/Adminhtml/MassDisable.php":
            "magento2/files/Controller/Adminhtml/Entity/MassStatus.php",
            "vendor/module/Controller/Adminhtml/Delete.php":
            "magento2/files/Controller/Adminhtml/Entity/Delete.php",
            "vendor/module/Controller/Adminhtml/Validate.php":
            "magento2/files/Controller/Adminhtml/Entity/Validate.php",
            "vendor/module/Controller/Name/Index.php":
            "magento2/files/Controller/Entity/Index.php",
            "vendor/module/Controller/Name/Save.php":
            "magento2/files/Controller/Entity/Save.php",
            "vendor/module/Controller/Name/Post.php":
            "magento2/files/Controller/Entity/Save.php",
            "vendor/module/etc/adminhtml/di.xml":
            "magento2/files/etc/adminhtml/di.xml",
            "vendor/module/etc/adminhtml/events.xml":
            "magento2/files/etc/adminhtml/events.xml",
            "vendor/module/etc/adminhtml/menu.xml":
            "magento2/files/etc/adminhtml/menu.xml",
            "vendor/module/etc/adminhtml/routes.xml":
            "magento2/files/etc/adminhtml/routes.xml",
            "vendor/module/etc/adminhtml/system.xml":
            "magento2/files/etc/adminhtml/system.xml",
            "vendor/module/etc/frontend/di.xml":
            "magento2/files/etc/frontend/di.xml",
            "vendor/module/etc/frontend/events.xml":
            "magento2/files/etc/frontend/events.xml",
            "vendor/module/etc/frontend/page_types.xml":
            "magento2/files/etc/frontend/page_types.xml",
            "vendor/module/etc/frontend/routes.xml":
            "magento2/files/etc/frontend/routes.xml",
            "vendor/module/etc/frontend/sections.xml":
            "magento2/files/etc/frontend/sections.xml",
            "vendor/module/etc/acl.xml": "magento2/files/etc/acl.xml",
            "vendor/module/etc/config.xml": "magento2/files/etc/config.xml",
            "vendor/module/etc/di.xml": "magento2/files/etc/di.xml",
            "vendor/module/etc/events.xml": "magento2/files/etc/events.xml",
            "vendor/module/etc/module.xml": "magento2/files/etc/module.xml",
            "vendor/module/etc/widget.xml": "magento2/files/etc/widget.xml",
            "vendor/module/Helper/Data.php": "magento2/files/Helper/Data.php",
            "vendor/module/Helper/Subfolder/Name.php":
            "magento2/files/Helper/Data.php",
            "vendor/module/Model/Name.php": "magento2/files/Model/Entity.php",
            "vendor/module/Model/NameRepository.php":
            "magento2/files/Model/EntityRepository.php",
            "vendor/module/Model/Source/Name.php":
            "magento2/files/Model/Config/Source/Entity.php",
            "vendor/module/Model/ResourceModel/Name.php":
            "magento2/files/Model/ResourceModel/Entity.php",
            "vendor/module/Model/ResourceModel/Name/Collection.php":
            "magento2/files/Model/ResourceModel/Entity/Collection.php",
            "vendor/module/Model/ResourceModel/Name/Grid/Collection.php":
            "magento2/files/Model/ResourceModel/Entity/Grid/Collection.php",
            "vendor/module/Observer/ClassName.php":
            "magento2/files/Observer/Default.php",
            "vendor/module/Observer/Subfolder/ClassName.php":
            "magento2/files/Observer/Default.php",
            "vendor/module/Plugin/Name.php":
            "magento2/files/Plugin/Default.php",
            "vendor/module/Setup/UpgradeSchema.php":
            "magento2/files/Setup/UpgradeSchema.php",
            "vendor/module/Ui/DataProvider/EntityProvider.php":
            "magento2/files/Ui/DataProvider/EntityProvider.php",
            "vendor/module/Ui/DataProvider/Form/EntityProvider.php":
            "magento2/files/Ui/DataProvider/Form/EntityProvider.php",
            "vendor/module/Ui/DataProvider/Name/Form/EntityDataProvider.php":
            "magento2/files/Ui/DataProvider/Form/EntityProvider.php",
            "vendor/module/Ui/DataProvider/Name/DataProvider.php":
            "magento2/files/Ui/DataProvider/EntityProvider.php",
            "vendor/module/Ui/Component/Listing/Columns/SomeActions.php":
            "magento2/files/Ui/Component/Listing/Columns/Actions.php",
            "vendor/module/Ui/Component/Listing/Columns/FieldRenderer.php":
            "magento2/files/Ui/Component/Listing/Columns/Default.php",
            "vendor/module/Ui/Component/Listing/Column/FieldRenderer.php":
            "magento2/files/Ui/Component/Listing/Columns/Default.php",
            "vendor/module/view/adminhtml/layout/vendor_module_index.xml":
            "magento2/files/view/adminhtml/layout/index.xml",
            "vendor/module/view/adminhtml/layout/vendor_module_edit.xml":
            "magento2/files/view/adminhtml/layout/edit.xml",
            "vendor/module/view/adminhtml/layout/vendor_module_new.xml":
            "magento2/files/view/adminhtml/layout/new.xml",
            "vendor/module/view/adminhtml/ui_component/module_entity_listing.xml":
            "magento2/files/view/adminhtml/ui_component/listing.xml",
            "vendor/module/view/adminhtml/ui_component/module_entity_list.xml":
            "magento2/files/view/adminhtml/ui_component/listing.xml",
            "vendor/module/view/adminhtml/ui_component/module_entity_form.xml":
            "magento2/files/view/adminhtml/ui_component/form.xml",
            "vendor/module/view/adminhtml/ui_component/module_entity_new.xml":
            "magento2/files/view/adminhtml/ui_component/form.xml",
            "vendor/module/view/adminhtml/ui_component/module_entity_edit.xml":
            "magento2/files/view/adminhtml/ui_component/form.xml",
            "vendor/module/view/frontend/layout/default.xml":
            "magento2/files/view/base/layout/layout.xml",
            "vendor/module/view/base/layout/default.xml":
            "magento2/files/view/base/layout/layout.xml",
            "vendor/module/view/frontend/requirejs-config.js":
            "magento2/files/view/base/requirejs-config.js",
            "vendor/module/view/frontend/web/js/mixin/action-mixin.js":
            "magento2/files/view/base/web/js/mixin/action-mixin.js",
            "vendor/module/view/frontend/web/js/action-mixin.js":
            "magento2/files/view/base/web/js/mixin/action-mixin.js",
            "vendor/module/view/frontend/web/js/mixin/name.js":
            "magento2/files/view/base/web/js/mixin/model-mixin.js",
            "vendor/module/view/frontend/web/js/action/name.js":
            "magento2/files/view/base/web/js/action.js",
            "vendor/module/view/frontend/web/js/model/name.js":
            "magento2/files/view/base/web/js/model.js",
            "vendor/module/view/frontend/web/js/view/name.js":
            "magento2/files/view/base/web/js/view.js",
            "vendor/module/view/frontend/web/js/name.js":
            "magento2/files/view/base/web/js/default.js",
            "vendor/module/composer.json": "magento2/files/composer.json",
            "vendor/module/README.md": "magento2/files/README.md",
            "vendor/module/registration.php": "magento2/files/registration.php"
        }

        for filepath in mapping:
            app = App(filepath)
            app.composer._path = "vendor/module/composer.json"
            app.composer._data = {"type": "magento2-module"}
            self.assertEqual(mapping[filepath],
                             app.template.guess_template_path())