maruto 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/fixtures/magento_1.0/app/Mage.php +585 -0
- data/fixtures/magento_1.13.0.0/app/Mage.php +42 -0
- data/fixtures/magento_1.3.3.0/app/Mage.php +738 -0
- data/fixtures/magento_1.4.0.0/app/Mage.php +859 -0
- data/fixtures/magento_1.7.0.2/app/Mage.php +989 -0
- data/lib/maruto/magento_instance.rb +4 -0
- data/lib/maruto/magento_version.rb +57 -0
- data/lib/maruto/module_configuration.rb +11 -2
- data/lib/maruto/runner.rb +12 -3
- data/lib/maruto/version.rb +1 -1
- data/maruto.gemspec +1 -1
- data/spec/magento_version_spec.rb +57 -0
- data/spec/module_events_spec.rb +45 -35
- metadata +14 -6
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
require 'maruto/magento_version'
|
|
2
3
|
require 'maruto/module_definition'
|
|
3
4
|
require 'maruto/module_configuration'
|
|
4
5
|
|
|
5
6
|
module Maruto::MagentoInstance
|
|
6
7
|
def self.load(magento_root)
|
|
7
8
|
Dir.chdir(magento_root) do
|
|
9
|
+
magento_version = Maruto::MagentoVersion.read_magento_version()
|
|
10
|
+
|
|
8
11
|
all_modules = Maruto::ModuleDefinition.parse_all_module_definitions()
|
|
9
12
|
sorted_modules, active_modules = Maruto::ModuleDefinition.analyse_module_definitions(all_modules)
|
|
10
13
|
|
|
@@ -25,6 +28,7 @@ module Maruto::MagentoInstance
|
|
|
25
28
|
:all_modules => Hash[all_modules.collect { |m| [m[:name], m]}],
|
|
26
29
|
:sorted_modules => sorted_modules,
|
|
27
30
|
:event_observers => event_observers,
|
|
31
|
+
:version => magento_version,
|
|
28
32
|
:warnings => warnings,
|
|
29
33
|
}
|
|
30
34
|
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'maruto/base'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
|
|
4
|
+
module Maruto::MagentoVersion
|
|
5
|
+
|
|
6
|
+
def self.read_magento_version()
|
|
7
|
+
mage = 'app/Mage.php'
|
|
8
|
+
return nil unless File.exists? mage
|
|
9
|
+
File.open mage do |file|
|
|
10
|
+
# newer magento version have a getVersionInfo function
|
|
11
|
+
newer = file.find { |line| line =~ /getVersionInfo/ }
|
|
12
|
+
file.rewind
|
|
13
|
+
if newer
|
|
14
|
+
# newer Magento version
|
|
15
|
+
function = read_function(file, 'getVersionInfo')
|
|
16
|
+
match = function.match(/return array\(.*'major'.*'(\d+)'.*'minor'.*'(\d+)'.*'revision'.*'(\d+)'.*'patch'.*'(\d+)'.*'stability'.*'number'.*\)/)
|
|
17
|
+
version = []
|
|
18
|
+
version[0] = match[1].to_i unless match[1].nil?
|
|
19
|
+
version[1] = match[2].to_i unless match[2].nil?
|
|
20
|
+
version[2] = match[3].to_i unless match[3].nil?
|
|
21
|
+
version[3] = match[4].to_i unless match[4].nil?
|
|
22
|
+
return version
|
|
23
|
+
else
|
|
24
|
+
# older Magento version
|
|
25
|
+
function = read_function(file, 'getVersion')
|
|
26
|
+
match = function.match(/return '(\d+)\.(\d+)\.?(\d+)?\.?(\d+)?';/)
|
|
27
|
+
version = []
|
|
28
|
+
version[0] = match[1].to_i unless match[1].nil?
|
|
29
|
+
version[1] = match[2].to_i unless match[2].nil?
|
|
30
|
+
version[2] = match[3].to_i unless match[3].nil?
|
|
31
|
+
version[3] = match[4].to_i unless match[4].nil?
|
|
32
|
+
return version
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def self.read_function(file, function_name)
|
|
40
|
+
func = nil
|
|
41
|
+
file.rewind
|
|
42
|
+
file.each_line do |line|
|
|
43
|
+
if func then
|
|
44
|
+
func += line
|
|
45
|
+
if /}/ =~ line
|
|
46
|
+
break
|
|
47
|
+
end
|
|
48
|
+
else
|
|
49
|
+
if /public static function #{function_name}\(\)/ =~ line
|
|
50
|
+
func = line
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
func.delete("\n")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
@@ -124,8 +124,17 @@ module Maruto::ModuleConfiguration
|
|
|
124
124
|
events[event_name] ||= Hash.new
|
|
125
125
|
event[:observers].each do |observer|
|
|
126
126
|
observer_name = observer[:name]
|
|
127
|
-
if events[event_name].include? observer_name
|
|
128
|
-
|
|
127
|
+
if events[event_name].include? observer_name then
|
|
128
|
+
if observer[:type] != :disabled
|
|
129
|
+
add_module_config_warning(m, "event_observer:#{area}/#{event_name}/#{observer_name} - defined in module:#{events[event_name][observer_name][:module]} and redefined in module:#{m[:name]} (use type: disabled instead)")
|
|
130
|
+
end
|
|
131
|
+
unless m.include? :dependencies and m[:dependencies].include? events[event_name][observer_name][:module]
|
|
132
|
+
add_module_config_warning(m, "module:#{m[:name]} should have a dependency on module:#{events[event_name][observer_name][:module]} because of event_observer:#{area}/#{event_name}/#{observer_name}")
|
|
133
|
+
end
|
|
134
|
+
else
|
|
135
|
+
if observer[:type] == :disabled
|
|
136
|
+
add_module_config_warning(m, "event_observer:#{area}/#{event_name}/#{observer_name} - cannot disable an inexistant event observer")
|
|
137
|
+
end
|
|
129
138
|
end
|
|
130
139
|
events[event_name][observer_name] = observer
|
|
131
140
|
events[event_name][observer_name][:module] = m[:name]
|
data/lib/maruto/runner.rb
CHANGED
|
@@ -8,9 +8,17 @@ class Maruto::Runner < Thor
|
|
|
8
8
|
|
|
9
9
|
map "-v" => :version, "--version" => :version
|
|
10
10
|
|
|
11
|
-
desc "version", "Show Maruto version"
|
|
11
|
+
desc "version", "Show Maruto and Magento version"
|
|
12
|
+
method_option :magento_root, :aliases => "-m", :default => "."
|
|
12
13
|
def version
|
|
13
14
|
say "Maruto #{Maruto::VERSION}"
|
|
15
|
+
begin
|
|
16
|
+
magento_root = check_magento_folder()
|
|
17
|
+
magento = Maruto::MagentoInstance.load(magento_root)
|
|
18
|
+
say "Magento #{magento[:version].join('.')}"
|
|
19
|
+
rescue Thor::Error
|
|
20
|
+
# do nothing
|
|
21
|
+
end
|
|
14
22
|
end
|
|
15
23
|
|
|
16
24
|
desc "magento?", "check if MAGENTO_ROOT contains a magento app"
|
|
@@ -32,7 +40,8 @@ class Maruto::Runner < Thor
|
|
|
32
40
|
begin
|
|
33
41
|
firstline = File.open(file, &:readline)
|
|
34
42
|
# TODO return list of warnings
|
|
35
|
-
|
|
43
|
+
# TODO case insensitive
|
|
44
|
+
puts file unless firstline.start_with?("<?php") or firstline.start_with?("<?PHP")
|
|
36
45
|
rescue
|
|
37
46
|
# TODO return list of errors
|
|
38
47
|
puts "error in " + file
|
|
@@ -140,7 +149,7 @@ class Maruto::Runner < Thor
|
|
|
140
149
|
(magento_root + 'app/code').directory? &&
|
|
141
150
|
(magento_root + 'app/etc').directory? &&
|
|
142
151
|
(magento_root + 'app/etc/modules').directory? &&
|
|
143
|
-
(magento_root + 'app/etc/
|
|
152
|
+
(magento_root + 'app/etc/modules/Mage_All.xml').file?
|
|
144
153
|
raise Thor::Error, "could not find magento in this folder: #{magento_root.realpath}#{options[:magento_root] == '.' ? ' (try -m MAGENTO_ROOT)' : ''}" unless is_magento
|
|
145
154
|
|
|
146
155
|
return magento_root
|
data/lib/maruto/version.rb
CHANGED
data/maruto.gemspec
CHANGED
|
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
|
|
|
23
23
|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
|
25
25
|
spec.add_development_dependency "rake"
|
|
26
|
-
spec.add_development_dependency "minitest"
|
|
26
|
+
spec.add_development_dependency "minitest", "~> 5"
|
|
27
27
|
# spec.add_development_dependency "minitest-reporters"
|
|
28
28
|
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'maruto/magento_version'
|
|
4
|
+
|
|
5
|
+
module Maruto
|
|
6
|
+
|
|
7
|
+
describe "when reading the magento version" do
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
# Magento Community Edition
|
|
11
|
+
@magento_root_1_0 = File.expand_path('../../fixtures/magento_1.0', __FILE__)
|
|
12
|
+
@magento_root_1_3_3_0 = File.expand_path('../../fixtures/magento_1.3.3.0', __FILE__)
|
|
13
|
+
@magento_root_1_4_0_0 = File.expand_path('../../fixtures/magento_1.4.0.0', __FILE__)
|
|
14
|
+
@magento_root_1_7_0_2 = File.expand_path('../../fixtures/magento_1.7.0.2', __FILE__)
|
|
15
|
+
# Magento Enterprise Edition
|
|
16
|
+
@magento_root_1_13_0_0 = File.expand_path('../../fixtures/magento_1.13.0.0', __FILE__)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "will return an array" do
|
|
20
|
+
Dir.chdir(@magento_root_1_0) do
|
|
21
|
+
version = MagentoVersion.read_magento_version()
|
|
22
|
+
version.must_be_kind_of Array
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
it "will read version 1.0" do
|
|
26
|
+
Dir.chdir(@magento_root_1_0) do
|
|
27
|
+
version = MagentoVersion.read_magento_version()
|
|
28
|
+
version.must_equal [1,0]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
it "will read version 1.3.3.0" do
|
|
32
|
+
Dir.chdir(@magento_root_1_3_3_0) do
|
|
33
|
+
version = MagentoVersion.read_magento_version()
|
|
34
|
+
version.must_equal [1,3,3,0]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
it "will read version 1.4.0.0" do
|
|
38
|
+
Dir.chdir(@magento_root_1_4_0_0) do
|
|
39
|
+
version = MagentoVersion.read_magento_version()
|
|
40
|
+
version.must_equal [1,4,0,0]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
it "will read version 1.7.0.2" do
|
|
44
|
+
Dir.chdir(@magento_root_1_7_0_2) do
|
|
45
|
+
version = MagentoVersion.read_magento_version()
|
|
46
|
+
version.must_equal [1,7,0,2]
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
it "will read version 1.13.0.0" do
|
|
50
|
+
Dir.chdir(@magento_root_1_13_0_0) do
|
|
51
|
+
version = MagentoVersion.read_magento_version()
|
|
52
|
+
version.must_equal [1,13,0,0]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
data/spec/module_events_spec.rb
CHANGED
|
@@ -301,18 +301,19 @@ module Maruto
|
|
|
301
301
|
@module_c = { :name => :Mage_C, :active => true, :code_pool => :core, :defined => 'c', :config_path => 'app/code/core/Mage/C/etc/config.xml' }
|
|
302
302
|
@module_d = { :name => :Mage_D, :active => true, :code_pool => :core, :defined => 'd', :config_path => 'app/code/core/Mage/D/etc/config.xml' }
|
|
303
303
|
|
|
304
|
-
@observer_1 = { :name => 'a_o1', :type =>
|
|
304
|
+
@observer_1 = { :name => 'a_o1', :type => :singleton, :class => 'Mage_A_Model_Observer', :method => 'global_1' }
|
|
305
|
+
@observer_2 = { :name => 'a_o2', :type => :singleton, :class => 'Mage_A_Model_Observer', :method => 'global_2' }
|
|
305
306
|
|
|
306
307
|
@module_a[:events] = {
|
|
307
308
|
:global => [{ :name => 'e1', :observers => [
|
|
308
309
|
@observer_1,
|
|
309
|
-
|
|
310
|
+
@observer_2
|
|
310
311
|
] }],
|
|
311
312
|
:adminhtml => [{ :name => 'e1', :observers => [
|
|
312
|
-
{ :name => 'a_o1', :type =>
|
|
313
|
+
{ :name => 'a_o1', :type => :singleton, :class => 'Mage_A_Model_Observer', :method => 'adminhtml_1' }
|
|
313
314
|
] }],
|
|
314
315
|
:frontend => [{ :name => 'e1', :observers => [
|
|
315
|
-
{ :name => 'a_o1', :type =>
|
|
316
|
+
{ :name => 'a_o1', :type => :singleton, :class => 'Mage_A_Model_Observer', :method => 'frontend_1' }
|
|
316
317
|
] }]
|
|
317
318
|
}
|
|
318
319
|
|
|
@@ -341,19 +342,54 @@ module Maruto
|
|
|
341
342
|
@module_b[:events] = {
|
|
342
343
|
:global => [{ :name => 'e1', :observers => [ @observer_1 ] }]
|
|
343
344
|
}
|
|
345
|
+
@module_b[:dependencies] = [:Mage_A]
|
|
344
346
|
h = ModuleConfiguration.collect_scoped_event_observers(:global, [@module_a, @module_b])
|
|
345
347
|
|
|
346
348
|
@module_b.must_include :warnings
|
|
347
349
|
@module_b[:warnings].size.must_equal 1
|
|
348
350
|
end
|
|
349
|
-
it "will add a warning when overwriting an observer without module dependency" do
|
|
350
|
-
# TODO
|
|
351
|
-
end
|
|
352
351
|
it "wont add a warning when overwriting an observer to disable it" do
|
|
353
|
-
|
|
352
|
+
disabled_observer = @observer_1.clone
|
|
353
|
+
disabled_observer[:type] = :disabled
|
|
354
|
+
@module_b[:events] = {
|
|
355
|
+
:global => [{ :name => 'e1', :observers => [ disabled_observer ] }]
|
|
356
|
+
}
|
|
357
|
+
@module_b[:dependencies] = [:Mage_A]
|
|
358
|
+
h = ModuleConfiguration.collect_scoped_event_observers(:global, [@module_a, @module_b])
|
|
359
|
+
|
|
360
|
+
@module_b.wont_include :warnings
|
|
361
|
+
end
|
|
362
|
+
it "will add a warning when overwriting an observer without module dependency" do
|
|
363
|
+
disabled_observer = @observer_2.clone
|
|
364
|
+
disabled_observer[:type] = :disabled
|
|
365
|
+
|
|
366
|
+
@module_b[:events] = {
|
|
367
|
+
:global => [{ :name => 'e1', :observers => [ @observer_1 ] }]
|
|
368
|
+
}
|
|
369
|
+
@module_c[:events] = {
|
|
370
|
+
:global => [{ :name => 'e1', :observers => [ disabled_observer ] }]
|
|
371
|
+
}
|
|
372
|
+
@module_d[:events] = {
|
|
373
|
+
:global => [{ :name => 'e1', :observers => [ @observer_1, disabled_observer ] }]
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
h = ModuleConfiguration.collect_scoped_event_observers(:global, [@module_a, @module_b])
|
|
377
|
+
@module_b.must_include :warnings
|
|
378
|
+
@module_b[:warnings].size.must_equal 2 # 1 for overwriting + 1 for missing dependency
|
|
379
|
+
|
|
380
|
+
h = ModuleConfiguration.collect_scoped_event_observers(:global, [@module_a, @module_c])
|
|
381
|
+
@module_c.must_include :warnings
|
|
382
|
+
@module_c[:warnings].size.must_equal 1 # 1 for missing dependency
|
|
383
|
+
|
|
384
|
+
h = ModuleConfiguration.collect_scoped_event_observers(:global, [@module_a, @module_d])
|
|
385
|
+
@module_d.must_include :warnings
|
|
386
|
+
@module_d[:warnings].size.must_equal 3 # 1 for overwriting + 2 for missing dependency
|
|
354
387
|
end
|
|
355
388
|
it "will add a warning when disabling a non-existing observer" do
|
|
356
|
-
|
|
389
|
+
@observer_1[:type] = :disabled
|
|
390
|
+
h = ModuleConfiguration.collect_scoped_event_observers(:global, [@module_a])
|
|
391
|
+
@module_a.must_include :warnings
|
|
392
|
+
@module_a[:warnings].size.must_equal 1
|
|
357
393
|
end
|
|
358
394
|
|
|
359
395
|
|
|
@@ -401,31 +437,5 @@ module Maruto
|
|
|
401
437
|
end
|
|
402
438
|
end
|
|
403
439
|
|
|
404
|
-
describe "when analysing event observers" do
|
|
405
|
-
|
|
406
|
-
it "will add a warning when an observer has already been declared" do
|
|
407
|
-
|
|
408
|
-
end
|
|
409
|
-
|
|
410
|
-
# it "will warn when an event has no observers" do
|
|
411
|
-
# xml_node_no_obs = Nokogiri::XML('''
|
|
412
|
-
# <config><scope><events><first_event></first_event></events></scope></config>
|
|
413
|
-
# ''').root
|
|
414
|
-
# events, warnings = ModuleConfiguration.parse_scoped_event_observers('root', xml_node_no_obs.xpath('/config/scope'))
|
|
415
|
-
# events.size.must_equal 0
|
|
416
|
-
# warnings.size.must_equal 1
|
|
417
|
-
# warnings[0].must_include 'root/events/first_event'
|
|
418
|
-
# end
|
|
419
|
-
# it "will warn when an event has an empty observers node" do
|
|
420
|
-
# xml_node_empty_obs = Nokogiri::XML('''
|
|
421
|
-
# <config><scope><events><first_event><observers></observers></first_event></events></scope></config>
|
|
422
|
-
# ''').root
|
|
423
|
-
# events, warnings = ModuleConfiguration.parse_scoped_event_observers('root', xml_node_empty_obs.xpath('/config/scope'))
|
|
424
|
-
# events.size.must_equal 0
|
|
425
|
-
# warnings.size.must_equal 1
|
|
426
|
-
# warnings[0].must_include 'root/events/first_event/observers'
|
|
427
|
-
# end
|
|
428
|
-
|
|
429
|
-
end
|
|
430
440
|
end
|
|
431
441
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: maruto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.8
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-05-
|
|
12
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: nokogiri
|
|
@@ -80,17 +80,17 @@ dependencies:
|
|
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
|
81
81
|
none: false
|
|
82
82
|
requirements:
|
|
83
|
-
- -
|
|
83
|
+
- - ~>
|
|
84
84
|
- !ruby/object:Gem::Version
|
|
85
|
-
version: '
|
|
85
|
+
version: '5'
|
|
86
86
|
type: :development
|
|
87
87
|
prerelease: false
|
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
|
89
89
|
none: false
|
|
90
90
|
requirements:
|
|
91
|
-
- -
|
|
91
|
+
- - ~>
|
|
92
92
|
- !ruby/object:Gem::Version
|
|
93
|
-
version: '
|
|
93
|
+
version: '5'
|
|
94
94
|
description: Magento Ruby Tools
|
|
95
95
|
email:
|
|
96
96
|
- jlgeering.13@gmail.com
|
|
@@ -107,6 +107,11 @@ files:
|
|
|
107
107
|
- README.md
|
|
108
108
|
- Rakefile
|
|
109
109
|
- bin/maruto
|
|
110
|
+
- fixtures/magento_1.0/app/Mage.php
|
|
111
|
+
- fixtures/magento_1.13.0.0/app/Mage.php
|
|
112
|
+
- fixtures/magento_1.3.3.0/app/Mage.php
|
|
113
|
+
- fixtures/magento_1.4.0.0/app/Mage.php
|
|
114
|
+
- fixtures/magento_1.7.0.2/app/Mage.php
|
|
110
115
|
- fixtures/magento_root/app/code/core/Mage/A/etc/config.xml
|
|
111
116
|
- fixtures/magento_root/app/code/core/Mage/B/etc/config.xml
|
|
112
117
|
- fixtures/magento_root/app/code/core/Mage/C/etc/config.xml
|
|
@@ -118,11 +123,13 @@ files:
|
|
|
118
123
|
- lib/maruto/base.rb
|
|
119
124
|
- lib/maruto/magento_config.rb
|
|
120
125
|
- lib/maruto/magento_instance.rb
|
|
126
|
+
- lib/maruto/magento_version.rb
|
|
121
127
|
- lib/maruto/module_configuration.rb
|
|
122
128
|
- lib/maruto/module_definition.rb
|
|
123
129
|
- lib/maruto/runner.rb
|
|
124
130
|
- lib/maruto/version.rb
|
|
125
131
|
- maruto.gemspec
|
|
132
|
+
- spec/magento_version_spec.rb
|
|
126
133
|
- spec/module_definition_spec.rb
|
|
127
134
|
- spec/module_events_spec.rb
|
|
128
135
|
- spec/module_version_spec.rb
|
|
@@ -153,6 +160,7 @@ signing_key:
|
|
|
153
160
|
specification_version: 3
|
|
154
161
|
summary: config parser and analyser, ...
|
|
155
162
|
test_files:
|
|
163
|
+
- spec/magento_version_spec.rb
|
|
156
164
|
- spec/module_definition_spec.rb
|
|
157
165
|
- spec/module_events_spec.rb
|
|
158
166
|
- spec/module_version_spec.rb
|