




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which file is mandatory for every Magento 2 module to be recognized by the framework? A) registration.php B) module.xml C) composer.json D) di.xml Answer: A Explanation: registration.php contains the call to \Magento\Framework\Component\ComponentRegistrar::register() which tells Magento that the module exists. Question 2. What is the purpose of etc/module.xml in a Magento 2 module? A) Define database schema B) Declare module name, setup version, and dependencies C) Register JavaScript components D) List cron jobs Answer: B Explanation: etc/module.xml declares the module’s name, its setup version, and any module dependencies required for load order. Question 3. In Magento 2 Dependency Injection, which method is preferred for obtaining class dependencies?
A) Using the Object Manager directly in the code B) Constructor injection C) Static calls to the class D) Global helper functions Answer: B Explanation: Constructor injection promotes testability and clear dependency definition; direct use of the Object Manager is discouraged in application code. Question 4. Which Magento 2 concept ensures API stability across releases? A) Plugins B) Observers C) Service Contracts (interfaces) D) Preferences Answer: C Explanation: Service contracts define stable interfaces for business services, allowing Magento to change implementations without breaking third‑party code. Question 5. When Magento merges configuration files, which of the following has the highest precedence? A) Global config.xml B) Module’s config.xml
Explanation: The frontend area loads configuration, layout, and routes intended for the storefront. Question 8. Which file defines custom frontend routes for a module? A) etc/frontend/routes.xml B) etc/adminhtml/routes.xml C) etc/webapi.xml D) etc/di.xml Answer: A Explanation: etc/frontend/routes.xml registers route IDs and frontNames for the storefront. Question 9. In a Magento controller, which method is executed to produce the result? A) render() B) execute() C) run() D) dispatch() Answer: B Explanation: All action controllers implement the execute() method which returns a ResultInterface.
Question 10. Which ResultFactory type should be used to return JSON data from a controller? A) page B) redirect C) json D) forward Answer: C Explanation: $resultFactory-
create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON) creates a JSON response. Question 11. How can you retrieve a GET parameter named “id” inside a controller action? A) $this->getRequest()->getParam('id') B) $this->request->get('id') C) $this->url->getParam('id') D) $this->_request->get('id') Answer: A Explanation: The Request object provides getParam() to fetch query or post parameters. Question 12. Which class is responsible for persisting data to a specific database table in Magento 2?
C) $collection->where('field = ?', $value) D) $collection->setFilter('field', $value) Answer: B Explanation: addFieldToFilter() is the standard method for adding conditions to a collection query. Question 15. When using declarative schema, which file defines a new database table? A) db_schema.xml B) schema.xml C) InstallSchema.php D) UpgradeSchema.php Answer: A Explanation: db_schema.xml is the declarative schema file that describes tables, columns, indexes, and foreign keys. Question 16. Which command applies data patches after a module is installed? A) bin/magento setup:upgrade B) bin/magento setup:db-schema:upgrade C) bin/magento setup:di:compile D) bin/magento cache:flush
Answer: A Explanation: setup:upgrade runs schema and data patches, updating the database to the latest version. Question 17. In the EAV model, which table stores attribute definitions for products? A) catalog_product_entity B) eav_attribute C) catalog_product_entity_int D) eav_entity_type Answer: B Explanation: eav_attribute contains metadata for all attributes across entities, including products. Question 18. Which layout handle is used for the Magento admin “Dashboard” page? A) adminhtml_dashboard_index B) adminhtml_dashboard_index_index C) adminhtml_dashboard_index_grid D) adminhtml_dashboard_index_view Answer: B
Question 21. When creating a plugin, which method type runs before the original method? A) beforeMethodName B) afterMethodName C) aroundMethodName D) preMethodName Answer: A Explanation: before* methods are executed prior to the original method and can modify arguments. Question 22. Which di.xml element is used to replace a core class with a custom implementation? A)
B) Magento’s code generation skips them C) Plugins rely on inheritance and method overriding, which final prevents D) They are loaded in a separate autoloader Answer: C Explanation: Final prevents subclassing, so Magento cannot generate an interceptor that overrides the method. Question 24. In an observer class, which method receives the event data? A) execute() B) dispatch() C) process() D) observe() Answer: A Explanation: All observer classes implement the execute(\Magento\Framework\Event\Observer $observer) method. Question 25. Which XML file registers an observer for the “customer_register_success” event in the frontend area? A) etc/events.xml B) etc/frontend/events.xml C) etc/adminhtml/events.xml
Answer: A Explanation: etc/acl.xml contains
Explanation: setup:di:compile generates interceptors and other DI code, reflecting new plugins. Question 30. What is the correct way to log a custom message in Magento 2? A) error_log('message'); B) $this->logger->info('message'); C) Mage::log('message'); D) $this->_logger->debug('message'); Answer: B Explanation: Inject \Psr\Log\LoggerInterface and use its info(), debug(), etc., methods. Question 31. Which class provides the request object in a controller? A) \Magento\Framework\App\Request\Http B) \Magento\Framework\App\Response\Http C) \Magento\Framework\App\Action\Context D) \Magento\Framework\HTTP\PhpEnvironment\Request Answer: C Explanation: The Action Context injects the request, response, and other dependencies into the controller.
A) To create a class at runtime without a PHP file B) To define a type that extends another type with modified arguments C) To register a plugin for an interface D) To declare a preference for an interface Answer: B Explanation: Virtual types inherit from a concrete class but allow you to change constructor arguments without creating a new PHP class. Question 35. Which file is used to add custom JavaScript mixins for a Magento UI component? A) requirejs-config.js B) mixins.js C) view.xml D) component.js Answer: A Explanation: requirejs-config.js maps original component paths to mixin files using the “mixins” configuration. Question 36. In a Magento 2 theme, where are layout XML files typically placed? A) app/design/frontend/Vendor/theme/Magento_Theme/layout/ B) app/design/frontend/Vendor/theme/layout/
C) app/code/Vendor/Theme/view/frontend/layout/ D) app/design/frontend/Vendor/theme/web/layout/ Answer: A Explanation: Theme-specific layout overrides reside in the module folder (Magento_Theme) inside the theme’s layout directory. Question 37. Which result type should a controller return to perform a 302 redirect to a CMS page? A) redirect B) forward C) page D) raw Answer: A Explanation: The redirect result can be configured with setUrl() to send a 302 response to the desired URL. Question 38. What is the effect of setting “mode” to “developer” in Magento? A) Enables static content signing only B) Turns off caching, enables template path hints, and displays detailed errors C) Enables production‑grade minification D) Disables all cron jobs
Question 41. Which of the following best describes a “frontend router” in Magento 2? A) A class that maps API endpoints to services B) A configuration that links a URL prefix to a module’s controller namespace C) A PHP script that reads .htaccess rules D) A JavaScript file handling client navigation Answer: B Explanation: The router defined in routes.xml maps a frontName (URL prefix) to a module’s controller classes. Question 42. What is the purpose of the “view.xml” file in a Magento theme? A) Define layout handles B) Configure image dimensions and responsive breakpoints C) Register JavaScript modules D) Set up ACL rules Answer: B Explanation: view.xml contains image size definitions, media URL settings, and other view‑related configurations. Question 43. Which XML tag is used to set a default value for a system configuration field?
A)